-
Notifications
You must be signed in to change notification settings - Fork 399
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
detachInterrupt() from within ISR (freeRTOS) runs into Mutex #1441
Comments
Hmm arduino-pico/cores/rp2040/wiring_private.cpp Lines 145 to 154 in 6e52b72
You think the right path here would to check if we're inside an interrupt when detachInterrupt() is called and then not take the mutex? |
a speculative fix i came up with was adding Problem with that approach is, i don't know how the include system in the framework is supposed to work, so i shoehorned relative path includes to FreeRTOSConfig.h and portmacro.h to the CoreMutex.cpp file, and i am positive that's not how it's supposed to work :-) |
@caveman99 your suggestion sounds good. Do you have a PR you'd like to throw out there? The mutex can't be skipped because the underlying call uses a 32b bitmask which is a 3-cycle read/modify/write operation. So you can't safely clear or set a bit w/o it. Removing the mutex would require turning the 4-byte value into an array of 32 |
Automatically check, when in FreeRTOS, if we're in an ISR and if so call the correct mutex grab. Thanks to @caveman99 for finding and proposing a solution! Fixes #1441
Automatically check, when in FreeRTOS, if we're in an ISR and if so call the correct mutex grab. Thanks to @caveman99 for finding and proposing a solution! Fixes #1441
So I just read the 2nd part of your comment, @caveman99 . The FreeRTOS includes in the core are kind of obtuse since we don't use FreeRTOS and its in a library. I've done a proposed change implementing what you said. Could you give #1442 a try and report back, or offer suggestions if it's not what you had done? |
Thanks, that was exactly what i had in mind. I will test asap, was tied up today... |
If you pulled #1442 earlier, please re-pull the PR and try again. I forgot to handle the mutex_give_from_isr() portion in the destructor. That's been cleaned up, along with the manual special case I did for GPIO IRQ handling (taken care of by the real API am-i-in-isr call). |
Fixes #1439 Use a real FreeRTOS task, at the highest priority, to idle the other core while doing flash accesses. The USB stack seems to have some timing dependent bits which get broken if FreeRTOS switches out the current task when it's running. Avoid any issue by disabling preemption on the core for all tud_task calls. The PendSV handler disable flag can live completely inside the FreeRTOS variant port, so remove any reference to it in the main core. Tested using Multicode-FreeRTOS, #1402 and #1441 The USB FIFO interrupts were still being serviced even when the core was frozen, leading to crashes. Explicitly shut off IRQs on both the victim and the initiator core when freezing. Removed the need for hack __holdUpPendSV flag
Ping @caveman99 . Any update? |
i'm sorry, i have a surprise workload this week. will get to this asap monday or tuesday. |
* Fix FreeRTOS CoreMutex shim to handle ISRs Automatically check, when in FreeRTOS, if we're in an ISR and if so call the correct mutex grab. Thanks to @caveman99 for finding and proposing a solution! Fixes #1441 * Fix the CoreMutex destructor, too
I see that you merged the PR already, but I wanted to let you know that I just tested the Meshtastic firmware with this and it doesn't run into a deadlock upon receiving anymore. Thank you very much for the quick implementation! Looks like Meshtastic has another supported board :) |
Awesome, thanks for the feedback! Normally I'd wait for feedback, but the problem and solution were pretty obvious here so I' figured I'd take a shot to get out a new release this week. |
We are using Radiolib in Meshtastic. While porting the existing code (that runs fine on ESP32* an nRF52) to RP2040 we're running into a mutex deadlock when calling detachInterrupt through the Radiolib clearDio1Action() from a running ISR. This seems to be a similar issue as #878
There is more comments and a debug trace in meshtastic/firmware#2299
The calling code is as simple as
The text was updated successfully, but these errors were encountered: