RFC: Should the MicroPython RP2 port implement a PICO_PANIC_FUNCTION? #18736
Replies: 1 comment 2 replies
-
|
@Gadgetoid I think this would be really useful. My only request would be if it could still hit a breakpoint if the debugger is attached (it looks like it'll still do this, but just checking.) while (1) {
mp_event_handle_nowait();
sleep_ms(1);
}Not sure about this detail, as if there's a full panic it's probably not safe to execute any event callbacks. EDIT: Although I realise without this TinyUSB may not ever deliver the panic message to the host... ah...
I think ports are pretty inconsistent in how they handle both hard faults and panics at the moment, a lot will sit in an infinite loop of some kind. Printing something and sitting still is pretty useful for development debug (especially if the USB serial port vanishes on reset). However, it's really inconvenient for production use if you've got a device deployed somewhere and you'd actually like it to reset itself. There are board hooks to add custom panic handlers on some ports, but they're not available on every port. I have my own set of ideas about standardising this, but I haven't actually done anything about it. Something like what you've proposed here looks like a step in the right direction, to me. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For longer than I'd care to admit I let Pico SDK functions raise a
panicand basically lock up MicroPython with no useful output. This happens when attempting to claim DMA channels when they're exhausted, and for all sorts of other reasons that are easy to hit when re-running C/C++ device driver code upon soft reset.Defining
PICO_PANIC_FUNCTIONto print out the error usingmp_plat_printand sit in a loop reliably (as far as I can tell) gets the panic message out over USB serial and has been a time saver for chasing down hardware resource related bugs/lockups.I put this in the board config:
And this... somewhere:
Should this be included in the RP2 port by default? I don't believe it has any drawbacks. It would probably be ideal if it supplemented the format string with "PANIC: " to make it clear why the board has stopped responding.
Is there any precedent for this sort of thing in other ports I could follow?
The standard
panicimplementation is here: https://github.com/raspberrypi/pico-sdk/blob/a1438dff1d38bd9c65dbd693f0e5db4b9ae91779/src/rp2_common/pico_platform_panic/panic.c#L64-L83Beta Was this translation helpful? Give feedback.
All reactions