Skip to content

Commit e8a3282

Browse files
authored
Merge pull request #13816 from pennam/patch-stm32-usbhs-pull
STM32: allow HS USB endpoints and increase USB OTG_HS endpoints number
2 parents f550ed3 + f1ea281 commit e8a3282

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

drivers/include/drivers/USBCDC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class AsyncOp;
3333
* @{
3434
*/
3535

36+
#define CDC_MAX_PACKET_SIZE 64
37+
3638
class USBCDC: public USBDevice {
3739
public:
3840

@@ -219,13 +221,13 @@ class USBCDC: public USBDevice {
219221

220222
OperationList<AsyncWrite> _tx_list;
221223
bool _tx_in_progress;
222-
uint8_t _tx_buffer[64];
224+
uint8_t _tx_buffer[CDC_MAX_PACKET_SIZE];
223225
uint8_t *_tx_buf;
224226
uint32_t _tx_size;
225227

226228
OperationList<AsyncRead> _rx_list;
227229
bool _rx_in_progress;
228-
uint8_t _rx_buffer[64];
230+
uint8_t _rx_buffer[CDC_MAX_PACKET_SIZE];
229231
uint8_t *_rx_buf;
230232
uint32_t _rx_size;
231233
};

drivers/source/usb/USBCDC.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ static const uint8_t cdc_line_coding_default[7] = {0x80, 0x25, 0x00, 0x00, 0x00,
3434
#define CLS_DTR (1 << 0)
3535
#define CLS_RTS (1 << 1)
3636

37-
#define CDC_MAX_PACKET_SIZE 64
38-
3937
class USBCDC::AsyncWrite: public AsyncOp {
4038
public:
4139
AsyncWrite(USBCDC *serial, uint8_t *buf, uint32_t size):

targets/TARGET_STM/USBPhy_STM32.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,29 @@
2929
#define IDX_TO_EP(idx) (((idx) >> 1)|((idx) & 1) << 7)
3030

3131
/* endpoint defines */
32-
#define NUM_ENDPOINTS 4
32+
33+
#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
34+
35+
#define NUM_ENDPOINTS 6
36+
#define MAX_PACKET_SIZE_NON_ISO 512
37+
#define MAX_PACKET_SIZE_ISO 1023
38+
39+
#else
40+
41+
#define NUM_ENDPOINTS 4
3342
#define MAX_PACKET_SIZE_NON_ISO 64
3443
#define MAX_PACKET_SIZE_ISO (256 + 128) // Spec can go up to 1023, only ram for this though
3544

45+
#endif
46+
3647
static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = {
3748
MAX_PACKET_SIZE_NON_ISO,
3849
MAX_PACKET_SIZE_NON_ISO,
3950
MAX_PACKET_SIZE_NON_ISO,
51+
#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
52+
MAX_PACKET_SIZE_NON_ISO,
53+
MAX_PACKET_SIZE_NON_ISO,
54+
#endif
4055
MAX_PACKET_SIZE_ISO
4156
};
4257

@@ -333,8 +348,11 @@ void USBPhyHw::init(USBPhyEvents *events)
333348
total_bytes += fifo_size;
334349
}
335350

351+
#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
336352
/* 1.25 kbytes */
337353
MBED_ASSERT(total_bytes <= 1280);
354+
#endif
355+
338356
#endif
339357

340358
// Configure interrupt vector
@@ -424,11 +442,18 @@ void USBPhyHw::remote_wakeup()
424442
const usb_ep_table_t *USBPhyHw::endpoint_table()
425443
{
426444
static const usb_ep_table_t table = {
445+
#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
427446
1280, // 1.25K for endpoint buffers but space is allocated up front
447+
#else
448+
4096,
449+
#endif
428450
{
429451
{USB_EP_ATTR_ALLOW_CTRL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
430452
{USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO
431453
{USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO
454+
#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
455+
{USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
456+
#endif
432457
{USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
433458
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
434459
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
@@ -441,7 +466,9 @@ const usb_ep_table_t *USBPhyHw::endpoint_table()
441466
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
442467
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
443468
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
469+
#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
444470
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}
471+
#endif
445472
}
446473
};
447474
return &table;

0 commit comments

Comments
 (0)