dcd/musb: defer EP0 SETUP during DATA_IN/STATUS race#3643
Open
HiFiPhile wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Mentor MUSB device controller (DCD) EP0 control-transfer state machine to better handle a race where a new SETUP arrives before the prior control transfer has fully completed (typically under high CPU load). It also adjusts MUSB port headers to avoid multiple-definition linkage issues around MUSB_BASES.
Changes:
- Split EP0 DATA state into explicit
DATA_IN/DATA_OUTstates and add buffering of a “deferred” SETUP request to replay after status completion. - Add logic to complete pending STATUS stages before dispatching the deferred SETUP.
- Make
MUSB_BASESstatic constin MUSB port headers to prevent ODR/multiple-definition problems.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/portable/mentor/musb/musb_ti.h | Make MUSB_BASES static const to avoid multiple definitions across translation units. |
| src/portable/mentor/musb/musb_max32.h | Same MUSB_BASES linkage fix for the MAX32 port. |
| src/portable/mentor/musb/dcd_musb.c | Rework EP0 control-transfer state machine and add deferred-SETUP buffering/replay to handle SETUP vs status/data completion races. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
TinyUSB Average Code Size Metrics
Input files
|
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| msp_exp432e401y/dfu_runtime | 8,592 → 8,816 (+224) | — | — | 1,048 → 1,056 (+8) | 10,372 → 10,604 (+232) | +2.2% |
| msp_exp432e401y/hid_generic_inout | 9,644 → 9,868 (+224) | — | — | 1,252 → 1,260 (+8) | 11,628 → 11,860 (+232) | +2.0% |
| msp_exp432e401y/hid_multiple_interface | 10,428 → 10,652 (+224) | — | — | 1,128 → 1,136 (+8) | 12,288 → 12,520 (+232) | +1.9% |
| msp_exp432e401y/hid_boot_interface | 10,440 → 10,664 (+224) | — | — | 1,128 → 1,136 (+8) | 12,300 → 12,532 (+232) | +1.9% |
| msp_exp432e401y/hid_composite | 10,652 → 10,876 (+224) | — | — | 1,116 → 1,124 (+8) | 12,500 → 12,732 (+232) | +1.9% |
| msp_exp432e401y/midi_test | 10,748 → 10,972 (+224) | — | — | 1,248 → 1,256 (+8) | 12,728 → 12,960 (+232) | +1.8% |
| ek_tm4c123gxl/dfu_runtime | 8,540 → 8,772 (+232) | — | — | 612 → 620 (+8) | 13,316 → 13,556 (+240) | +1.8% |
| msp_exp432e401y/cdc_dual_ports | 11,592 → 11,816 (+224) | — | — | 1,432 → 1,440 (+8) | 13,756 → 13,988 (+232) | +1.7% |
| msp_exp432e401y/printer_to_cdc | 11,716 → 11,940 (+224) | — | — | 1,412 → 1,420 (+8) | 13,852 → 14,084 (+232) | +1.7% |
| ek_tm4c123gxl/hid_generic_inout | 9,536 → 9,768 (+232) | — | — | 816 → 824 (+8) | 14,512 → 14,752 (+240) | +1.7% |
Handle cases where a new SETUP arrives before the previous control transfer fully completes by buffering the SETUP and replaying it after status completion. Split EP0 DATA state into DATA_IN/DATA_OUT and finalize pending status-out completion before processing deferred SETUP. Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
This was referenced May 15, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handle cases where a new SETUP arrives before the previous control transfer fully completes by buffering the SETUP and replaying it after status completion. Split EP0 DATA state into DATA_IN/DATA_OUT and finalize pending status-out completion before processing deferred SETUP.
Take care these 2 cases if new SETUP packet arrived while old control transfer is not finished yet. This could happen in following scenarios when CPU load is high:
Supercede #3626
Tested intensively with DFU example with Interrupt turned on/off every 20ms simulating high CP load: