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..63ec3c974b6 100644 --- a/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/targets/TARGET_STM/USBPhy_STM32.cpp @@ -29,14 +29,29 @@ #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 + +#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, 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 }; @@ -333,8 +348,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 @@ -424,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}, @@ -441,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;