enum { //用于指定数据的位数
PRINT_FIRMWARE_INFO,
PRINT_ASSERT_ON_THREAD,
PRINT_ASSERT_ON_HANDLER,
PRINT_THREAD_STACK_INFO,
PRINT_MAIN_STACK_INFO,
PRINT_THREAD_STACK_OVERFLOW,
PRINT_MAIN_STACK_OVERFLOW,
PRINT_CALL_STACK_INFO,
PRINT_CALL_STACK_ERR,
PRINT_FAULT_ON_THREAD,
PRINT_FAULT_ON_HANDLER,
PRINT_REGS_TITLE,
PRINT_HFSR_VECTBL,
PRINT_MFSR_IACCVIOL,
PRINT_MFSR_DACCVIOL,
PRINT_MFSR_MUNSTKERR,
PRINT_MFSR_MSTKERR,
PRINT_MFSR_MLSPERR,
PRINT_BFSR_IBUSERR,
PRINT_BFSR_PRECISERR,
PRINT_BFSR_IMPREISERR,
PRINT_BFSR_UNSTKERR,
PRINT_BFSR_STKERR,
PRINT_BFSR_LSPERR,
PRINT_UFSR_UNDEFINSTR,
PRINT_UFSR_INVSTATE,
PRINT_UFSR_INVPC,
PRINT_UFSR_NOCP,
PRINT_UFSR_UNALIGNED,
PRINT_UFSR_DIVBYZERO0,
PRINT_DFSR_HALTED,
PRINT_DFSR_BKPT,
PRINT_DFSR_DWTTRAP,
PRINT_DFSR_VCATCH,
PRINT_DFSR_EXTERNAL,
PRINT_MMAR,
PRINT_BFAR,
};
----------
static const char *print_info[] = {
[PRINT_FIRMWARE_INFO] /* 指定改行的字符串是第一位防止出错 */ = "Firmware name: %s, hardware version: %s, software version: %s",
[PRINT_ASSERT_ON_THREAD] = "Assert on thread %s",
[PRINT_ASSERT_ON_HANDLER] = "Assert on interrupt or bare metal(no OS) environment",
[PRINT_THREAD_STACK_INFO] = "===== Thread stack information =====",
[PRINT_MAIN_STACK_INFO] = "====== Main stack information ======",
[PRINT_THREAD_STACK_OVERFLOW] = "Error: Thread stack(%08x) was overflow",
[PRINT_MAIN_STACK_OVERFLOW] = "Error: Main stack(%08x) was overflow",
[PRINT_CALL_STACK_INFO] = "Show more call stack info by run: addr2line -e %s%s -a -f %.*s",
[PRINT_CALL_STACK_ERR] = "Dump call stack has an error",
[PRINT_FAULT_ON_THREAD] = "Fault on thread %s",
[PRINT_FAULT_ON_HANDLER] = "Fault on interrupt or bare metal(no OS) environment",
[PRINT_REGS_TITLE] = "=================== Registers information ====================",
[PRINT_HFSR_VECTBL] = "Hard fault is caused by failed vector fetch",
[PRINT_MFSR_IACCVIOL] = "Memory management fault is caused by instruction access violation",
[PRINT_MFSR_DACCVIOL] = "Memory management fault is caused by data access violation",
[PRINT_MFSR_MUNSTKERR] = "Memory management fault is caused by unstacking error",
[PRINT_MFSR_MSTKERR] = "Memory management fault is caused by stacking error",
[PRINT_MFSR_MLSPERR] = "Memory management fault is caused by floating-point lazy state preservation",
[PRINT_BFSR_IBUSERR] = "Bus fault is caused by instruction access violation",
[PRINT_BFSR_PRECISERR] = "Bus fault is caused by precise data access violation",
[PRINT_BFSR_IMPREISERR] = "Bus fault is caused by imprecise data access violation",
[PRINT_BFSR_UNSTKERR] = "Bus fault is caused by unstacking error",
[PRINT_BFSR_STKERR] = "Bus fault is caused by stacking error",
[PRINT_BFSR_LSPERR] = "Bus fault is caused by floating-point lazy state preservation",
[PRINT_UFSR_UNDEFINSTR] = "Usage fault is caused by attempts toexecute an undefined instruction",
[PRINT_UFSR_INVSTATE] = "Usage fault is caused by attempts to switch to an invalid state (e.g., ARM)",
[PRINT_UFSR_INVPC] = "Usage fault is caused by attempts todo an exceptionwith a bad valuein the EXC_RETURN number",
[PRINT_UFSR_NOCP] = "Usage fault is caused by attempts toexecute a coprocessor instruction",
[PRINT_UFSR_UNALIGNED] = "Usage fault is caused by indicates that an unaligned access fault has taken place",
[PRINT_UFSR_DIVBYZERO0] = "Usage fault is caused by Indicates a divide by zero has taken place (can be setonlyif DIV_0_TRP isset)",
[PRINT_DFSR_HALTED] = "Debug fault is caused by halt requested in NVIC",
[PRINT_DFSR_BKPT] = "Debug fault is caused by BKPT instruction executed",
[PRINT_DFSR_DWTTRAP] = "Debug fault is caused by DWT match occurred",
[PRINT_DFSR_VCATCH] = "Debug fault is caused by Vector fetch occurred",
[PRINT_DFSR_EXTERNAL] = "Debug fault is caused by EDBGRQ signal asserted",
[PRINT_MMAR] = "The memory management fault occurred address is %08x",
[PRINT_BFAR] = "The bus fault occurred address is %08x",
};
//使用union 和struct 以及位域来实现数据的按位处理union {
unsignedint value; //该数据的所有的位数可以由下面的数据按位处理struct {
unsignedint MEMFAULTACT : 1; // Read as 1 if memory management fault is activeunsignedint BUSFAULTACT : 1; // Read as 1 if bus fault exception is activeunsignedint UnusedBits1 : 1;
unsignedint USGFAULTACT : 1; // Read as 1 if usage fault exception is activeunsignedint UnusedBits2 : 3;
unsignedint SVCALLACT : 1; // Read as 1 if SVC exception is activeunsignedint MONITORACT : 1; // Read as 1 if debug monitor exception is activeunsignedint UnusedBits3 : 1;
unsignedint PENDSVACT : 1; // Read as 1 if PendSV exception is activeunsignedint SYSTICKACT : 1; // Read as 1 if SYSTICK exception is activeunsignedint USGFAULTPENDED : 1; // Usage fault pended; usage fault started but was replaced by a higher-priority exceptionunsignedint MEMFAULTPENDED : 1; // Memory management fault pended; memory management fault started but was replaced by a higher-priority exceptionunsignedint BUSFAULTPENDED : 1; // Bus fault pended; bus fault handler was started but was replaced by a higher-priority exceptionunsignedint SVCALLPENDED : 1; // SVC pended; SVC was started but was replaced by a higher-priority exceptionunsignedint MEMFAULTENA : 1; // Memory management fault handler enableunsignedint BUSFAULTENA : 1; // Bus fault handler enableunsignedint USGFAULTENA : 1; // Usage fault handler enable
} bits;
} syshndctrl; // System Handler Control and State Register (0xE000ED24)