mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-15 20:42:23 +00:00
esp32 cdc host with max3421 work well
This commit is contained in:
parent
277852afc1
commit
7dc1a66f91
@ -27,9 +27,43 @@
|
||||
#include "tusb.h"
|
||||
#include "bsp/board_api.h"
|
||||
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define CDC_STACK_SZIE 2048
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
|
||||
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
StackType_t cdc_stack[CDC_STACK_SZIE];
|
||||
StaticTask_t cdc_taskdef;
|
||||
#endif
|
||||
|
||||
static void cdc_app_task(void* param);
|
||||
|
||||
void cdc_app_init(void) {
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
xTaskCreateStatic(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
|
||||
#else
|
||||
xTaskCreate(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
// helper
|
||||
size_t get_console_inputs(uint8_t *buf, size_t bufsize) {
|
||||
@ -45,11 +79,7 @@ size_t get_console_inputs(uint8_t *buf, size_t bufsize) {
|
||||
return count;
|
||||
}
|
||||
|
||||
void cdc_app_init(void) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
void cdc_app_task(void* param) {
|
||||
static void cdc_app_task(void* param) {
|
||||
(void) param;
|
||||
|
||||
uint8_t buf[64 + 1]; // +1 for extra null character
|
||||
@ -74,6 +104,10 @@ void cdc_app_task(void* param) {
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TinyUSB Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received new data
|
||||
void tuh_cdc_rx_cb(uint8_t idx) {
|
||||
uint8_t buf[64 + 1]; // +1 for extra null character
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define USBH_STACK_SIZE 4096
|
||||
#define CDC_STACK_SZIE 2048
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
@ -50,7 +49,6 @@
|
||||
|
||||
// Increase stack size when debug log is enabled
|
||||
#define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
|
||||
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
|
||||
#endif
|
||||
|
||||
|
||||
@ -74,38 +72,30 @@ StaticTimer_t blinky_tmdef;
|
||||
|
||||
StackType_t usb_host_stack[USBH_STACK_SIZE];
|
||||
StaticTask_t usb_host_taskdef;
|
||||
|
||||
StackType_t cdc_stack[CDC_STACK_SZIE];
|
||||
StaticTask_t cdc_taskdef;
|
||||
#endif
|
||||
|
||||
TimerHandle_t blinky_tm;
|
||||
|
||||
static void led_blinky_cb(TimerHandle_t xTimer);
|
||||
static void usb_host_task(void* param);
|
||||
|
||||
extern void cdc_app_init(void);
|
||||
extern void hid_app_init(void);
|
||||
extern void msc_app_init(void);
|
||||
|
||||
static void usb_host_task(void* param);
|
||||
extern void cdc_app_task(void* param);
|
||||
|
||||
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
int main(void) {
|
||||
board_init();
|
||||
|
||||
printf("TinyUSB Host CDC MSC HID with FreeRTOS Example\r\n");
|
||||
|
||||
// Create soft timer for blinky, task for tinyusb stack and CDC
|
||||
// Create soft timer for blinky, task for tinyusb stack
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef);
|
||||
xTaskCreateStatic(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_host_stack, &usb_host_taskdef);
|
||||
xTaskCreateStatic(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
|
||||
#else
|
||||
blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
|
||||
xTaskCreate(usb_host_task, "usbd", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
|
||||
xTaskCreate(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
|
||||
#endif
|
||||
|
||||
xTimerStart(blinky_tm, 0);
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "driver/periph_ctrl.h"
|
||||
#endif
|
||||
|
||||
#define UART_ID UART_NUM_0
|
||||
|
||||
#ifdef NEOPIXEL_PIN
|
||||
#include "led_strip.h"
|
||||
static led_strip_t *strip;
|
||||
@ -59,6 +61,17 @@ static void configure_pins(usb_hal_context_t *usb);
|
||||
|
||||
// Initialize on-board peripherals : led, button, uart and USB
|
||||
void board_init(void) {
|
||||
// uart init
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
|
||||
};
|
||||
uart_driver_install(UART_ID, 1024, 0, 0, NULL, 0);
|
||||
uart_param_config(UART_ID, &uart_config);
|
||||
|
||||
#ifdef NEOPIXEL_PIN
|
||||
#ifdef NEOPIXEL_POWER_PIN
|
||||
gpio_reset_pin(NEOPIXEL_POWER_PIN);
|
||||
@ -144,7 +157,7 @@ uint32_t board_button_read(void) {
|
||||
|
||||
// Get characters from UART
|
||||
int board_uart_read(uint8_t *buf, int len) {
|
||||
return uart_read_bytes(UART_NUM_0, buf, len, 0);
|
||||
return uart_read_bytes(UART_ID, buf, len, 0);
|
||||
}
|
||||
|
||||
// Send characters to UART
|
||||
@ -155,9 +168,8 @@ int board_uart_write(void const *buf, int len) {
|
||||
}
|
||||
|
||||
int board_getchar(void) {
|
||||
// char c;
|
||||
// return (uart_read_bytes(UART_NUM_0, &c, 1, 0) > 0) ? (int) c : (-1);
|
||||
return -1;
|
||||
char c;
|
||||
return (uart_read_bytes(UART_ID, &c, 1, 0) > 0) ? (int) c : (-1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
Loading…
x
Reference in New Issue
Block a user