fixed hardfault handler to better work on cm0

sipo
Ondřej Hruška 7 years ago
parent 1e41d4c3cb
commit 71f5918e54
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 49
      cortex_handlers.c
  2. 2
      framework/settings.c
  3. 11
      gex.mk
  4. 6
      utils/payload_parser.h

@ -35,7 +35,8 @@ void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
while (1);
}
#if VERBOSE_HARDFAULT && (__CORTEX_M >= 3)
// && (__CORTEX_M >= 3)
#if VERBOSE_HARDFAULT
void prvGetRegistersFromStack( uint32_t *origStack, uint32_t lr_value)
{
/* These are volatile to try and prevent the compiler/linker optimising them
@ -51,7 +52,9 @@ of this function. */
volatile uint32_t stacked_pc; /* Program counter. */
volatile uint32_t stacked_psr;/* Program status register. */
#if (__CORTEX_M >= 3)
uint32_t cfsr, hfsr, dfsr;
uint32_t bus_fault_address;
uint32_t memmanage_fault_address;
@ -60,6 +63,7 @@ of this function. */
cfsr = SCB->CFSR;
hfsr = SCB->HFSR;
dfsr = SCB->DFSR;
#endif
stacked_r0 = origStack[0];
stacked_r1 = origStack[1];
@ -100,6 +104,7 @@ of this function. */
(exc>=16)?"IRQ":"Unknown"
);
#if (__CORTEX_M >= 3)
PRINTF("\r\n- FSR/FAR:\r\n");
PRINTF(" CFSR = \033[36m0x%08"PRIX32"\033[m\r\n", cfsr);
PRINTF(" UsageFault: \033[31;1m%s%s%s%s%s%s%s\033[m\r\n"
@ -151,8 +156,9 @@ of this function. */
if (cfsr & 0x8000) PRINTF(" BFAR = \033[33m0x%08"PRIX32"\033[m\r\n", bus_fault_address);
PRINTF("\r\n- Misc\r\n");
PRINTF(" LR/EXC_RETURN= %s0x%08"PRIX32"\033[m\n", REDPTR(lr_value), lr_value);
#endif
StatusLed_On(STATUS_FAULT);
Indicator_Effect(STATUS_FAULT);
while (1);
}
#endif
@ -162,19 +168,32 @@ of this function. */
*/
void __attribute__((naked)) HardFault_Handler(void)
{
#if VERBOSE_HARDFAULT && (__CORTEX_M >= 3)
__asm volatile
(
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, [r0, #24] \n"
" mov r2, lr \n"
" ldr r3, handler2_address_const \n"
" bx r3 \n"
" handler2_address_const: .word prvGetRegistersFromStack \n"
);
#if VERBOSE_HARDFAULT
// __asm volatile
// (
// " tst lr, #4 \n"
// " ite eq \n"
// " mrseq r0, msp \n"
// " mrsne r0, psp \n"
// " ldr r1, [r0, #24] \n"
// " mov r2, lr \n"
// " ldr r3, handler2_address_const \n"
// " bx r3 \n"
// " handler2_address_const: .word prvGetRegistersFromStack \n"
// );
//
__asm volatile( ".syntax unified\n"
"MOVS R0, #4 \n"
"MOV R1, LR \n"
"TST R0, R1 \n"
"BEQ _MSP \n"
"MRS R0, PSP \n"
"B prvGetRegistersFromStack \n"
"_MSP: \n"
"MRS R0, MSP \n"
"B prvGetRegistersFromStack \n"
".syntax divided\n") ;
#endif
PRINTF(tFAULT" HARD FAULT\r\n\r\n");

@ -270,7 +270,7 @@ void settings_load_ini_begin(void)
void settings_load_ini_key(const char *restrict section, const char *restrict key, const char *restrict value)
{
//dbg("[%s] %s = %s", section, key, value);
dbg("[%s] %s = %s", section, key, value);
static char namebuf[INI_KEY_MAX];
// SYSTEM and UNITS files must be separate.

@ -49,14 +49,13 @@ GEX_CFLAGS = \
-D__weak="__attribute__((weak))" -D__packed="__attribute__((__packed__))" \
-std=gnu99 -Wfatal-errors \
-Wall -Wextra -Wshadow \
-Wwrite-strings -Wold-style-definition -Winline -Wno-missing-noreturn -Wstrict-prototypes -Wreturn-type \
-Wwrite-strings -Wold-style-definition -Winline -Wstrict-prototypes -Wreturn-type \
-Wredundant-decls -Wfloat-equal -Wsign-compare \
-fno-common -ffunction-sections -fdata-sections -Wno-unused-function \
-MD -Wno-format-zero-length -Wno-redundant-decls -Wno-unused-parameter \
-Wno-discarded-qualifiers -Wno-unused-variable -Wno-inline \
-Wno-float-equal -Wno-implicit-fallthrough -Wno-strict-aliasing \
-fmerge-constants -fmerge-all-constants \
-fno-exceptions -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -finline-small-functions -findirect-inlining \
-MD -Wno-redundant-decls -Wno-unused-parameter \
-Wno-unused-variable -Wno-inline \
-fmerge-constants -fmerge-all-constants -Wno-implicit-fallthrough \
-fno-exceptions -finline-small-functions -findirect-inlining -Wno-strict-aliasing -Wno-float-equal -Wno-discarded-qualifiers
GEX_CDEFS_BASE = \
-D__weak="__attribute__((weak))" \

@ -41,9 +41,9 @@ typedef struct PayloadParser_ PayloadParser;
typedef bool (*pp_empty_handler)(PayloadParser *pp, uint32_t needed);
struct PayloadParser_ {
uint8_t *start; //!< Pointer to the beginning of the buffer
uint8_t *current; //!< Pointer to the next byte to be read
uint8_t *end; //!< Pointer to the end of the buffer (start + length)
const uint8_t *start; //!< Pointer to the beginning of the buffer
const uint8_t *current; //!< Pointer to the next byte to be read
const uint8_t *end; //!< Pointer to the end of the buffer (start + length)
pp_empty_handler empty_handler; //!< Callback for buffer underrun
bool bigendian; //!< Flag to use big-endian parsing
bool ok; //!< Indicates that all reads were successful

Loading…
Cancel
Save