From 8a1d7f95128670ff53191e4e954034f483e3c39c Mon Sep 17 00:00:00 2001 From: ranchuan Date: Mon, 15 Sep 2025 11:14:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=9D=E8=AF=81stm32=E7=BC=96=E8=AF=91=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw/bsp/board.c | 18 +++++++++--------- lib/rt-thread/tusb_config.h | 20 ++++++++++++-------- lib/rt-thread/tusb_rt_thread_port.c | 10 ++++++---- src/osal/osal_rtthread.h | 11 +++++++---- src/portable/synopsys/dwc2/dwc2_stm32.h | 8 ++++---- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/hw/bsp/board.c b/hw/bsp/board.c index 1ba5a1b9d..f86b72890 100644 --- a/hw/bsp/board.c +++ b/hw/bsp/board.c @@ -98,16 +98,16 @@ int sys_read (int fhdl, char *buf, size_t count) { #else // Default logging with on-board UART -int sys_write (int fhdl, const char *buf, size_t count) { - (void) fhdl; - return board_uart_write(buf, (int) count); -} +// int sys_write (int fhdl, const char *buf, size_t count) { +// (void) fhdl; +// return board_uart_write(buf, (int) count); +// } -int sys_read (int fhdl, char *buf, size_t count) { - (void) fhdl; - int rd = board_uart_read((uint8_t*) buf, (int) count); - return (rd > 0) ? rd : -1; -} +// int sys_read (int fhdl, char *buf, size_t count) { +// (void) fhdl; +// int rd = board_uart_read((uint8_t*) buf, (int) count); +// return (rd > 0) ? rd : -1; +// } #endif diff --git a/lib/rt-thread/tusb_config.h b/lib/rt-thread/tusb_config.h index 11dc21983..1124d408e 100644 --- a/lib/rt-thread/tusb_config.h +++ b/lib/rt-thread/tusb_config.h @@ -84,7 +84,7 @@ extern "C" { #endif #ifndef BOARD_DEVICE_RHPORT_SPEED -#define BOARD_DEVICE_RHPORT_SPEED PKG_TINYUSB_DEVICE_PORT_SPEED +#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED #endif #if BOARD_DEVICE_RHPORT_NUM == 0 @@ -103,11 +103,11 @@ extern "C" { * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) */ #ifndef CFG_TUSB_MEM_SECTION -#define CFG_TUSB_MEM_SECTION rt_section(PKG_TINYUSB_MEM_SECTION) +#define CFG_TUSB_MEM_SECTION #endif #ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN rt_align(PKG_TINYUSB_MEM_ALIGN) +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) #endif //-------------------------------------------------------------------- @@ -120,16 +120,20 @@ extern "C" { #endif #ifndef CFG_TUD_ENDPOINT0_SIZE -#define CFG_TUD_ENDPOINT0_SIZE PKG_TINYUSB_EDPT0_SIZE +#define CFG_TUD_ENDPOINT0_SIZE 8 +#endif + +#ifndef CFG_TUD_CDC +#define CFG_TUD_CDC 1 #endif // CDC FIFO size of TX and RX -#define CFG_TUD_CDC_RX_BUFSIZE PKG_TINYUSB_DEVICE_CDC_RX_BUFSIZE -#define CFG_TUD_CDC_TX_BUFSIZE PKG_TINYUSB_DEVICE_CDC_TX_BUFSIZE +#define CFG_TUD_CDC_RX_BUFSIZE 128 +#define CFG_TUD_CDC_TX_BUFSIZE 128 -#define CFG_TUD_MSC_EP_BUFSIZE PKG_TINYUSB_DEVICE_MSC_EP_BUFSIZE +#define CFG_TUD_MSC_EP_BUFSIZE 32 -#define CFG_TUD_HID_EP_BUFSIZE PKG_TINYUSB_DEVICE_HID_EP_BUFSIZE +#define CFG_TUD_HID_EP_BUFSIZE 32 #ifndef PKG_TINYUSB_DEVICE_CDC_STRING #define PKG_TINYUSB_DEVICE_CDC_STRING "" diff --git a/lib/rt-thread/tusb_rt_thread_port.c b/lib/rt-thread/tusb_rt_thread_port.c index 7e04d2453..4a8cb6998 100644 --- a/lib/rt-thread/tusb_rt_thread_port.c +++ b/lib/rt-thread/tusb_rt_thread_port.c @@ -25,6 +25,7 @@ */ #ifdef __RTTHREAD__ #include +#include "bsp_init.h" #define DBG_TAG "TinyUSB" #define DBG_LVL DBG_INFO @@ -57,13 +58,13 @@ static int init_tinyusb(void) { rt_thread_t tid; - tusb_board_init(); + // tusb_board_init(); tusb_init(); #ifdef RT_USING_HEAP tid = rt_thread_create("tusb", tusb_thread_entry, RT_NULL, - PKG_TINYUSB_STACK_SIZE, - PKG_TINYUSB_THREAD_PRIORITY, 10); + 2048, + 5, 10); if (tid == RT_NULL) #else rt_err_t result; @@ -82,5 +83,6 @@ static int init_tinyusb(void) return 0; } -INIT_APP_EXPORT(init_tinyusb); +// INIT_APP_EXPORT(init_tinyusb); +extern_init(tinyusb, init_tinyusb); #endif /*__RTTHREAD__*/ diff --git a/src/osal/osal_rtthread.h b/src/osal/osal_rtthread.h index a778f5425..2336fd090 100644 --- a/src/osal/osal_rtthread.h +++ b/src/osal/osal_rtthread.h @@ -45,27 +45,30 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec) { //--------------------------------------------------------------------+ // Spinlock API //--------------------------------------------------------------------+ -typedef struct rt_spinlock osal_spinlock_t; +typedef struct rt_mutex osal_spinlock_t; #define OSAL_SPINLOCK_DEF(_name, _int_set) \ osal_spinlock_t _name TU_ATTR_ALWAYS_INLINE static inline void osal_spin_init(osal_spinlock_t *ctx) { - rt_spin_lock_init(ctx); + // rt_spin_lock_init(ctx); + rt_mutex_init(ctx, "tusb", RT_IPC_FLAG_PRIO); } TU_ATTR_ALWAYS_INLINE static inline void osal_spin_lock(osal_spinlock_t *ctx, bool in_isr) { if (!TUP_MCU_MULTIPLE_CORE && in_isr) { return; // single core MCU does not need to lock in ISR } - rt_spin_lock(ctx); + // rt_spin_lock(ctx); + rt_mutex_take(ctx, RT_WAITING_FOREVER); } TU_ATTR_ALWAYS_INLINE static inline void osal_spin_unlock(osal_spinlock_t *ctx, bool in_isr) { if (!TUP_MCU_MULTIPLE_CORE && in_isr) { return; // single core MCU does not need to lock in ISR } - rt_spin_unlock(ctx); + // rt_spin_unlock(ctx); + rt_mutex_release(ctx); } //--------------------------------------------------------------------+ diff --git a/src/portable/synopsys/dwc2/dwc2_stm32.h b/src/portable/synopsys/dwc2/dwc2_stm32.h index 5f2b8419c..ecbb39286 100644 --- a/src/portable/synopsys/dwc2/dwc2_stm32.h +++ b/src/portable/synopsys/dwc2/dwc2_stm32.h @@ -48,11 +48,11 @@ extern "C" { #elif CFG_TUSB_MCU == OPT_MCU_STM32F4 #include "stm32f4xx.h" - #define EP_MAX_FS USB_OTG_FS_MAX_IN_ENDPOINTS - #define EP_FIFO_SIZE_FS USB_OTG_FS_TOTAL_FIFO_SIZE + #define EP_MAX_FS 4 + #define EP_FIFO_SIZE_FS 256 - #define EP_MAX_HS USB_OTG_HS_MAX_IN_ENDPOINTS - #define EP_FIFO_SIZE_HS USB_OTG_HS_TOTAL_FIFO_SIZE + #define EP_MAX_HS 4 + #define EP_FIFO_SIZE_HS 256 #elif CFG_TUSB_MCU == OPT_MCU_STM32H7 #include "stm32h7xx.h"