Skip to content

Commit

Permalink
Merge pull request #20616 from dylad/pr/cpu/cortexm/rework_break_on_p…
Browse files Browse the repository at this point in the history
…anic

cpu/cortexm: rework bkpt instruction call on panic
  • Loading branch information
maribu authored Apr 24, 2024
2 parents 772bc7a + e784794 commit 05034b5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cpu/cortexm_common/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
static void print_ipsr(void)
{
uint32_t ipsr = __get_IPSR() & IPSR_ISR_Msk;
if(ipsr) {

if (ipsr) {
/* if you get here, you might have forgotten to implement the isr
* for the printed interrupt number */
LOG_ERROR("Inside isr %d\n", ((int)ipsr) - 16);
Expand All @@ -39,7 +40,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 debugger) */
#ifdef CoreDebug_DHCSR_C_DEBUGEN_Msk
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
/* if Debug session is running, tell the debugger to break 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 05034b5

Please sign in to comment.