maxikrie opened a new pull request, #21009:
URL: https://github.com/apache/nuttx/pull/21009
## Summary
The nRF52 USBD driver waits for VBUS forever at boot and never turns the
controller off again:
- `nrf52_hwinitialize()` spun until `USBREGSTATUS.VBUSDETECT` was set, so a
board running from a battery with USB device support configured hung in
`arm_usbinitialize()` during boot.
- Once enabled, the USBD stayed enabled after the cable was pulled, and an
enabled USBD keeps drawing current without VBUS: about 1.3 mA measured on a
XIAO nRF52840 running from its battery.
This PR makes the driver follow VBUS, in the order the nRF52840 Product
Specification gives:
- VBUS appears: enable the USBD, which starts the USB regulator;
- regulator ready (`USBREGSTATUS.OUTPUTRDY`) and a class driver bound:
connect the D+ pull-up;
- VBUS removed: disconnect, reset (the class driver sees the disconnect and
gets its requests back) and disable the USBD.
VBUS is polled every 500 ms from a watchdog, not taken from the POWER
`USBDETECTED`/`USBREMOVED` events. Their `POWER_CLOCK` interrupt belongs to
the SoftDevice Controller when BLE is enabled (`nrf52_sdc.c`), and polling
works the same with or without it.
The first commit fixes the nxstyle errors already in `nrf52_usbd.c`
(case-label indentation in `nrf52_ep0out_stdrequest()`), whitespace only:
`xiao-nrf52840:usbnsh` builds to the same `nuttx.bin` before and after it.
## Impact
- nRF52 boards with `CONFIG_USBDEV`: boot no longer waits for VBUS. With the
cable already plugged in at boot, the USBD is enabled in
`arm_usbinitialize()` as before; plugged in later, it is enabled within
500 ms.
- The USBD is disabled while unplugged, so it no longer draws current on
battery.
- One extra watchdog per USBD, firing every 500 ms.
- No Kconfig, API or build changes. The nRF53 driver (`nrf53_usbd.c`) has the
same VBUS wait and is not changed here.
## Testing
Host: Debian Linux (kernel 6.1), x86_64.
Toolchain: `arm-none-eabi-gcc (Arm GNU Toolchain 13.3.Rel1) 13.3.1 20240614`
Build (CMake/Ninja), all without warnings: `xiao-nrf52840:usbnsh`,
`xiao-nrf52840:jumbo`, `nrf52840-dongle:usbnsh`, `nrf52840-dk:cdcacm`,
`nrf52840-dk:composite`. Both commits pass `tools/checkpatch.sh`.
Hardware: XIAO nRF52840 Sense boards with a custom configuration (CDC-ACM,
tickless RTC), USB from a Linux host, battery on the BAT pads. The same logic
(with the state in file-scope variables instead of the device struct) has run
on these boards on NuttX 12.13.0 since 2026-10-20:
- running from the battery without USB, the board boots and runs its
application (without the change, `nrf52_hwinitialize()` waits for VBUS);
- idle current from the battery, measured with a Nordic PPK2 at 3.7 V,
dropped by about 1.3 mA with the USBD disabled while unplugged.
--
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]