From db7954bc9b80986d57805e5f97849a285f9dad63 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 17 Mar 2020 11:37:07 +0100 Subject: [PATCH 1/2] STM32: allow high speed USB endpoints --- drivers/include/drivers/USBCDC.h | 6 ++++-- drivers/source/usb/USBCDC.cpp | 2 -- targets/TARGET_STM/USBPhy_STM32.cpp | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/include/drivers/USBCDC.h b/drivers/include/drivers/USBCDC.h index 5f173c84a69..777b352ad00 100644 --- a/drivers/include/drivers/USBCDC.h +++ b/drivers/include/drivers/USBCDC.h @@ -33,6 +33,8 @@ class AsyncOp; * @{ */ +#define CDC_MAX_PACKET_SIZE 64 + class USBCDC: public USBDevice { public: @@ -219,13 +221,13 @@ class USBCDC: public USBDevice { OperationList _tx_list; bool _tx_in_progress; - uint8_t _tx_buffer[64]; + uint8_t _tx_buffer[CDC_MAX_PACKET_SIZE]; uint8_t *_tx_buf; uint32_t _tx_size; OperationList _rx_list; bool _rx_in_progress; - uint8_t _rx_buffer[64]; + uint8_t _rx_buffer[CDC_MAX_PACKET_SIZE]; uint8_t *_rx_buf; uint32_t _rx_size; }; diff --git a/drivers/source/usb/USBCDC.cpp b/drivers/source/usb/USBCDC.cpp index e4e1737f154..9cf1ed04d9e 100644 --- a/drivers/source/usb/USBCDC.cpp +++ b/drivers/source/usb/USBCDC.cpp @@ -34,8 +34,6 @@ static const uint8_t cdc_line_coding_default[7] = {0x80, 0x25, 0x00, 0x00, 0x00, #define CLS_DTR (1 << 0) #define CLS_RTS (1 << 1) -#define CDC_MAX_PACKET_SIZE 64 - class USBCDC::AsyncWrite: public AsyncOp { public: AsyncWrite(USBCDC *serial, uint8_t *buf, uint32_t size): diff --git a/targets/TARGET_STM/USBPhy_STM32.cpp b/targets/TARGET_STM/USBPhy_STM32.cpp index 51049c959de..247fed582b8 100644 --- a/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/targets/TARGET_STM/USBPhy_STM32.cpp @@ -29,10 +29,21 @@ #define IDX_TO_EP(idx) (((idx) >> 1)|((idx) & 1) << 7) /* endpoint defines */ -#define NUM_ENDPOINTS 4 + +#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS) + +#define NUM_ENDPOINTS 6 +#define MAX_PACKET_SIZE_NON_ISO 512 +#define MAX_PACKET_SIZE_ISO 1023 // Spec can go up to 1023, only ram for this though + +#else + +#define NUM_ENDPOINTS 4 #define MAX_PACKET_SIZE_NON_ISO 64 #define MAX_PACKET_SIZE_ISO (256 + 128) // Spec can go up to 1023, only ram for this though +#endif + static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = { MAX_PACKET_SIZE_NON_ISO, MAX_PACKET_SIZE_NON_ISO, @@ -333,8 +344,11 @@ void USBPhyHw::init(USBPhyEvents *events) total_bytes += fifo_size; } +#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS) /* 1.25 kbytes */ MBED_ASSERT(total_bytes <= 1280); +#endif + #endif // Configure interrupt vector From f1ea281613244e4b6a2129509d0e398749eca065 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 27 Aug 2020 11:46:29 +0200 Subject: [PATCH 2/2] STM32: USB: allow more endpoints for OTG_HS ports --- targets/TARGET_STM/USBPhy_STM32.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_STM/USBPhy_STM32.cpp b/targets/TARGET_STM/USBPhy_STM32.cpp index 247fed582b8..63ec3c974b6 100644 --- a/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/targets/TARGET_STM/USBPhy_STM32.cpp @@ -34,7 +34,7 @@ #define NUM_ENDPOINTS 6 #define MAX_PACKET_SIZE_NON_ISO 512 -#define MAX_PACKET_SIZE_ISO 1023 // Spec can go up to 1023, only ram for this though +#define MAX_PACKET_SIZE_ISO 1023 #else @@ -48,6 +48,10 @@ static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = { MAX_PACKET_SIZE_NON_ISO, MAX_PACKET_SIZE_NON_ISO, MAX_PACKET_SIZE_NON_ISO, +#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS) + MAX_PACKET_SIZE_NON_ISO, + MAX_PACKET_SIZE_NON_ISO, +#endif MAX_PACKET_SIZE_ISO }; @@ -438,11 +442,18 @@ void USBPhyHw::remote_wakeup() const usb_ep_table_t *USBPhyHw::endpoint_table() { static const usb_ep_table_t table = { +#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS) 1280, // 1.25K for endpoint buffers but space is allocated up front +#else + 4096, +#endif { {USB_EP_ATTR_ALLOW_CTRL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, {USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO {USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO +#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS) + {USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, +#endif {USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, @@ -455,7 +466,9 @@ const usb_ep_table_t *USBPhyHw::endpoint_table() {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, +#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS) {0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0} +#endif } }; return &table;