@@ -220,12 +220,34 @@ void __attribute__((noreturn)) panic_unsupported() {
220
220
panic ("not supported" );
221
221
}
222
222
223
+ // PICO_CONFIG: PICO_PANIC_FUNCTION, Name of a function to use in place of the stock panic function or empty string to simply breakpoint on panic, default=panic, group=pico_runtime
224
+ // note the default is not "panic" it is undefined
225
+ #ifdef PICO_PANIC_FUNCTION
226
+ #define PICO_PANIC_FUNCTION_EMPTY (__CONCAT(PICO_PANIC_FUNCTION, 1) == 1)
227
+ #if !PICO_PANIC_FUNCTION_EMPTY
228
+ extern void __attribute__((noreturn )) __printflike (1 , 0 ) PICO_PANIC_FUNCTION (__unused const char * fmt , ...);
229
+ #endif
230
+ // Use a forwarding method here as it is a little simpler than renaming the symbol as it is used from assembler
231
+ void __attribute__((naked , noreturn )) __printflike (1 , 0 ) panic (__unused const char * fmt , ...) {
232
+ // if you get an undefined reference here, you didn't define your PICO_PANIC_FUNCTION!
233
+ asm (
234
+ "push {lr}\n"
235
+ #if !PICO_PANIC_FUNCTION_EMPTY
236
+ "bl " __XSTRING (PICO_PANIC_FUNCTION ) "\n "
237
+ #endif
238
+ "bkpt #0 \n "
239
+ "1: b 1b\n" // loop for ever as we are no return
240
+ :
241
+ :
242
+ :
243
+ );
244
+ }
245
+ #else
223
246
// todo consider making this try harder to output if we panic early
224
247
// right now, print mutex may be uninitialised (in which case it deadlocks - although after printing "PANIC")
225
248
// more importantly there may be no stdout/UART initialized yet
226
249
// todo we may want to think about where we print panic messages to; writing to USB appears to work
227
250
// though it doesn't seem like we can expect it to... fine for now
228
- //
229
251
void __attribute__((noreturn )) __printflike (1 , 0 ) panic (const char * fmt , ...) {
230
252
puts ("\n*** PANIC ***\n" );
231
253
if (fmt ) {
@@ -246,6 +268,7 @@ void __attribute__((noreturn)) __printflike(1, 0) panic(const char *fmt, ...) {
246
268
247
269
_exit (1 );
248
270
}
271
+ #endif
249
272
250
273
void hard_assertion_failure (void ) {
251
274
panic ("Hard assert" );
0 commit comments