STM32中使用静态“字符串的方式”
生活随笔
收集整理的這篇文章主要介紹了
STM32中使用静态“字符串的方式”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 activeunsigned int BUSFAULTACT : 1; // Read as 1 if bus fault exception is activeunsigned int UnusedBits1 : 1;unsigned int USGFAULTACT : 1; // Read as 1 if usage fault exception is activeunsigned int UnusedBits2 : 3;unsigned int SVCALLACT : 1; // Read as 1 if SVC exception is activeunsigned int MONITORACT : 1; // Read as 1 if debug monitor exception is activeunsigned int UnusedBits3 : 1;unsigned int PENDSVACT : 1; // Read as 1 if PendSV exception is activeunsigned int SYSTICKACT : 1; // Read as 1 if SYSTICK exception is activeunsigned int USGFAULTPENDED : 1; // Usage fault pended; usage fault started but was replaced by a higher-priority exceptionunsigned int MEMFAULTPENDED : 1; // Memory management fault pended; memory management fault started but was replaced by a higher-priority exceptionunsigned int BUSFAULTPENDED : 1; // Bus fault pended; bus fault handler was started but was replaced by a higher-priority exceptionunsigned int SVCALLPENDED : 1; // SVC pended; SVC was started but was replaced by a higher-priority exceptionunsigned int MEMFAULTENA : 1; // Memory management fault handler enableunsigned int BUSFAULTENA : 1; // Bus fault handler enableunsigned int USGFAULTENA : 1; // Usage fault handler enable} bits;} syshndctrl; // System Handler Control and State Register (0xE000ED24)
總結
以上是生活随笔為你收集整理的STM32中使用静态“字符串的方式”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 作者:庄会富(1985-),男,中国科学
- 下一篇: 作者:李喜莲(1992-),女,北京大学