You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Tim Hardisty <ti...@gmail.com> on 2025/05/16 14:22:29 UTC

USB status notifications

Possibly not a NuttX-specific question.

Short version: how should an App go about determining USB 
connect/disconnect (or some higher level USB device status changes that 
signifies a successful, perhaps specified-type of connection to a host 
PC) in a portable way?

Long version (TL;DR ?): the processor on my board has USBDEV and USBHOST 
support that is intended for traditional and separate USB 2.0 
connectivity. I have wrapped a USB-C controller (FUSB302) around it so I 
can use a single (USB-C) connector as, essentially, an OTG connection. 
This works and auto-detects whatever is connected as needing host or 
device support and switches everything needed. Works a treat!

The USB-device usage is as a USB composite device (right now), one 
element of which is CDC-NCM, the other MSD. This fundamentally works but 
I have found that:

  * The DHCPD daemon can't be run *before* the first connection to the
    host otherwise it stops the CDC-NCM connection being established at
    all. It might be a bug in the (example app) daemon but the quick fix
    would be to start/stop it on USB connect/disconnect.
  * I want to run a (new) mDNS daemon on connection to advertise
    services, so I need to know when the USB is connected/disconnected
    and the CDC-NCM connection is valid.

So far I have considered:

 1. Moving my USB-C/FUSB302 auto switching worker function from being a
    board-level function to an app-level function, but it doesn't know
    what type of device connection has been made, nor if it was
    ultimately successful. Doesn't sound right.
 2. USBMONITOR has plenty reporting but it is a bit bewildering, is
    intended for DEBUG as I understand it, goes to syslog, and, anyway,
    the CDC-NCM code has no useful calls to USBTRACE (although I could
    add some.
 3. Write my own USBMONITOR task that makes use of the USBTRACE calls
    littered throughout the code...if only I could fathom the correct
    TRACE value (and then add that to CDC-NCM!). And probably not
    portable as it is NuttX-thing?

Since this is *surely* something others have needed to do in the 
NuttX/Linux/POSIX world, but my web trawling has so far failed to turn 
up anything, I am reaching out as ever to my learned and experienced 
e-friends here :-)

Thank you for reading :-)

TimH