feat(usb): add CDC/ACM suspend/resume check - #14
Closed
dakejahl wants to merge 1 commit into
Closed
Conversation
A USB device driver that reports CLASS_SUSPEND but never CLASS_RESUME leaves cdcacm_suspend()'s uart_connected(false) latched, after which serial.c refuses every board-side open() and write() on the CDC port with -ENOTCONN. The device stays enumerated, so nothing about the failure looks like a suspend bug. Linux hosts reach that state on their own, so the check only has to force it deterministically: each cycle re-arms runtime PM and confirms runtime_status actually reached suspended before judging anything, because a resumed device will not idle out again until PM is toggled. Bytes are counted over the whole read window and over its last second -- the first read after a broken resume still returns the stale CDC TX buffer, which on STM32H7 is a convincing 12 kB of nothing. Ported from a standalone script used to characterise apache/nuttx#19936, which unmasks WKUP in eight DWC2-derived device drivers. Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
raiden00pl
marked this pull request as draft
August 23, 2026 18:21
Member
|
this code doesnt belong to this repo. Test cases are in https://github.com/apache/nuttx-ntfc-testing |
Author
|
Agreed, thanks — reopened against nuttx-ntfc-testing as apache/nuttx-ntfc-testing#4, reworked into a pytest case rather than an |
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
Adds
ntfc usb-suspend, a host-side check that a NuttX USB CDC/ACM link survives Linux USB runtime suspend. Moved here from apache/nuttx#19936 at @xiaoxiang781216's request; that PR now carries the driver fix alone.Problem
A USB device driver that reports
CLASS_SUSPENDbut neverCLASS_RESUMEleavescdcacm_suspend()'suart_connected(&priv->serdev, false)latched, after whichserial.crefuses every board-sideopen()andwrite()on the CDC port with-ENOTCONNfor the rest of the boot. The device stays enumerated throughout and the host is perfectly happy, so nothing about the symptom points at suspend.Linux hosts reach that state unprompted — with
power/control=autoand the usualautosuspend_delay_ms=2000, closing the tty is enough — which is why this reads as an intermittent USB wedge rather than a deterministic bug, and why it needs a check that forces the transition instead of waiting for it.Solution
Each cycle re-arms runtime PM and waits for
runtime_statusto actually reachsuspendedbefore judging anything: a resumed device will not idle out again on its own until PM is toggled, so a naive loop measures nothing after the first cycle. Opening the port is what resumes the device.Bytes are counted both over the read window and over its trailing second. The tail count is what separates a working link from one that only flushed its stale CDC TX buffer on resume — on STM32H7 that stale buffer is a convincing 12 kB. With
--consoleon a second port, the board is also asked directly whether its CDC port is writable again.Exit codes: 0 recovered from every suspend, 1 did not, 2 the host never suspended so nothing was exercised.
Needs a Linux host,
sudofor two sysfs power attributes, a closed port, and a board that transmits unprompted. Takes no--confpath.Sample output against an ARK FMU v6X (STM32H743,
CONFIG_STM32H7_OTGFS=y,CONFIG_CDCACM=y), before the driver fix:and after:
tox -e lint,flake8,type,pypasses, coverage stays at 100%.