Repository navigation
rp2: Disable DMA IRQ before clearing handler function. - #18914
Conversation
|
@pdw-mb @agatti Thanks for the very clear bug report and the stack trace, made this very easy to fix. @agatti One slight niggle, your stack trace in the issue shows a crash happening earlier than mine did - and without the tell-tale |
|
Code size report: |
|
FWIW I'm not exactly sure why the DMA IRQ triggers at this point, because |
|
Thanks for looking into this. I verified the fix in this PR works on a RPI_PICO_W. And the fix here does seem like a very sensible thing to do even regardless of it fixing a known bug. I also found another patch which seems to fix it: --- a/ports/rp2/rp2_dma.c
+++ b/ports/rp2/rp2_dma.c
@@ -427,6 +427,8 @@ static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
uint8_t channel = self->channel;
if (channel != CHANNEL_CLOSED) {
+ dma_channel_set_irq0_enabled(channel, false);
+
// Reset this channel's registers to their default values (zeros).
dma_channel_config config = { .ctrl = 0 };
dma_channel_configure(channel, &config, NULL, NULL, 0, false);
@@ -441,7 +443,6 @@ static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
if (irq) {
irq->parent = MP_OBJ_NULL;
irq->handler = MP_OBJ_NULL;
- dma_channel_set_irq0_enabled(channel, false);
}
dma_channel_unclaim(channel);
self->channel = CHANNEL_CLOSED;and that patch also arguably makes sense regardless of it fixing any known bugs (ie disable the IRQ before resetting and aborting the DMA).
The patch I show just above maybe gives a hint here: the call to Yet another idea I had was to run What do you think is the best way to fix this? Maybe applying this PR and my patch above? |
8082e16 to
08ffbd3
Compare
Sounds good. I've done this and re-ran the rp2_dma.py unit test on a |
For what it's worth, your earlier patch did fix the issue in the same scenario (debug build, swd debugger attached) :) |
Both the overall IRQ line and the per-channel IRQ, for good measure. Otherwise, soft reset will remove the handler before the finaliser for the DMA object(s) run and trigger IRQs if the channel is still active. Closes micropython#18765 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
08ffbd3 to
d2cda57
Compare
|
Beginn der weitergeleiteten Nachricht:
…
Von: DHL Paket ***@***.***>
Datum: 15.05.2026 um 19:41
To: robert ***@***.***>
Betreff: Ihre Calzedoniac/o DHL PZ Ludwigsfelde Sendung ist unterwegs
Wichtige Informationen zu Ihrer Sendung
Onlineversion | Datenschutzhinweis zur Übersetzung
on
English English
Türkçe Türkçe
العربية العربية
Polski Polski
on on on on on
English
Türkçe
العربية
Polski
Español
Русский
Français
Italiano
Українська
עברית
Shqip
Română
Hallo,
Ihre Calzedoniac/o DHL PZ Ludwigsfelde Sendung wurde von uns bearbeitet und wird Ihnen voraussichtlich
am Samstag, den 16.05.
zugestellt.
Jetzt Zustelloption wählen
Ablageort buchen
An Nachbar:in liefern
Liefertag ändern
Paketmitnahme buchen
Sendungsstatus einsehen
JJD149990200046830871
Sie möchten keine oder nur noch bestimmte Informationen zu Ihrer Sendung erhalten?
E-Mail-Einstellungen verwalten
Datenschutzhinweise
Impressum
DHL Group
2026 © DHL Paket GmbH. All rights reserved.
|
Summary
WIthout this fix, soft reset will remove the IRQ handler before the finaliser for the DMA object(s) run and trigger IRQs if the channel is still active.
Closes #18765
This work was funded through GitHub Sponsors.
Testing
Ran the test case supplied with the issue and verified it crashes on
RPI_PICOwithout this fix, and doesn't crash with the fix. I wasn't able to reproduce the problem onRPI_PICO2_W, so possibly it's RP2040-only (was reported on RP2040).The stack trace shows the unhandled IRQ was to blame:
I have not added a regression test for this as I think there's no "clean" way to trigger a soft reset inside a test, the test would need to rely on the rp2 crashing after the test was "done" which seems a bit iffy.
Trade-offs and Alternatives
As there's a finite number of channels, we could conceivably track them statically and clean them up from
rp2_deinit()instead of waiting for finalisers to come and clean them up. However, I think relying on finalisers is OK now that the interrupt is disabled before we reach this point.Generative AI
I did not use generative AI tools when creating this PR.