Skip to content

Commit 2d54735

Browse files
gigaj0ulefpistm
authored andcommitted
Add single buffer mode option to USB to fix off-by-one corruption
When using the debug mode, halting the CPU at a breakpoint can create an occasional condition where the HAL USB state machine encounters an off-by-one error in the packet handling. This error is un-recoverable. completely breaks USB communications, and requires you to reset the STM32. This is caused by an issue with the double-buffering option available in the endpoint hardware. Adding the option to disable double buffer mode, and to allow single buffer mode, fixes this issue, and, in my tests, also improves reliability in USB communication with noisy systems, such as motor controllers. Single buffer mode can now be enabled with -DUSBD_CDC_USE_SINGLE_BUFFER at compile time. This commit does not break any other functions of STM32DUINO as far as I can tell.
1 parent dd84578 commit 2d54735

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: libraries/USBDevice/src/usbd_ep_conf.c

+4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ 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
4041
{CDC_OUT_EP, PMA_CDC_OUT_ADDR, PCD_DBL_BUF},
42+
#else
43+
{CDC_OUT_EP, PMA_CDC_OUT_ADDR, PCD_SNG_BUF},
44+
#endif
4145
{CDC_IN_EP, PMA_CDC_IN_ADDR, PCD_SNG_BUF},
4246
{CDC_CMD_EP, PMA_CDC_CMD_ADDR, PCD_SNG_BUF}
4347
#endif

0 commit comments

Comments
 (0)