Merge pull request #14718 from bergzand/pr/cortexm_common/hard_fault_add_thread_info

cortexm_common: Add thread info to hard fault handler
This commit is contained in:
Francisco 2020-08-26 12:40:25 +02:00 committed by GitHub
commit f963089b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include "board.h"
#include "mpu.h"
#include "panic.h"
#include "sched.h"
#include "vectors_cortexm.h"
#ifdef MODULE_PUF_SRAM
#include "puf_sram.h"
@ -372,6 +373,20 @@ __attribute__((used)) void hard_fault_handler(uint32_t* sp, uint32_t corrupted,
printf("EXC_RET: 0x%08" PRIx32 "\n", exc_return);
if (!corrupted) {
/* Test if the EXC_RETURN returns to thread mode,
* to check if the hard fault happened in ISR context */
if (exc_return & 0x08) {
kernel_pid_t active_pid = thread_getpid();
printf("Active thread: %"PRIi16" \"%s\"\n",
active_pid, thread_getname(active_pid));
}
else {
/* Print the interrupt number, NMI being -14, hardfault is -13,
* IRQ0 is 0 and so on */
uint32_t psr = sp[7]; /* Program status register. */
printf("Hard fault occured in ISR number %d\n",
(int)(psr & 0xff) - 16);
}
puts("Attempting to reconstruct state for debugging...");
printf("In GDB:\n set $pc=0x%" PRIx32 "\n frame 0\n bt\n", pc);
int stack_left = _stack_size_left(HARDFAULT_HANDLER_REQUIRED_STACK_SPACE);

View File

@ -9,6 +9,7 @@ BOARD_INSUFFICIENT_MEMORY := \
nucleo-f031k6 \
nucleo-l031k6 \
nucleo-f042k6 \
nucleo-l031k6 \
stm32f030f4-demo \
telosb \
z1 \