Skip to content

test(usb): add CDC/ACM suspend/resume check - #4

Open
dakejahl wants to merge 1 commit into
apache:mainfrom
dakejahl:feature/usb-suspend-check
Open

test(usb): add CDC/ACM suspend/resume check#4
dakejahl wants to merge 1 commit into
apache:mainfrom
dakejahl:feature/usb-suspend-check

Conversation

@dakejahl

Copy link
Copy Markdown

Summary

Adds driver/usb, a check that a NuttX USB CDC/ACM link survives Linux USB runtime suspend. Moved here from apache/nuttx-ntfc#14, which put it in the framework repository; test cases belong here.

Problem

A USB device driver that reports CLASS_SUSPEND but never CLASS_RESUME leaves cdcacm_suspend()'s uart_connected(&priv->serdev, false) latched, after which serial.c refuses every board-side open() and write() on the CDC port with -ENOTCONN for 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=auto and the usual autosuspend_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_status to actually reach suspended before 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. The board is then asked over the NTFC console whether its own CDC port is writable again.

The test skips rather than fails whenever the host cannot be brought into a measurable state: not Linux, no passwordless sudo for the two sysfs power attributes, no CDC/ACM port, the port already held open, or a device that never actually suspended.

Wiring comes from the environment — NTFC_USB_CDC_DEVICE is the host path of the port under test, defaulting to the only CDC/ACM port present, and NTFC_USB_CDC_PATH is the same port as the board names it. The port under test must not be the NTFC console, since an open port pins runtime PM.

Measurements below are from the standalone form of this check against an ARK FMU v6X (STM32H743, CONFIG_STM32H7_OTGFS=y, CONFIG_CDCACM=y), before the driver fix in apache/nuttx#19936:

[1] suspended=True   read=12179   tail=0       board-side open failed: -ENOTCONN
[2] suspended=True   read=0       tail=0       board-side open failed: -ENOTCONN

FAIL: the link died after suspend and did not come back.

and after:

[1] suspended=True   read=40898   tail=23316   board-side open ok
[2] suspended=True   read=42441   tail=22020   board-side open ok

PASS: the link recovered from every suspend.

The host-side measurement is unchanged here; the board-side probe now goes through pytest.product.sendCommand instead of a second serial port. I have no v6X on the bench at the moment, so this pytest form itself has not yet been run against hardware — happy to re-run and post output once it is back.

black, isort and flake8 are clean.

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.

Written to characterise apache/nuttx#19936, which
unmasks WKUP in eight DWC2-derived device drivers.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Comment thread driver/usb/test_driver_usb_integration.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants