From c0ea9c3ab3667fe19d4e454795e398e0f493e46b Mon Sep 17 00:00:00 2001 From: Epagris Date: Fri, 7 Mar 2025 16:34:25 +0100 Subject: [PATCH] - CH32F207 port fixed - ACM stack size fixed --- class/acm.c | 2 +- driver/ch32/usb_drv.c | 6 +++--- driver/ch32/usb_drv.h | 12 +++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/class/acm.c b/class/acm.c index 1234ad4..ecc2cff 100644 --- a/class/acm.c +++ b/class/acm.c @@ -97,7 +97,7 @@ void usb_acm_init(const Usb_Acm_EpAssignments *as) { // create thread osThreadAttr_t attr; memset(&attr, 0, sizeof(osThreadAttr_t)); - attr.stack_size = 1024; + attr.stack_size = 512; attr.name = "acm"; th = osThreadNew(thread_usb_acm, NULL, &attr); } diff --git a/driver/ch32/usb_drv.c b/driver/ch32/usb_drv.c index 3fefbeb..152c217 100644 --- a/driver/ch32/usb_drv.c +++ b/driver/ch32/usb_drv.c @@ -34,8 +34,8 @@ #define USB_EP_TX_BUF_SIZE (64) ///< Transmit buffer size #define USB_EP_RX_BUF_SIZE (64) ///< Receive buffer size -#define USB_EP_COMBINED_BUF_SIZE ((USB_EP_TX_BUF_SIZE + USB_EP_RX_BUF_SIZE) * 2) ///< Combined buffer size in a single direction -#define USB_EP_SUMMED_BUF_SIZE (USB_EP_COMBINED_BUF_SIZE * USB_NUM_OF_ENDPOINTS * 2) ///< Summed size for each endpoint in each direction +#define USB_EP_COMBINED_BUF_SIZE ((USB_EP_TX_BUF_SIZE + USB_EP_RX_BUF_SIZE)) ///< Combined buffer size in a single direction +#define USB_EP_SUMMED_BUF_SIZE (USB_EP_COMBINED_BUF_SIZE * USB_NUM_OF_ENDPOINTS) ///< Summed size for each endpoint in each direction static USBDRV_GlobalState gs; ///< Global USB state static uint8_t buf[USB_EP_SUMMED_BUF_SIZE] DWORD_ALIGN; ///< Transmit/Receive buffer @@ -214,7 +214,7 @@ typedef struct { } USB_EP_Ctrl; // clang-format off -static const USB_EP_Ctrl USB_EPCtrl[USB_NUM_OF_ENDPOINTS] = { +static const USB_EP_Ctrl USB_EPCtrl[USB_MAX_NUM_OF_ENDPOINTS] = { {NULL, 0, 0, 0, &(USBG->UEP0_DMA), &(USBG->UEP0_TX_LEN), &(USBG->UEP0_TX_CTRL), &(USBG->UEP0_RX_CTRL)}, // EP0 {&(USBG->UEP4_1_MOD), USBFS_UEP1_RX_EN, USBFS_UEP1_TX_EN, USBFS_UEP1_BUF_MOD, &(USBG->UEP1_DMA), &(USBG->UEP1_TX_LEN), &(USBG->UEP1_TX_CTRL), &(USBG->UEP1_RX_CTRL) }, // EP1 {&(USBG->UEP2_3_MOD), USBFS_UEP2_RX_EN, USBFS_UEP2_TX_EN, USBFS_UEP2_BUF_MOD, &(USBG->UEP2_DMA), &(USBG->UEP2_TX_LEN), &(USBG->UEP2_TX_CTRL), &(USBG->UEP2_RX_CTRL) }, // EP2 diff --git a/driver/ch32/usb_drv.h b/driver/ch32/usb_drv.h index 0b8a309..59c56a7 100644 --- a/driver/ch32/usb_drv.h +++ b/driver/ch32/usb_drv.h @@ -5,8 +5,18 @@ #include "../../usb_driver_common.h" +// maximum number of endpoints that can be supported +#define USB_MAX_NUM_OF_ENDPOINTS (8) + // number of supported endpoints -#define USB_NUM_OF_ENDPOINTS (8) // set it to the maximum that this type of module can support +#ifndef USB_NUM_OF_ENDPOINTS // number of endpoints can be overridden to conserve memory +#define USB_NUM_OF_ENDPOINTS (USB_MAUSB_MAX_NUM_OF_ENDPOINTS) // set it to the maximum that this type of module can support +#else +#if USB_MAX_NUM_OF_ENDPOINTS > USB_MAX_NUM_OF_ENDPOINTS // do not allow greater number of endpoints than what the device supports +#undef USB_NUM_OF_ENDPOINTS +#define USB_NUM_OF_ENDPOINTS (USB_MUSB_MAX_NUM_OF_ENDPOINTS) +#endif +#endif // non isochronous transfers #define USB_MAX_FS_PCKT_SIZE_NON_ISOCHRONOUS (64)