From 5536f1afc57d63d8146c3f5e83ba6643561bc62d Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Fri, 21 Aug 2020 10:50:20 +0200 Subject: [PATCH 1/2] tests/pkg_fatfs_vfs: blacklist nucleo-l031k6 Adding the extra prints to the hard fault handler bumped this test over the available ROM for this board --- tests/pkg_fatfs_vfs/Makefile.ci | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pkg_fatfs_vfs/Makefile.ci b/tests/pkg_fatfs_vfs/Makefile.ci index 41426e51ea..6d2b8ddac4 100644 --- a/tests/pkg_fatfs_vfs/Makefile.ci +++ b/tests/pkg_fatfs_vfs/Makefile.ci @@ -8,6 +8,7 @@ BOARD_INSUFFICIENT_MEMORY := \ msb-430h \ nucleo-f031k6 \ nucleo-f042k6 \ + nucleo-l031k6 \ stm32f030f4-demo \ telosb \ z1 \ From 0d484f4d3a4f588c37bbb92934e3dd9510330c5a Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Thu, 6 Aug 2020 14:02:39 +0200 Subject: [PATCH 2/2] cortexm_common: Add thread info to hard fault handler While the hard fault handler prints the offending program counter, it does not print information about the context triggering the hard fault. This commit adds a line printing the thread ID and name that triggered the hard fault. If the hard fault is triggered during an ISR, it only prints that the hard fault happened during ISR context, not which ISR triggered it. --- cpu/cortexm_common/vectors_cortexm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index 5f39c5c552..a078e3f35c 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -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);