Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add single buffer mode option to USB CDC to fix off-by-one corruption #2435

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

gigaj0ule
Copy link
Contributor

This PR fixes/implements the following bugs/features

[Bug]

When using the debug mode, halting the CPU at a breakpoint can create a 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.

[Fix]

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.

[Breaking: None]

This commit does not break any functions of STM32DUINO and is a completely optional command-line option.

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.
@fpistm fpistm added the enhancement New feature or request label Jul 15, 2024
@fpistm fpistm self-requested a review July 15, 2024 07:40
@fpistm fpistm added this to In progress in STM32 core based on ST HAL via automation Jul 15, 2024
@fpistm fpistm linked an issue Jul 15, 2024 that may be closed by this pull request
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issue foreseen.
LGTM

STM32 core based on ST HAL automation moved this from In progress to Reviewer approved Jul 15, 2024
@fpistm fpistm merged commit 2d54735 into stm32duino:main Jul 15, 2024
23 checks passed
STM32 core based on ST HAL automation moved this from Reviewer approved to Done Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

CDC_ReceiveQueue fails after CPU halt
2 participants