Skip to content

Commit 8adf1fc

Browse files
committed
fix(usb): double buffer management
also enable USB double buffer for HALv2 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent e142d86 commit 8adf1fc

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎cores/arduino/stm32/stm32yyxx_hal_conf.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
#undef USE_HAL_PCD_MODULE
149149
#endif
150150
#define USE_HAL_PCD_MODULE 1U
151+
#if defined(USBD_CDC_USE_SINGLE_BUFFER)
152+
#define USE_HAL_PCD_USB_DOUBLE_BUFFER 0U
153+
#else
154+
#define USE_HAL_PCD_USB_DOUBLE_BUFFER 1U
155+
#endif
151156
#endif
152157

153158
#else /* HALv1 */

‎libraries/USBDevice/inc/usbd_ep_conf.h‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <stdint.h>
2626
#include "usbd_def.h"
2727

28+
#if defined (USE_HAL_PCD_USB_DOUBLE_BUFFER) && (USE_HAL_PCD_USB_DOUBLE_BUFFER == 0)
29+
#define USBD_CDC_USE_SINGLE_BUFFER
30+
#endif
31+
2832
typedef struct {
2933
uint32_t ep_adress; /* Endpoint address */
3034
uint32_t ep_size; /* Endpoint size */
@@ -69,21 +73,15 @@ typedef struct {
6973

7074
#ifdef USBD_USE_CDC
7175
#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
76+
#if !defined(USBD_CDC_USE_SINGLE_BUFFER)
8277
#define PMA_CDC_OUT_ADDR ((PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE) | \
8378
(PMA_CDC_OUT_BASE << 16U))
8479
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE * 2)
85-
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + CDC_CMD_PACKET_SIZE)
80+
#else
81+
#define PMA_CDC_OUT_ADDR PMA_CDC_OUT_BASE
82+
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE)
8683
#endif
84+
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + CDC_CMD_PACKET_SIZE)
8785
#endif /* USBD_USE_CDC */
8886
#ifdef USBD_USE_HID_COMPOSITE
8987
#define PMA_MOUSE_IN_ADDR (PMA_EP0_IN_ADDR + HID_MOUSE_EPIN_SIZE)

‎libraries/USBDevice/src/usbd_ep_conf.c‎

Lines changed: 1 addition & 1 deletion
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-
#if !defined(STM32C5xx) && !defined(USBD_CDC_USE_SINGLE_BUFFER)
40+
#if !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},

0 commit comments

Comments
 (0)