[BACKPORT] fix(arch/otg): unmask WKUP so USB resume reaches the class driver - #393
Merged
dakejahl merged 1 commit intoAug 25, 2026
Conversation
… driver Every DWC2-derived USB device driver enables USBSUSP in GINTMSK but not WKUP, and every one of them ANDs GINTSTS with GINTMSK before dispatch. The resume handler is therefore unreachable: CLASS_SUSPEND is delivered on suspend, CLASS_RESUME never is. For CDC/ACM that is fatal. cdcacm_suspend() calls uart_connected(false), after which serial.c refuses every open() and write() with -ENOTCONN, and the cdcacm_resume() that would clear it never runs. On a Linux host with the default USB autosuspend (power/control=auto, 2000 ms) simply closing the tty is enough to trip it, and the port stays dead for the rest of the boot while the device remains enumerated. Verified on STM32H7 (ARK FMU v6X): before, one host suspend leaves the CDC/ACM port permanently -ENOTCONN; after, five forced suspend/resume cycles all recover with the MAVLink stream intact. The remaining drivers carry a line-for-line copy of the same initialisation. Upstream: apache/nuttx#19936 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
dakejahl
added a commit
to PX4/PX4-Autopilot
that referenced
this pull request
Aug 25, 2026
Brings in PX4/NuttX#393 (backport of apache/nuttx#19936). The DWC2-derived USB device drivers masked off the WKUP interrupt, so CLASS_RESUME was never delivered. cdcacm_suspend() marks the serial device disconnected and the matching resume never runs, leaving the CDC/ACM port returning -ENOTCONN for the rest of the boot after the first host autosuspend. Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
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.
Summary
Backport of apache/nuttx#19936.
The DWC2-derived USB device drivers enable
USBSUSPinGINTMSKbut notWKUP, and each one ANDsGINTSTSwithGINTMSKat the top of its ISR before dispatching. TheWKUPbranch and the*_resumeinterrupt()it calls are dead code:CLASS_SUSPENDis delivered,CLASS_RESUMEnever is.For CDC/ACM that is fatal.
cdcacm_suspend()callsuart_connected(&priv->serdev, false), after whichserial.crefuses every board-sideopen()andwrite()with-ENOTCONN. Thecdcacm_resume()that would clear it never runs, so the port is unusable for the rest of the boot while the device stays enumerated.Adding
WKUPto the mask makes the existing handler reachable. The status bit is already acknowledged in the same read/ack cycle as the other writable interrupts, so unmasking it cannot latch.The upstream PR also carries a host-side test script; it is left out here.
Impact
Fixes PX4/PX4-Autopilot#28340 once the submodule is bumped.
Affects every PX4 board with
CONFIG_CDCACM=y, which is 152 in-tree NuttX configs: 113 on STM32H7, 21 on STM32F7, 18 on STM32 F4.CDCACMselectsSERIAL_REMOVABLE, so no board opts into this — they all inherit it.Linux hosts trigger it by default: with
power/control=autoand the usualautosuspend_delay_ms=2000, closing the tty is enough. QGroundControl holds the port open continuously and so never sees it; CLI tooling that opens, reads and closes —mavlink_shell.py, pymavlink scripts, production test benches — loses USB MAVLink on the first close and does not get it back without a reboot.No configuration, API or wire-format change. One extra interrupt source per suspend/resume, handled by code already present.
Testing
Host: Linux 7.0.0-28-generic x86_64, xhci_hcd,
usbcore.autosuspend=2.Board: ARK FMU v6X (STM32H743),
ark_fmu-v6x_default, console on a separate STLINK-V3 VCP so it survives the CDC port dying.Only the STM32H7 path was exercised on hardware. The other five drivers carry a line-for-line copy of the same
GINTMSKinitialisation and the same masked-off resume handler.Each cycle forces a verified USB runtime suspend, resumes the device by opening the port, reads for 2 s, then asks the board over its console whether the CDC port is writable again.
Before:
readis bytes over the whole 2 s window,tailbytes in its last second. The 12179 on the first cycle is the staleCONFIG_CDCACM_TXBUFSIZE=12000buffer flushing on resume, not a working link.After:
On the unpatched build, one host suspend is enough to kill the port for good:
Patched, the same command succeeds once the host resumes, and a 22 s suspend is followed by full recovery:
mavlink statusinstance #2 back totx 21946 B/s,txerr 0.0 B/s, 217 kB read by the host over the following 10 s.Build-tested beyond STM32H7:
cubepilot_cubeyellow(stm32f7),airmind_mindpx-v2(stm32 OTGFS),matek_gnss-m9n-f4(stm32 OTGHS).