Skip to content

nrf5x: Fix race condition during startup#1221

Merged
hathach merged 1 commit intohathach:masterfrom
kasjer:kasjer/fix-nrf5x-vbus-race-condition
Dec 8, 2021
Merged

nrf5x: Fix race condition during startup#1221
hathach merged 1 commit intohathach:masterfrom
kasjer:kasjer/fix-nrf5x-vbus-race-condition

Conversation

@kasjer
Copy link
Copy Markdown
Collaborator

@kasjer kasjer commented Dec 1, 2021

Describe the PR
When NRF5x device is reset by software (after DFU for example),
power event is ready from the beginning.
When power interrupt is triggered before tud_init() finished
USBD_IRQn is enabled before it would be enabled in tud_init().
This in turn may result in BUS RESET event being sent from
USB interrupt to USB task when queue is not initialized yet.
This scenario often happens in Mynewt build where queue creation
takes more time.

To prevent this scenario USBD_IRQn is not enabled in power event
interrupt handler before dcd_init() was called.

Additional context
Fixes #1154

This solution is simple enough but I'm opened to other solutions.

Copy link
Copy Markdown
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work, thank you for the fix. Though maybe we should use tud_inited() . nrf dcd use usbd_defer_func() API to schedule/defer function call anyway 😄

When NRF5x device is reset by software (after DFU for example),
power event is ready from the beginning.
When power interrupt is triggered before tud_init() finished
USBD_IRQn is enabled before it would be enabled in tud_init().
This in turn may result in BUS RESET event being sent from
USB interrupt to USB task when queue is not initialized yet.
This scenario often happens in Mynewt build where queue creation
takes more time.

To prevent this scenario USBD_IRQn is not enabled in power event
interrupt handler before dcd_init() was called.
@kasjer kasjer force-pushed the kasjer/fix-nrf5x-vbus-race-condition branch from a21efa9 to 21db235 Compare December 8, 2021 07:41
Copy link
Copy Markdown
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look great, thank you for the fix

@hathach
Copy link
Copy Markdown
Owner

hathach commented Dec 8, 2021

PS: github ci seesm to have network issue, need to re-run the build. will merge when it complete.

@hathach hathach merged commit 6bf7fba into hathach:master Dec 8, 2021
@kasjer kasjer deleted the kasjer/fix-nrf5x-vbus-race-condition branch December 8, 2021 19:53
7FM pushed a commit to 7FM/tinyusb that referenced this pull request Aug 23, 2025
This will enable builds to use pre-compiled copies of pioasm and elf2uf2, instead of requiring a native compiler.
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.

NRF5x startup race condition between VBUS interrupt and stack initialization

2 participants