fix nrf hanged (blocking wait) when called within critical section #416
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the PR
This implement an alternative approach to #396 to solve issue when TinyUSB API is called within an critical section with CPSR-I bit disabled (global interrupt) and/or NVIC USB disabled. Due to the EasyDMA can only has 1 active transfer at a time, the dcd_edpt_xfer() must wait until the previous DMA complete before starting its own.
Although #396 work fine with noOS, with an RTOS such as freeRTOS, any queue push API called within critical section as result of
dcd_init_handler()can potentially cause problem (even withISR API). Since freeRTOS and/or other RTOS probably use the CPSR-I for enterring critical section within the queue API as well.This PR count the ENDED events comparing with pending dma to determine if previous DMA is complete and should be safe to use. This is really an edge case, user shouldn't call TinyUSB API within critical section in the first place !!!
Fix segger project for nrf52 cdc_msc example when debugging
Additional context
related to adafruit/circuitpython#2868