Bugfixes for fault handlers

This commit is contained in:
jvblanck
2021-07-18 17:14:03 +02:00
parent 2ca1ec4b8f
commit fb68e8c4d6
2 changed files with 181 additions and 89 deletions

View File

@ -5,28 +5,35 @@
struct FaultStatusRegisters {
uint32_t HFSR;
uint32_t CFSR;
uint32_t MMFAR;
uint32_t BFAR;
uint32_t DFSR;
uint32_t AFSR;
uint32_t SHCSR;
};
enum class FaultType {
HardFault, MemManage, BusFault, UsageFault
};
struct FlashDump {
FaultType type;
uint32_t stacked_registers[8];
FaultStatusRegisters fsr;
};
struct FlashDumpInfo {
uint8_t _zero; // Used to check that the storage area has been initialized
uint32_t n_dumps;
};
struct FlashDump {
uint32_t stacked_registers[8];
FaultStatusRegisters fsr;
};
constexpr uint32_t FLASH_DUMP_ADDR_BASE = 0;
constexpr uint32_t FLASH_DUMP_ADDR_INFO = FLASH_DUMP_ADDR_BASE + 0;
constexpr uint32_t FLASH_DUMP_ADDR_DUMPS =
FLASH_DUMP_ADDR_INFO + sizeof(FlashDump);
void flash_dump_write_fault(const uint32_t *stack,
void flash_dump_write_fault(FaultType fault_type, const uint32_t *stack,
const FaultStatusRegisters *fsr);
/**
* Read the FlashDumpInfo (and create it if it hasn't been initialized yet).
@ -34,13 +41,24 @@ void flash_dump_write_fault(const uint32_t *stack,
const FlashDumpInfo *flash_dump_get_info();
const FlashDump *flash_dump_get_fault(uint32_t n);
bool check_serial_available();
void uart_wait_for_txrdy();
size_t uart_write(uint8_t c);
size_t uart_print(const char* str);
size_t uart_print_hex(uint32_t x);
void print_dumped_faults();
void print_stacked_registers(const uint32_t *stack);
void print_fault_registers(const FaultStatusRegisters *fsr);
void print_dumped_faults(bool in_irq=false);
void print_stacked_registers(const uint32_t *stack, bool in_irq=false);
void print_fault_registers(const FaultStatusRegisters *fsr, bool in_irq=false);
FaultStatusRegisters get_current_fsr();
void fault_handler(uint32_t *stack_addr, const char *fault_type,
const char* get_fault_type_name(FaultType type);
void fault_handler(uint32_t *stack_addr, FaultType fault_type,
const int *leds, unsigned n_leds);
void inline busy_wait(size_t iterations) {
for (size_t i = 0; i < iterations; i++) {
// Does nothing, but ensures the compiler doesn't optimize the loop away.
__ASM ("" ::: "memory");
}
}