Skip to content

bugfix: shut down nRF52820 and turn off LED when USB disconnected - #19

Open
m4rkw wants to merge 2 commits into
makerdiary:mainfrom
m4rkw:main
Open

bugfix: shut down nRF52820 and turn off LED when USB disconnected#19
m4rkw wants to merge 2 commits into
makerdiary:mainfrom
m4rkw:main

Conversation

@m4rkw

@m4rkw m4rkw commented Aug 15, 2026

Copy link
Copy Markdown

Hi

I'm building an open-source vehicle tracker that uses the Connect Kit (see: https://l0destar.com) and believe I have identified a bug in the nRF52820 firmware.

My prototypes have a sleep current of 120 µA but I noticed that if I connect the USB interface and disconnect it again this jumps to around 2mA and the green LED on the Connect Kit stays on when it was off before. It seems that after VBUS removal the USB stack is disabled but the UART bridge peripheral keeps HFCLK running (~2mA), and the green status LED stays lit (~300µA). The chip stays in this state indefinitely.

This is a problem for my boards because they're intended to be hardwired into vehicles and so minimal sleep current is critical.

The patch adds set_all_leds_off() + sys_poweroff() to two paths in main.c: the USBD_MSG_VBUS_REMOVED callback, and a VBUS check at the top of main() for the case where the board boots without a USB cable. In SYSTEM OFF the nRF52820 draws ~0.3µA and wakes automatically on VBUS detect, rebooting with full functionality (CMSIS-DAP, UART bridge, shell, charger).

In my testing this completely resolves the issue, after unplugging the USB and letting the device go back to sleep its current is once again 120 µA. Reconnecting the cable still works normally.

Cheers,
Mark

@m4rkw

m4rkw commented Aug 15, 2026

Copy link
Copy Markdown
Author

wait there's a problem with this - closing for now

@m4rkw m4rkw closed this Aug 15, 2026
@m4rkw

m4rkw commented Aug 15, 2026

Copy link
Copy Markdown
Author

The change fixes the sleep current issue but breaks ability to flash over USB. Investigating at the moment.

@m4rkw m4rkw reopened this Aug 15, 2026
@m4rkw

m4rkw commented Aug 15, 2026

Copy link
Copy Markdown
Author

Good to go now, was actually two issues:

  1. I was building with NCS v3.3.0, this requires v3.4.0. This was why flashing was broken after updating the firmware.

  2. The system poweroff call wasn't actually working, it was just never activating the interface in the first place which is why the current measured low, it hadn't actually fixed the problem. Zephyr sets SEVONPEND in the Cortex-M SCR register at boot. With SEVONPEND set, any pending interrupt (even masked by PRIMASK) causes WFE to return immediately. The v3.4.0 UDC driver enables POWER USB event interrupts that weren't present in v3.3.0, so nrf_power_system_off()'s while(true) { __WFE(); } loop spins forever instead of entering SYSTEM OFF.

The new enter_system_off() wrapper clears SEVONPEND before calling sys_poweroff(), letting WFE actually sleep.

This is now tested and working, flashing still works and my sleep current is back at ~120 µA.

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.

1 participant