Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrf5x: Fix race condition during startup #1221

Merged

Conversation

kasjer
Copy link
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
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 😄

src/portable/nordic/nrf5x/dcd_nrf5x.c Outdated Show resolved Hide resolved
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
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
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
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