dakejahl opened a new pull request, #14:
URL: https://github.com/apache/nuttx-ntfc/pull/14

   ## Summary
   
   Adds `ntfc usb-suspend`, a host-side check that a NuttX USB CDC/ACM link 
survives Linux USB runtime suspend. Moved here from 
https://github.com/apache/nuttx/pull/19936 at @xiaoxiang781216's request; that 
PR now carries the driver fix alone.
   
   ## 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. With `--console` on 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, `sudo` for 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:
   
   ```
   [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.
   ```
   
   `tox -e lint,flake8,type,py` passes, coverage stays at 100%.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to