STM32中使用静态“字符串的方式”

来源:互联网 发布:mac 内存占用 编辑:程序博客网 时间:2024/06/05 02:13
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 to execute 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 to do an exception with a bad value in the EXC_RETURN number",        [PRINT_UFSR_NOCP]             = "Usage fault is caused by attempts to execute 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 set only if DIV_0_TRP is set)",        [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 {    unsigned int value;  //该数据的所有的位数可以由下面的数据按位处理    struct {      unsigned int MEMFAULTACT    : 1;   // Read as 1 if memory management fault is active      unsigned int BUSFAULTACT    : 1;   // Read as 1 if bus fault exception is active      unsigned int UnusedBits1    : 1;      unsigned int USGFAULTACT    : 1;   // Read as 1 if usage fault exception is active      unsigned int UnusedBits2    : 3;      unsigned int SVCALLACT      : 1;   // Read as 1 if SVC exception is active      unsigned int MONITORACT     : 1;   // Read as 1 if debug monitor exception is active      unsigned int UnusedBits3    : 1;      unsigned int PENDSVACT      : 1;   // Read as 1 if PendSV exception is active      unsigned int SYSTICKACT     : 1;   // Read as 1 if SYSTICK exception is active      unsigned int USGFAULTPENDED : 1;   // Usage fault pended; usage fault started but was replaced by a higher-priority exception      unsigned int MEMFAULTPENDED : 1;   // Memory management fault pended; memory management fault started but was replaced by a higher-priority exception      unsigned int BUSFAULTPENDED : 1;   // Bus fault pended; bus fault handler was started but was replaced by a higher-priority exception      unsigned int SVCALLPENDED   : 1;   // SVC pended; SVC was started but was replaced by a higher-priority exception      unsigned int MEMFAULTENA    : 1;   // Memory management fault handler enable      unsigned int BUSFAULTENA    : 1;   // Bus fault handler enable      unsigned int USGFAULTENA    : 1;   // Usage fault handler enable    } bits;  } syshndctrl;                          // System Handler Control and State Register (0xE000ED24)
原创粉丝点击