Эх сурвалжийг харах

make hardfault handler gdb-friendly

Sergey Alirzaev 5 жил өмнө
parent
commit
9377fe0294

+ 1 - 1
Makefile.inc.stm32

@@ -5,7 +5,7 @@ PWD = $(shell pwd)
 
 COMMONFLAGS = -mcpu=cortex-m4 -mthumb -ggdb3
 CFLAGS += $(COMMONFLAGS) -Os $(INCLUDES) -I.
-CFLAGS += -std=c99 -Wall -Wextra -static -fdata-sections -ffunction-sections -fno-hosted -fno-builtin
+CFLAGS += -std=gnu99 -Wall -Wextra -static -fdata-sections -ffunction-sections -fno-hosted -fno-builtin
 CFLAGS += -nostdlib -nodefaultlibs -fstack-usage
 CFLAGS += -mapcs-frame -msoft-float
 CFLAGS += -Werror-implicit-function-declaration

+ 1 - 0
modules/Makefile

@@ -96,6 +96,7 @@ CSRC += $(wildcard ../thirdparty/FreeRTOS/portable/MemMang/heap_4.c)
     INCLUDES += -I../thirdparty/lwip_patched/port/FreeRTOS
     INCLUDES += -I../thirdparty/lwip_patched/system
     INCLUDES += -I../thirdparty/lwip_patched/system/arch
+    CFLAGS += -DLWIP_TIMEVAL_PRIVATE=0
     INCLUDES += -IEthernet
  # INCLUDES += -I../stm32/stm32f4x7_ethernet 
  	INCLUDES += -ISTM32F4x7_ETH_Driver

+ 10 - 0
user/stm32f4xx_it.c

@@ -80,8 +80,18 @@ void NMI_Handler(void)
 {
 }
 
+void **HARDFAULT_PSP;
+register void *stack_pointer asm("sp");
+
 void HardFault_Output(uint32_t *sp)
 {
+    // Hijack the process stack pointer to make backtrace work
+    asm("mrs %0, psp" : "=r"(HARDFAULT_PSP) : :);
+    stack_pointer = HARDFAULT_PSP;
+
+    // call our debugger
+    asm("bkpt #0");
+
     uint32_t r0  = sp[0];
     uint32_t r1  = sp[1];
     uint32_t r2  = sp[2];