[关闭]
@zwh8800 2017-08-23T10:12:28.000000Z 字数 3893 阅读 192868

cortex-m3 系统异常相关寄存器

blog 归档 stm32 单片机


enc28j60 驱动和 udp 协议栈移植到 stm32 成功


1. 手动挂起、清除系统异常和中断挂起示意

软件挂起

类型 NMI PendSV SysTick
寄存器位 NMIPENDSET PENDSVSET PENDSTSET

软件清除

类型 PendSV SysTick
寄存器位 PENDSVCLR PENDSVCLR

中断挂起状态示意

ISRPENDING

寄存器: SCB_ICSR(Interrupt Control and state register)

image_1bl04ftuo1f9ck9318ol1pqn195c9.png-148.6kB
image_1bl04gc7heidbq71ikbn99tanm.png-174.2kB

2. 设置系统异常优先级

寄存器: SCB_SHPRx(System handler priority)

image_1bl04hde214oj1i9i13iv194p1vam13.png-101.3kB
image_1bl04hodm70q11la19pkuuh1jhr1g.png-116.3kB
image_1bl04i123oasa21c94f1u1r01t.png-57.5kB

3. 使能 fault,和挂起状态、活动状态示意

使能

类型 Usage fault Bus fault mem fault
寄存器位 USGFAULTENA BUSFAULTENA MEMFAULTENA

挂起状态

类型 SVC Bus fault mem fault Usage fault
寄存器位 SVCALLPENDED BUSFAULTPENDED MEMFAULTPENDED USGFAULTPENDED

活动状态

类型 SysTick PendSV Debug Monitor SVC Usage fault Bus fault Mem fault
寄存器位 SYSTICKACT PENDSVACT MONITORACT SVCALLACT USGFAULTACT BUSFAULTACT MEMFAULTACT

寄存器: SCB_SHCSR(System handler control and state register)

image_1bl04u1pi1o0v9cc19ugj11c672a.png-177.9kB

一个 dump 出 scb(System control block 系统控制块) 的函数, 调试的时候有时很有用

  1. #define PRIORITY_Msk 0xF0
  2. #define PRIORITY_Pos 4
  3. void dump_scb()
  4. {
  5. uint32_t icsr = SCB->ICSR;
  6. uint32_t shcsr = SCB->SHCSR;
  7. printf("ICSR:\r\n");
  8. printf("\t there %s interrupt pending\r\n",
  9. (icsr & SCB_ICSR_ISRPENDING_Msk) ? "is" : "isn't");
  10. printf("\t pending exception number:%u\r\n",
  11. (icsr & SCB_ICSR_VECTPENDING_Msk) >> SCB_ICSR_VECTPENDING_Pos);
  12. printf("\t active exception number:%u\r\n",
  13. (icsr & SCB_ICSR_VECTACTIVE_Msk) >> SCB_ICSR_VECTACTIVE_Pos);
  14. printf("SHPRx:\r\n");
  15. printf("\t Mem Manage:%hhd\r\n", (SCB->SHP[0] & PRIORITY_Msk) >> PRIORITY_Pos);
  16. printf("\t Bus Fault:%hhd\r\n", (SCB->SHP[1] & PRIORITY_Msk) >> PRIORITY_Pos);
  17. printf("\t Usage Fault:%hhd\r\n", (SCB->SHP[2] & PRIORITY_Msk) >> PRIORITY_Pos);
  18. printf("\t SVC:%hhd\r\n", (SCB->SHP[7] & PRIORITY_Msk) >> PRIORITY_Pos);
  19. printf("\t Debug Monitor:%hhd\r\n", (SCB->SHP[8] & PRIORITY_Msk) >> PRIORITY_Pos);
  20. printf("\t PendSV:%hhd\r\n", (SCB->SHP[10] & PRIORITY_Msk) >> PRIORITY_Pos);
  21. printf("\t SysTick:%hhd\r\n", (SCB->SHP[11] & PRIORITY_Msk) >> PRIORITY_Pos);
  22. printf("SHCSR:\r\n");
  23. printf("\t Usage Fault enable:%u\r\n",
  24. (shcsr & SCB_SHCSR_USGFAULTENA_Msk) >> SCB_SHCSR_USGFAULTENA_Pos);
  25. printf("\t Bus Fault enable:%u\r\n",
  26. (shcsr & SCB_SHCSR_BUSFAULTENA_Msk) >> SCB_SHCSR_BUSFAULTENA_Pos);
  27. printf("\t Mem Fault enable:%u\r\n",
  28. (shcsr & SCB_SHCSR_MEMFAULTENA_Msk) >> SCB_SHCSR_MEMFAULTENA_Pos);
  29. printf("\r\n");
  30. printf("\t SVCall pended:%u\r\n",
  31. (shcsr & SCB_SHCSR_SVCALLPENDED_Msk) >> SCB_SHCSR_SVCALLPENDED_Pos);
  32. printf("\t Bus Fault pended:%u\r\n",
  33. (shcsr & SCB_SHCSR_BUSFAULTPENDED_Msk) >> SCB_SHCSR_BUSFAULTPENDED_Pos);
  34. printf("\t Mem Fault pended:%u\r\n",
  35. (shcsr & SCB_SHCSR_MEMFAULTPENDED_Msk) >> SCB_SHCSR_MEMFAULTPENDED_Pos);
  36. printf("\t Usage Fault pended:%u\r\n",
  37. (shcsr & SCB_SHCSR_USGFAULTPENDED_Msk) >> SCB_SHCSR_USGFAULTPENDED_Pos);
  38. printf("\r\n");
  39. printf("\t SysTick active:%u\r\n",
  40. (shcsr & SCB_SHCSR_SYSTICKACT_Msk) >> SCB_SHCSR_SYSTICKACT_Pos);
  41. printf("\t PendSV active:%u\r\n",
  42. (shcsr & SCB_SHCSR_PENDSVACT_Msk) >> SCB_SHCSR_PENDSVACT_Pos);
  43. printf("\t Monitor active:%u\r\n",
  44. (shcsr & SCB_SHCSR_MONITORACT_Msk) >> SCB_SHCSR_MONITORACT_Pos);
  45. printf("\t SVCall active:%u\r\n",
  46. (shcsr & SCB_SHCSR_SVCALLACT_Msk) >> SCB_SHCSR_SVCALLACT_Pos);
  47. printf("\t Usage Fault active:%u\r\n",
  48. (shcsr & SCB_SHCSR_USGFAULTACT_Msk) >> SCB_SHCSR_USGFAULTACT_Pos);
  49. printf("\t Bus Fault active:%u\r\n",
  50. (shcsr & SCB_SHCSR_BUSFAULTACT_Msk) >> SCB_SHCSR_BUSFAULTACT_Pos);
  51. printf("\t Mem Fault active:%u\r\n",
  52. (shcsr & SCB_SHCSR_MEMFAULTACT_Msk) >> SCB_SHCSR_MEMFAULTACT_Pos);
  53. }
  54. #define DIVBYZERO_Pos 9
  55. #define DIVBYZERO_Msk (1ul << DIVBYZERO_Pos)
  56. #define UNALIGNED_Pos 8
  57. #define UNALIGNED_Msk (1ul << UNALIGNED_Pos)
  58. #define NOCP_Pos 3
  59. #define NOCP_Msk (1ul << NOCP_Pos)
  60. #define INVPC_Pos 2
  61. #define INVPC_Msk (1ul << INVPC_Pos)
  62. #define INVSTATE_Pos 1
  63. #define INVSTATE_Msk (1ul << INVSTATE_Pos)
  64. #define UNDEFINSTR_Pos 0
  65. #define UNDEFINSTR_Msk (1ul << UNDEFINSTR_Pos)
  66. void dump_ufsr()
  67. {
  68. uint16_t ufsr = (SCB->CFSR & SCB_CFSR_USGFAULTSR_Msk) >> SCB_CFSR_USGFAULTSR_Pos;
  69. printf("UFSR:\r\n");
  70. printf("\t Divide by zero: %d\r\n",
  71. (ufsr & DIVBYZERO_Msk) >> DIVBYZERO_Pos);
  72. printf("\t Unaligned access: %d\r\n",
  73. (ufsr & UNALIGNED_Msk) >> UNALIGNED_Pos);
  74. printf("\t No coprocessor: %d\r\n",
  75. (ufsr & NOCP_Msk) >> NOCP_Pos);
  76. printf("\t Invaild PC load: %d\r\n",
  77. (ufsr & INVPC_Msk) >> INVPC_Pos);
  78. printf("\t Invaild state(attempt to entry ARM state): %d\r\n",
  79. (ufsr & INVSTATE_Msk) >> INVSTATE_Pos);
  80. printf("\t Undefined instruction: %d\r\n",
  81. (ufsr & UNDEFINSTR_Msk) >> UNDEFINSTR_Pos);
  82. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注