Skip to content

Commit 73e186f

Browse files
committed
fix(usb): use non-overlapping C5 CDC PMA buffers
1 parent 178420b commit 73e186f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎libraries/USBDevice/inc/usbd_ep_conf.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,21 @@ typedef struct {
6969

7070
#ifdef USBD_USE_CDC
7171
#define PMA_CDC_OUT_BASE (PMA_EP0_IN_ADDR + USB_MAX_EP0_SIZE)
72+
#if defined(STM32C5xx)
73+
/*
74+
* The C5 USB DRD FS peripheral is used with bulk double buffering disabled.
75+
* Keep each CDC endpoint in its own 64-byte PMA area; in particular, the
76+
* interrupt IN endpoint must not overlap the bulk IN data buffer.
77+
*/
78+
#define PMA_CDC_OUT_ADDR PMA_CDC_OUT_BASE
79+
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE)
80+
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + USB_FS_MAX_PACKET_SIZE)
81+
#else
7282
#define PMA_CDC_OUT_ADDR ((PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE) | \
7383
(PMA_CDC_OUT_BASE << 16U))
7484
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE * 2)
7585
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + CDC_CMD_PACKET_SIZE)
86+
#endif
7687
#endif /* USBD_USE_CDC */
7788
#ifdef USBD_USE_HID_COMPOSITE
7889
#define PMA_MOUSE_IN_ADDR (PMA_EP0_IN_ADDR + HID_MOUSE_EPIN_SIZE)
@@ -86,4 +97,4 @@ extern const ep_desc_t ep_def[DEV_NUM_EP + 1];
8697
#endif /* USBCON */
8798
#endif /* __USBD_EP_CONF_H */
8899

89-
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
100+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

‎libraries/USBDevice/src/usbd_ep_conf.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ep_desc_t ep_def[] = {
3737
#else
3838
{0x00, PMA_EP0_OUT_ADDR, PCD_SNG_BUF},
3939
{0x80, PMA_EP0_IN_ADDR, PCD_SNG_BUF},
40-
#ifndef USBD_CDC_USE_SINGLE_BUFFER
40+
#if !defined(STM32C5xx) && !defined(USBD_CDC_USE_SINGLE_BUFFER)
4141
{CDC_OUT_EP, PMA_CDC_OUT_ADDR, PCD_DBL_BUF},
4242
#else
4343
{CDC_OUT_EP, PMA_CDC_OUT_ADDR, PCD_SNG_BUF},
@@ -72,4 +72,3 @@ const ep_desc_t ep_def[] = {
7272

7373
#endif /* HAL_PCD_MODULE_ENABLED && USBCON */
7474
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
75-

0 commit comments

Comments
 (0)