Skip to content

nrf52840: add USBVBusPresent to detect USB cable unplug via SoftDevice#462

Open
sago35 wants to merge 1 commit into
devfrom
usbvbuspresent
Open

nrf52840: add USBVBusPresent to detect USB cable unplug via SoftDevice#462
sago35 wants to merge 1 commit into
devfrom
usbvbuspresent

Conversation

@sago35

@sago35 sago35 commented Jul 21, 2026

Copy link
Copy Markdown
Member

The POWER peripheral is restricted while the SoftDevice is enabled, so USB VBUS presence must be read through sd_power_usbregstatus_get instead of machine's own USB detection.

This matters because TinyGo's machine layer never notices the cable being unplugged (the USB power SOC events are drained unhandled by this package's event pump), so on a battery-powered device with a serial monitor attached, machine.Serial.Write blocks forever once its TX ring fills up after unplug. Callers can guard debug output with this function.

The POWER peripheral is restricted while the SoftDevice is enabled, so
USB VBUS presence must be read through sd_power_usbregstatus_get
instead of machine's own USB detection.

This matters because TinyGo's machine layer never notices the cable
being unplugged (the USB power SOC events are drained unhandled by
this package's event pump), so on a battery-powered device with a
serial monitor attached, machine.Serial.Write blocks forever once its
TX ring fills up after unplug. Callers can guard debug output with
this function.
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