Skip to content

Commit

Permalink
cpu/cortexm: rework bkpt instruction call on panic
Browse files Browse the repository at this point in the history
Only call this instruction if a debug session is active otherwise it will trigger a hardfault

Signed-off-by: Dylan Laduranty <[email protected]>
  • Loading branch information
dylad committed Apr 23, 2024
1 parent 3ae63a1 commit 679536e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cpu/cortexm_common/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ void panic_arch(void)
{
#ifdef DEVELHELP
print_ipsr();
/* The bkpt instruction will signal to the debugger to break here. */
__asm__("bkpt #0");
/* CM0+ has a C_DEBUGEN bit but it is NOT accessible by CPU (only by debug) */
#ifdef CoreDebug_DHCSR_C_DEBUGEN_Msk
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
/* if Debug session is running, tell the debugger to breaks here.
Skip it otherwise as this instruction will cause either a fault
escalation to hardfault or a CPU lockup */
__asm__("bkpt #0");
}
#endif /* CoreDebug_DHCSR_C_DEBUGEN_Msk */

#endif
}

0 comments on commit 679536e

Please sign in to comment.