dcd/musb: defer EP0 SETUP during DATA_IN/STATUS race#3643
Conversation
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.
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in size
Changes <1% in sizeNo entries. No changes
|
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| msp_exp432e401y/dfu_runtime | 8,592 → 8,832 (+240) | — | — | 1,048 → 1,056 (+8) | 10,372 → 10,620 (+248) | +2.4% |
| msp_exp432e401y/hid_generic_inout | 9,644 → 9,884 (+240) | — | — | 1,252 → 1,260 (+8) | 11,628 → 11,876 (+248) | +2.1% |
| msp_exp432e401y/hid_multiple_interface | 10,428 → 10,668 (+240) | — | — | 1,128 → 1,136 (+8) | 12,288 → 12,536 (+248) | +2.0% |
| msp_exp432e401y/hid_boot_interface | 10,440 → 10,680 (+240) | — | — | 1,128 → 1,136 (+8) | 12,300 → 12,548 (+248) | +2.0% |
| msp_exp432e401y/hid_composite | 10,652 → 10,892 (+240) | — | — | 1,116 → 1,124 (+8) | 12,500 → 12,748 (+248) | +2.0% |
| msp_exp432e401y/midi_test | 10,748 → 10,988 (+240) | — | — | 1,248 → 1,256 (+8) | 12,728 → 12,976 (+248) | +1.9% |
| ek_tm4c123gxl/dfu_runtime | 8,540 → 8,780 (+240) | — | — | 612 → 620 (+8) | 13,316 → 13,564 (+248) | +1.9% |
| msp_exp432e401y/cdc_dual_ports | 11,592 → 11,832 (+240) | — | — | 1,432 → 1,440 (+8) | 13,756 → 14,004 (+248) | +1.8% |
| msp_exp432e401y/printer_to_cdc | 11,716 → 11,956 (+240) | — | — | 1,412 → 1,420 (+8) | 13,852 → 14,100 (+248) | +1.8% |
| msp_exp432e401y/webusb_serial | 12,096 → 12,336 (+240) | — | — | 1,420 → 1,428 (+8) | 14,248 → 14,496 (+248) | +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>
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: