cortex-m4-control-registers.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. #pragma once
  2. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  3. #include <stdint.h>
  4. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  5. // Peripheral NVIC
  6. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  7. //-------------------- Interrupt Set-Enable Registers (idx = 0 ... 7)
  8. #define NVIC_ISER(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x00 + 4 * (idx))))
  9. //-------------------- Interrupt Clear-Enable Registers (idx = 0 ... 7)
  10. #define NVIC_ICER(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x80 + 4 * (idx))))
  11. //-------------------- Interrupt Set-Pending Registers (idx = 0 ... 7)
  12. #define NVIC_ISPR(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x100 + 4 * (idx))))
  13. //-------------------- Interrupt Clear-Pending Registers (idx = 0 ... 7)
  14. #define NVIC_ICPR(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x180 + 4 * (idx))))
  15. //-------------------- Interrupt Active Bit Register (idx = 0 ... 7)
  16. #define NVIC_IABR(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x200 + 4 * (idx))))
  17. //-------------------- Interrupt Priority Register (idx = 0 ... 59)
  18. #define NVIC_IPR(idx) (* ((const volatile uint32_t *) (0xE000E100 + 0x300 + 4 * (idx))))
  19. //-------------------- Software Trigger Interrupt Register
  20. #define NVIC_STIR (* ((volatile uint32_t *) (0xE000E100 + 0xE00)))
  21. // Field (width: 9 bits): Interrupt ID of the interrupt to trigger, in the range 0-239.
  22. inline uint32_t NVIC_STIR_INTID (const uint32_t inValue) { return (inValue & 511) << 0 ; }
  23. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  24. // Peripheral SCB
  25. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  26. //-------------------- Auxiliary Control Register
  27. #define SCB_ACTLR (* ((volatile uint32_t *) (0xE000E000 + 0x8)))
  28. // Boolean field: Disables Interruption Folding
  29. static const uint32_t SCB_ACTLR_DISFOLD = 1U << 2 ;
  30. // Boolean field: Disabled FPU exception outputs
  31. static const uint32_t SCB_ACTLR_PFEXCODIS = 1U << 10 ;
  32. // Boolean field: Disables dynamic read allocate mode for Write-Back Write-Allocate memory regions:
  33. static const uint32_t SCB_ACTLR_DISRAMODE = 1U << 11 ;
  34. // Boolean field: Disables ITM and DWT ATB flush:
  35. static const uint32_t SCB_ACTLR_DISITMATBFLUSH = 1U << 12 ;
  36. // Boolean field: Disables the Branch Target Address Cache (BTAC).
  37. static const uint32_t SCB_ACTLR_DISBTACREAD = 1U << 13 ;
  38. // Boolean field: Disables the Branch Target Address Cache allocation.
  39. static const uint32_t SCB_ACTLR_DISBTACALLOC = 1U << 14 ;
  40. // Boolean field: Disables critical AXI Read-Under-Read.
  41. static const uint32_t SCB_ACTLR_DISCRITAXIRUR = 1U << 15 ;
  42. // Boolean field: Disables dual-issued direct branches.
  43. static const uint32_t SCB_ACTLR_DISDI_DB = 1U << 16 ;
  44. // Boolean field: Disables dual-issued indirect branches.
  45. static const uint32_t SCB_ACTLR_DISDI_IB = 1U << 17 ;
  46. // Boolean field: Disables dual-issued loads to PC.
  47. static const uint32_t SCB_ACTLR_DISDI_LPC = 1U << 18 ;
  48. // Boolean field: Disables integer MAC and MUL dual-issued instructions.
  49. static const uint32_t SCB_ACTLR_DISDI_MAC_MUL = 1U << 19 ;
  50. // Boolean field: Disables VFP dual-issued instruction.
  51. static const uint32_t SCB_ACTLR_DISDI_VFP = 1U << 20 ;
  52. // Boolean field: Disables direct branches instructions in channel 1.
  53. static const uint32_t SCB_ACTLR_DISISSCH1_DB = 1U << 21 ;
  54. // Boolean field: Disables indirect branches instructions in channel 1.
  55. static const uint32_t SCB_ACTLR_DISISSCH1_IB = 1U << 22 ;
  56. // Boolean field: Disables loads to PC instructions in channel 1.
  57. static const uint32_t SCB_ACTLR_DISISSCH1_LPC = 1U << 23 ;
  58. // Boolean field: Disables integer MAC and MUL instructions in channel 1.
  59. static const uint32_t SCB_ACTLR_DISISSCH1_MAC_MUL = 1U << 24 ;
  60. // Boolean field: Disables VFP instructions in channel 1
  61. static const uint32_t SCB_ACTLR_DISISSCH1_VFP = 1U << 25 ;
  62. // Boolean field: Disables dynamic allocation of ADD and SUB instructions:
  63. static const uint32_t SCB_ACTLR_DISDYNADD = 1U << 26 ;
  64. //-------------------- CPUID Base Register
  65. #define SCB_CPUID (* ((const volatile uint32_t *) (0xE000E000 + 0xD00)))
  66. // Field (width: 4 bits): Revision number, the p value in the rnpn product revision identifier.
  67. inline uint32_t SCB_CPUID_Revision (const uint32_t inValue) { return (inValue & 15) << 0 ; }
  68. // Field (width: 12 bits): Part number of the processor.
  69. inline uint32_t SCB_CPUID_PartNo (const uint32_t inValue) { return (inValue & 4095) << 4 ; }
  70. // Field (width: 4 bits): Reads as 0xF.
  71. inline uint32_t SCB_CPUID_Constant (const uint32_t inValue) { return (inValue & 15) << 16 ; }
  72. // Field (width: 4 bits): Variant number, the r value in the rnpn product revision identifier.
  73. inline uint32_t SCB_CPUID_Variant (const uint32_t inValue) { return (inValue & 15) << 20 ; }
  74. // Field (width: 8 bits): Implementer code.
  75. inline uint32_t SCB_CPUID_Implementer (const uint32_t inValue) { return (inValue & 255) << 24 ; }
  76. //-------------------- Interrupt Control and State Register
  77. #define SCB_ICSR (* ((volatile uint32_t *) (0xE000E000 + 0xD04)))
  78. // Field (width: 9 bits): Contains the active exception number.
  79. inline uint32_t SCB_ICSR_VECTACTIVE (const uint32_t inValue) { return (inValue & 511) << 0 ; }
  80. // Boolean field: Indicates whether there are preempted active exceptions.
  81. static const uint32_t SCB_ICSR_RETTOBASE = 1U << 11 ;
  82. // Field (width: 9 bits): Indicates the exception number of the highest priority pending enabled exception.
  83. inline uint32_t SCB_ICSR_VECTPENDING (const uint32_t inValue) { return (inValue & 511) << 12 ; }
  84. // Boolean field: Interrupt pending flag, excluding NMI and Faults
  85. static const uint32_t SCB_ICSR_ISRPENDING = 1U << 22 ;
  86. // Boolean field: SysTick exception clear-pending bit.
  87. static const uint32_t SCB_ICSR_PENDSTCLR = 1U << 25 ;
  88. // Boolean field: SysTick exception set-pending bit.
  89. static const uint32_t SCB_ICSR_PENDSTSET = 1U << 26 ;
  90. // Boolean field: PendSV clear-pending bit.
  91. static const uint32_t SCB_ICSR_PENDSVCLR = 1U << 27 ;
  92. // Boolean field: PendSV set-pending bit.
  93. static const uint32_t SCB_ICSR_PENDSVSET = 1U << 28 ;
  94. // Boolean field: NMI set-pending bit.
  95. static const uint32_t SCB_ICSR_NMIPENDSET = 1U << 31 ;
  96. //-------------------- Vector Table Offset Register
  97. #define SCB_VTOR (* ((volatile uint32_t *) (0xE000E000 + 0xD08)))
  98. //-------------------- Application Interrupt and Reset Control Register
  99. #define SCB_AIRCR (* ((volatile uint32_t *) (0xE000E000 + 0xD0C)))
  100. // Boolean field: System reset request bit setting is implementation defined.
  101. static const uint32_t SCB_AIRCR_SYSRESETREQ = 1U << 2 ;
  102. // Field (width: 3 bits): Interrupt priority grouping field. This field determines the split of group priority from subpriority.
  103. inline uint32_t SCB_AIRCR_PRIGROUP (const uint32_t inValue) { return (inValue & 7) << 8 ; }
  104. // Boolean field: Data endianness bit setting is implementation defined.
  105. static const uint32_t SCB_AIRCR_ENDIANNESS = 1U << 15 ;
  106. // Field (width: 16 bits): Register key. On write, write 0x5FA to VECTKEY, otherwise the write is ignored. Reads as 0xFA05
  107. inline uint32_t SCB_AIRCR_VECTKEY (const uint32_t inValue) { return (inValue & 65535) << 16 ; }
  108. //-------------------- System Control Register
  109. #define SCB_SCR (* ((volatile uint32_t *) (0xE000E000 + 0xD10)))
  110. // Boolean field: Indicates sleep-on-exit when returning from Handler mode to Thread mode
  111. static const uint32_t SCB_SCR_SLEEPONEXIT = 1U << 1 ;
  112. // Boolean field: Controls whether the processor uses sleep or deep sleep as its low-power mode
  113. static const uint32_t SCB_SCR_SLEEPDEEP = 1U << 2 ;
  114. // Boolean field: Send event on pending bit
  115. static const uint32_t SCB_SCR_SEVONPEND = 1U << 4 ;
  116. //-------------------- Configuration and Control Register
  117. #define SCB_CCR (* ((volatile uint32_t *) (0xE000E000 + 0xD14)))
  118. // Boolean field: Indicates how the processor enters Thread mode
  119. static const uint32_t SCB_CCR_NONBASETHREADENA = 1U << 0 ;
  120. // Boolean field: Enables unprivileged software access to the STIR
  121. static const uint32_t SCB_CCR_USERSETMPEND = 1U << 1 ;
  122. // Boolean field: Enables unalign access traps.
  123. static const uint32_t SCB_CCR_UNALIGNED_TRP = 1U << 3 ;
  124. // Boolean field: Enables faulting or halting when the processor executes an SDIF or UDIV instruction with a divisor of 0.
  125. static const uint32_t SCB_CCR_DIV0_TRP = 1U << 4 ;
  126. // Boolean field: Enables handlers with priority -1 or -2 to ignore data BusFaults caused by load and store instructions. This applies to the hard fault, NMI, and FAULTMASK escalated handlers.
  127. static const uint32_t SCB_CCR_BFHFNMIGN = 1U << 8 ;
  128. // Boolean field: Always reads-as-one. It indicates stack alignment on exception entry is 8-byte aligned.
  129. static const uint32_t SCB_CCR_STKALIGN = 1U << 9 ;
  130. // Boolean field: Enables L1 data cache.
  131. static const uint32_t SCB_CCR_DC = 1U << 16 ;
  132. // Boolean field: Enables L1 instruction cache.
  133. static const uint32_t SCB_CCR_IC = 1U << 17 ;
  134. //-------------------- System Handler Priority Register 1
  135. #define SCB_SHPR1 (* ((volatile uint32_t *) (0xE000E000 + 0xD18)))
  136. // Field (width: 8 bits): Priority of the system handler, MemManage
  137. inline uint32_t SCB_SHPR1_PRI_4 (const uint32_t inValue) { return (inValue & 255) << 0 ; }
  138. // Field (width: 8 bits): Priority of the system handler, BusFault
  139. inline uint32_t SCB_SHPR1_PRI_5 (const uint32_t inValue) { return (inValue & 255) << 8 ; }
  140. // Field (width: 8 bits): Priority of the system handler, UsageFault
  141. inline uint32_t SCB_SHPR1_PRI_6 (const uint32_t inValue) { return (inValue & 255) << 16 ; }
  142. //-------------------- System Handler Priority Register 2
  143. #define SCB_SHPR2 (* ((volatile uint32_t *) (0xE000E000 + 0xD1C)))
  144. // Field (width: 8 bits): Priority of the system handler, SVCall
  145. inline uint32_t SCB_SHPR2_PRI_11 (const uint32_t inValue) { return (inValue & 255) << 24 ; }
  146. //-------------------- System Handler Priority Register 3
  147. #define SCB_SHPR3 (* ((volatile uint32_t *) (0xE000E000 + 0xD20)))
  148. // Field (width: 8 bits): Priority of the system handler, PendSV
  149. inline uint32_t SCB_SHPR3_PRI_14 (const uint32_t inValue) { return (inValue & 255) << 16 ; }
  150. // Field (width: 8 bits): Priority of the system handler, SysTick
  151. inline uint32_t SCB_SHPR3_PRI_15 (const uint32_t inValue) { return (inValue & 255) << 24 ; }
  152. //-------------------- System Handler Control and State Register
  153. #define SCB_SHCSR (* ((volatile uint32_t *) (0xE000E000 + 0xD24)))
  154. // Boolean field: MemManage exception active bit, reads as 1 if exception is active.
  155. static const uint32_t SCB_SHCSR_MEMFAULTACT = 1U << 0 ;
  156. // Boolean field: BusFault exception active bit, reads as 1 if exception is active.
  157. static const uint32_t SCB_SHCSR_BUSFAULTACT = 1U << 1 ;
  158. // Boolean field: UsageFault exception active bit, reads as 1 if exception is active.
  159. static const uint32_t SCB_SHCSR_USGFAULTACT = 1U << 3 ;
  160. // Boolean field: SVCall active bit, reads as 1 if exception is active.
  161. static const uint32_t SCB_SHCSR_SVCALLACT = 1U << 7 ;
  162. // Boolean field: Debug Monitor active bit, reads as 1 if exception is active.
  163. static const uint32_t SCB_SHCSR_MONITORACT = 1U << 8 ;
  164. // Boolean field: PendSV exception active bit, reads as 1 if exception is active.
  165. static const uint32_t SCB_SHCSR_PENDSVACT = 1U << 10 ;
  166. // Boolean field: Systick exception active bit, reads as 1 if exception is active.
  167. static const uint32_t SCB_SHCSR_SYSTICKACT = 1U << 11 ;
  168. // Boolean field: UsageFault exception pending bit, reads as 1 if exception is pending
  169. static const uint32_t SCB_SHCSR_USGFAULTPENDED = 1U << 12 ;
  170. // Boolean field: MemManage exception pending bit, reads as 1 if exception is pending
  171. static const uint32_t SCB_SHCSR_MEMFAULTPENDED = 1U << 13 ;
  172. // Boolean field: BusFault exception pending bit, reads as 1 if exception is pending
  173. static const uint32_t SCB_SHCSR_BUSFAULTPENDED = 1U << 14 ;
  174. // Boolean field: SVCall pending bit, reads as 1 if exception is pending
  175. static const uint32_t SCB_SHCSR_SVCALLPENDED = 1U << 15 ;
  176. // Boolean field: MemManage enable bit, set to 1 to enable
  177. static const uint32_t SCB_SHCSR_MEMFAULTENA = 1U << 16 ;
  178. // Boolean field: BusFault enable bit, set to 1 to enable
  179. static const uint32_t SCB_SHCSR_BUSFAULTENA = 1U << 17 ;
  180. // Boolean field: UsageFault enable bit, set to 1 to enable
  181. static const uint32_t SCB_SHCSR_USGFAULTENA = 1U << 18 ;
  182. //-------------------- MemManage Fault Status Register
  183. #define SCB_CFSR (* ((volatile uint8_t *) (0xE000E000 + 0xD28)))
  184. // Boolean field: Instruction access violation flag
  185. static const uint8_t SCB_CFSR_IACCVIOL = 1U << 0 ;
  186. // Boolean field: Data access violation flag
  187. static const uint8_t SCB_CFSR_DACCVIOL = 1U << 1 ;
  188. // Boolean field: MemManage fault on unstacking for a return from exception
  189. static const uint8_t SCB_CFSR_MUNSTKERR = 1U << 3 ;
  190. // Boolean field: MemManage fault on stacking for exception entry
  191. static const uint8_t SCB_CFSR_MSTKERR = 1U << 4 ;
  192. // Boolean field: MemManage fault during floating-point lazy state preservation.
  193. static const uint8_t SCB_CFSR_MLSPERR = 1U << 5 ;
  194. // Boolean field: MemManage fault address register valid flag.
  195. static const uint8_t SCB_CFSR_MMARVALID = 1U << 7 ;
  196. //-------------------- BusFault Status Register
  197. #define SCB_BFSR (* ((volatile uint8_t *) (0xE000E000 + 0xD29)))
  198. // Boolean field: Instruction bus error
  199. static const uint8_t SCB_BFSR_IBUSERR = 1U << 0 ;
  200. // Boolean field: Precise data bus error
  201. static const uint8_t SCB_BFSR_PRECISERR = 1U << 1 ;
  202. // Boolean field: Precise data bus error
  203. static const uint8_t SCB_BFSR_IMPRECISERR = 1U << 2 ;
  204. // Boolean field: BusFault on unstacking for a return from exception.
  205. static const uint8_t SCB_BFSR_UNSTKERR = 1U << 3 ;
  206. // Boolean field: BusFault on stacking for exception entry.
  207. static const uint8_t SCB_BFSR_STKERR = 1U << 4 ;
  208. // Boolean field: BusFault on floating-point lazy state preservation.
  209. static const uint8_t SCB_BFSR_LSPERR = 1U << 5 ;
  210. // Boolean field: BusFault Address Register valid flag.
  211. static const uint8_t SCB_BFSR_BFARVALID = 1U << 7 ;
  212. //-------------------- UsageFault Status Register
  213. #define SCB_UFSR (* ((volatile uint16_t *) (0xE000E000 + 0xD2A)))
  214. // Boolean field: Undefined instruction UsageFault
  215. static const uint16_t SCB_UFSR_UNDEFINSTR = 1U << 0 ;
  216. // Boolean field: Invalid State UsageFault
  217. static const uint16_t SCB_UFSR_INVSTATE = 1U << 1 ;
  218. // Boolean field: Invalid PC load UsageFault, caused by an invalid PC load by EXC_RETURN
  219. static const uint16_t SCB_UFSR_INVPC = 1U << 2 ;
  220. // Boolean field: No coprocessor UsageFault
  221. static const uint16_t SCB_UFSR_NOCP = 1U << 3 ;
  222. // Boolean field: Unaligned access UsageFault
  223. static const uint16_t SCB_UFSR_UNALIGNED = 1U << 8 ;
  224. // Boolean field: Divide by zero UsageFault.
  225. static const uint16_t SCB_UFSR_DIVBYZERO = 1U << 9 ;
  226. //-------------------- HardFault Status Register
  227. #define SCB_HFSR (* ((volatile uint32_t *) (0xE000E000 + 0xD2C)))
  228. // Boolean field: Indicates a BusFault on a vector table read during exception processing.
  229. static const uint32_t SCB_HFSR_VECTTBL = 1U << 1 ;
  230. // Boolean field: Indicates a forced hard fault, generated by escalation of a fault with configurable priority that cannot be handled, either because of priority or because it is disabled.
  231. static const uint32_t SCB_HFSR_FORCED = 1U << 30 ;
  232. // Boolean field: Reserved for Debug use. When writing to the register, you must write 1 to this bit, otherwise behavior is UNPREDICTABLE.
  233. static const uint32_t SCB_HFSR_DEBUGEVT = 1U << 31 ;
  234. //-------------------- MemManage Fault Address Register
  235. #define SCB_MMAR (* ((volatile uint32_t *) (0xE000E000 + 0xD34)))
  236. //-------------------- BusFault Address Register
  237. #define SCB_BFAR (* ((volatile uint32_t *) (0xE000E000 + 0xD38)))
  238. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  239. // Peripheral SysTick
  240. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  241. //-------------------- SysTick Control and Status Register
  242. #define SysTick_CSR (* ((volatile uint32_t *) (0xE000E010 + 0)))
  243. // Boolean field: Enable SysTick Timer
  244. static const uint32_t SysTick_CSR_ENABLE = 1U << 0 ;
  245. // Boolean field: Generate Tick Interrupt
  246. static const uint32_t SysTick_CSR_TICKINT = 1U << 1 ;
  247. // Boolean field: Source to count from
  248. static const uint32_t SysTick_CSR_CLKSOURCE = 1U << 2 ;
  249. // Boolean field: SysTick counted to zero
  250. static const uint32_t SysTick_CSR_COUNTFLAG = 1U << 16 ;
  251. //-------------------- SysTick Reload Value Register
  252. #define SysTick_RVR (* ((volatile uint32_t *) (0xE000E010 + 0x4)))
  253. // Field (width: 24 bits): Value to auto reload SysTick after reaching zero
  254. inline uint32_t SysTick_RVR_RELOAD (const uint32_t inValue) { return (inValue & 16777215) << 0 ; }
  255. //-------------------- SysTick Current Value Register
  256. #define SysTick_CVR (* ((volatile uint32_t *) (0xE000E010 + 0x8)))
  257. // Field (width: 24 bits): Current value
  258. inline uint32_t SysTick_CVR_CURRENT (const uint32_t inValue) { return (inValue & 16777215) << 0 ; }
  259. //-------------------- SysTick Calibration Value Register
  260. #define SysTick_CALIB (* ((const volatile uint32_t *) (0xE000E010 + 0xC)))
  261. // Field (width: 24 bits): Reload value to use for 10ms timing
  262. inline uint32_t SysTick_CALIB_TENMS (const uint32_t inValue) { return (inValue & 16777215) << 0 ; }
  263. // Boolean field: Clock Skew
  264. static const uint32_t SysTick_CALIB_SKEW = 1U << 30 ;
  265. // Boolean field: No Ref
  266. static const uint32_t SysTick_CALIB_NOREF = 1U << 31 ;
  267. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  268. // Peripheral MPU
  269. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  270. //-------------------- MPU Type Register
  271. #define MPU_TYPE (* ((const volatile uint32_t *) (0xE000ED90 + 0x0)))
  272. // Boolean field: Indicates support for unified or separate instruction and data memory maps.
  273. static const uint32_t MPU_TYPE_SEPARATE = 1U << 0 ;
  274. // Field (width: 8 bits): Indicates the number of supported MPU data regions depending on your implementation.
  275. inline uint32_t MPU_TYPE_DREGION (const uint32_t inValue) { return (inValue & 255) << 8 ; }
  276. // Field (width: 8 bits): Indicates the number of supported MPU instruction regions. Always contains 0x0: the MPU memory map is unified and is described by the DREGION field.
  277. inline uint32_t MPU_TYPE_IREGION (const uint32_t inValue) { return (inValue & 255) << 16 ; }
  278. //-------------------- MPU Control Register
  279. #define MPU_CTRL (* ((volatile uint32_t *) (0xE000ED90 + 0x4)))
  280. // Boolean field: Enables the optional MPU.
  281. static const uint32_t MPU_CTRL_ENABLE = 1U << 0 ;
  282. // Boolean field: Enables the operation of MPU during hard fault, NMI, and FAULTMASK handlers.
  283. static const uint32_t MPU_CTRL_HFNMIENA = 1U << 1 ;
  284. // Boolean field: Enables privileged software access to the default memory map.
  285. static const uint32_t MPU_CTRL_PRIVDEFENA = 1U << 2 ;
  286. //-------------------- MPU Region Number Register
  287. #define MPU_RNR (* ((volatile uint32_t *) (0xE000ED90 + 0x8)))
  288. // Field (width: 8 bits): Indicates the MPU region referenced by the MPU_RBAR and MPU_RASR registers.
  289. inline uint32_t MPU_RNR_REGION (const uint32_t inValue) { return (inValue & 255) << 0 ; }
  290. //-------------------- MPU Region Base Address Register
  291. #define MPU_RBAR (* ((volatile uint32_t *) (0xE000ED90 + 0xC)))
  292. // Field (width: 4 bits): On Write, see the VALID field. On read, specifies the region number.
  293. inline uint32_t MPU_RBAR_REGION (const uint32_t inValue) { return (inValue & 15) << 0 ; }
  294. // Boolean field: MPU Region number valid bit. Depending on your implementation, this has the following effect: 0 - either updates the base address for the region specified by MPU_RNR or ignores the value of the REGION field. 1 - either updates the value of the MPU_RNR to the value of the REGION field or updates the base address for the region specified in the REGION field.
  295. static const uint32_t MPU_RBAR_VALID = 1U << 4 ;
  296. // Field (width: 27 bits): The ADDR field is bits[31:N] of the MPU_RBAR.
  297. inline uint32_t MPU_RBAR_ADDR (const uint32_t inValue) { return (inValue & 134217727) << 5 ; }
  298. //-------------------- MPU Region Base Attribute and Size Register
  299. #define MPU_RASR (* ((volatile uint32_t *) (0xE000ED90 + 0x10)))
  300. // Boolean field: Region enable bit.
  301. static const uint32_t MPU_RASR_ENABLE = 1U << 0 ;
  302. // Field (width: 5 bits): Specifies the size of the MPU protection region. Minimum value is 4. The Region size is defined as (Region size in bytes) = 2^(SIZE+1)
  303. inline uint32_t MPU_RASR_SIZE (const uint32_t inValue) { return (inValue & 31) << 1 ; }
  304. // Boolean field: Subregion disable bits
  305. static const uint32_t MPU_RASR_SRD0 = 1U << 8 ;
  306. // Boolean field: Subregion disable bits
  307. static const uint32_t MPU_RASR_SRD1 = 1U << 9 ;
  308. // Boolean field: Subregion disable bits
  309. static const uint32_t MPU_RASR_SRD2 = 1U << 10 ;
  310. // Boolean field: Subregion disable bits
  311. static const uint32_t MPU_RASR_SRD3 = 1U << 11 ;
  312. // Boolean field: Subregion disable bits
  313. static const uint32_t MPU_RASR_SRD4 = 1U << 12 ;
  314. // Boolean field: Subregion disable bits.
  315. static const uint32_t MPU_RASR_SRD5 = 1U << 13 ;
  316. // Boolean field: Subregion disable bits.
  317. static const uint32_t MPU_RASR_SRD6 = 1U << 14 ;
  318. // Boolean field: Subregion disable bits.
  319. static const uint32_t MPU_RASR_SRD7 = 1U << 15 ;
  320. // Boolean field: Memory access attribute.
  321. static const uint32_t MPU_RASR_B = 1U << 16 ;
  322. // Boolean field: Memory access attribute.
  323. static const uint32_t MPU_RASR_C = 1U << 17 ;
  324. // Boolean field: Shareable bit. Applies to Normal memory only.
  325. static const uint32_t MPU_RASR_S = 1U << 18 ;
  326. // Field (width: 3 bits): Memory access attribute.
  327. inline uint32_t MPU_RASR_TEX (const uint32_t inValue) { return (inValue & 7) << 19 ; }
  328. // Field (width: 3 bits): Access permission field
  329. inline uint32_t MPU_RASR_AP (const uint32_t inValue) { return (inValue & 7) << 24 ; }
  330. // Boolean field: Instruction access disable bit
  331. static const uint32_t MPU_RASR_XN = 1U << 28 ;
  332. //-------------------- Uses (MPU_RNR[7:2]<<2) + 1
  333. #define MPU_RBAR_A1 (* ((volatile uint32_t *) (0xE000ED90 + 0x14)))
  334. //-------------------- Uses (MPU_RNR[7:2]<<2) + 1
  335. #define MPU_RASR_A1 (* ((volatile uint32_t *) (0xE000ED90 + 0x18)))
  336. //-------------------- Uses (MPU_RNR[7:2]<<2) + 2
  337. #define MPU_RBAR_A2 (* ((volatile uint32_t *) (0xE000ED90 + 0x1C)))
  338. //-------------------- Uses (MPU_RNR[7:2]<<2) + 2
  339. #define MPU_RASR_A2 (* ((volatile uint32_t *) (0xE000ED90 + 0x20)))
  340. //-------------------- Uses (MPU_RNR[7:2]<<2) + 3
  341. #define MPU_RBAR_A3 (* ((volatile uint32_t *) (0xE000ED90 + 0x24)))
  342. //-------------------- Uses (MPU_RNR[7:2]<<2) + 3
  343. #define MPU_RASR_A3 (* ((volatile uint32_t *) (0xE000ED90 + 0x28)))
  344. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  345. // Peripheral Debug
  346. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  347. //-------------------- Debug Fault Status Register
  348. #define Debug_DFSR (* ((volatile uint32_t *) (0xE000ED00 + 0x30)))
  349. // Boolean field: Halt request debug event.
  350. static const uint32_t Debug_DFSR_HALTED = 1U << 0 ;
  351. // Boolean field: BKPT instruction executed or breakpoint match in FPB.
  352. static const uint32_t Debug_DFSR_BKPT = 1U << 1 ;
  353. // Boolean field: Data Watchpoint and Trace trap. Indicates that the core halted due to at least one DWT trap event.
  354. static const uint32_t Debug_DFSR_DWTTRAP = 1U << 2 ;
  355. // Boolean field: Vector catch triggered. Corresponding FSR will contain the primary cause of the exception.
  356. static const uint32_t Debug_DFSR_VCATCH = 1U << 3 ;
  357. // Boolean field: An asynchronous exception generated due to the assertion of EDBGRQ.
  358. static const uint32_t Debug_DFSR_EXTERNAL = 1U << 4 ;
  359. //-------------------- Debug Halting Control and Status Register (on read)
  360. #define Debug_DHCSR_RO (* ((const volatile uint32_t *) (0xE000ED00 + 0xF0)))
  361. // Boolean field: Halting debug enable bit.
  362. static const uint32_t Debug_DHCSR_RO_C_DEBUGGEN = 1U << 0 ;
  363. // Boolean field: Processor halt bit.
  364. static const uint32_t Debug_DHCSR_RO_C_HALT = 1U << 1 ;
  365. // Boolean field: Processor step bit.
  366. static const uint32_t Debug_DHCSR_RO_C_STEP = 1U << 2 ;
  367. // Boolean field: When debug is enabled, the debugger can write to this bit to mask PendSV, SysTick and external configurable interrupts.
  368. static const uint32_t Debug_DHCSR_RO_C_MASKINTS = 1U << 3 ;
  369. // Boolean field: Allow imprecise entry to Debug state.
  370. static const uint32_t Debug_DHCSR_RO_C_SNAPSTALL = 1U << 5 ;
  371. // Boolean field: A handshake flag for transfers through the DCRDR.
  372. static const uint32_t Debug_DHCSR_RO_S_REGRDY = 1U << 16 ;
  373. // Boolean field: Indicates whether the processor is in Debug state.
  374. static const uint32_t Debug_DHCSR_RO_S_HALT = 1U << 17 ;
  375. // Boolean field: Indicates whether the processor is sleeping.
  376. static const uint32_t Debug_DHCSR_RO_S_SLEEP = 1U << 18 ;
  377. // Boolean field: Indicates whether the processor is locked up because of an unrecoverable exception.
  378. static const uint32_t Debug_DHCSR_RO_S_LOCKUP = 1U << 19 ;
  379. // Boolean field: Set to 1 every time the processor retires one or more instructions.
  380. static const uint32_t Debug_DHCSR_RO_S_RETIRE_ST = 1U << 24 ;
  381. // Boolean field: Indicates whether the processor has been reset since the last read of DHCSR.
  382. static const uint32_t Debug_DHCSR_RO_S_RESET_ST = 1U << 25 ;
  383. //-------------------- Debug Halting Control and Status Register (on write)
  384. #define Debug_DHCSR_WO (* ((volatile uint32_t *) (0xE000ED00 + 0xF0)))
  385. // Boolean field: Halting debug enable bit.
  386. static const uint32_t Debug_DHCSR_WO_C_DEBUGGEN = 1U << 0 ;
  387. // Boolean field: Processor halt bit.
  388. static const uint32_t Debug_DHCSR_WO_C_HALT = 1U << 1 ;
  389. // Boolean field: Processor step bit.
  390. static const uint32_t Debug_DHCSR_WO_C_STEP = 1U << 2 ;
  391. // Boolean field: When debug is enabled, the debugger can write to this bit to mask PendSV, SysTick and external configurable interrupts.
  392. static const uint32_t Debug_DHCSR_WO_C_MASKINTS = 1U << 3 ;
  393. // Boolean field: Allow imprecise entry to Debug state.
  394. static const uint32_t Debug_DHCSR_WO_C_SNAPSTALL = 1U << 5 ;
  395. // Field (width: 16 bits): Debug Key. The value 0xA05F must be written to enable write accesses to bits [15:0], otherwise the write access will be ignored.
  396. inline uint32_t Debug_DHCSR_WO_S_RESET_ST (const uint32_t inValue) { return (inValue & 65535) << 16 ; }
  397. //-------------------- Debug Core Register Selector Register
  398. #define Debug_DCRSR (* ((volatile uint32_t *) (0xE000ED00 + 0xF4)))
  399. // Field (width: 4 bits): Specifies the ARM core register, special-purpose register, or Floating-point extension register, to transfer.
  400. inline uint32_t Debug_DCRSR_REGSEL (const uint32_t inValue) { return (inValue & 15) << 0 ; }
  401. // Boolean field: Specifies the access type for the transfer.
  402. static const uint32_t Debug_DCRSR_REGWnR = 1U << 16 ;
  403. //-------------------- Debug Core Register Data Register
  404. #define Debug_DCRDR (* ((volatile uint32_t *) (0xE000ED00 + 0xF8)))
  405. //-------------------- Debug Exception and Monitor Control Register
  406. #define Debug_DEMCR (* ((volatile uint32_t *) (0xE000ED00 + 0xFC)))
  407. // Boolean field: Enable Reset Vector Catch. This causes a Local reset to halt a running system.
  408. static const uint32_t Debug_DEMCR_VC_CORERESET = 1U << 0 ;
  409. // Boolean field: Enable halting debug trap on a MemManage exception.
  410. static const uint32_t Debug_DEMCR_VC_MMERR = 1U << 4 ;
  411. // Boolean field: Enable halting debug trap on a UsageFault caused by an access to a Coprocessor.
  412. static const uint32_t Debug_DEMCR_VC_NOCPERR = 1U << 5 ;
  413. // Boolean field: Enable halting debug trap on a UsageFault exception caused by a checking error, for example an alignment check error.
  414. static const uint32_t Debug_DEMCR_VC_CHKERR = 1U << 6 ;
  415. // Boolean field: Enable halting debug trap on a UsageFault exception caused by a state information error, for example an Undefined instruction.
  416. static const uint32_t Debug_DEMCR_VC_STATERR = 1U << 7 ;
  417. // Boolean field: Enable halting debug trap on a BusFault exception.
  418. static const uint32_t Debug_DEMCR_VC_BUSERR = 1U << 8 ;
  419. // Boolean field: Enable halting debug trap on a fault occurring during exception entry or exception return.
  420. static const uint32_t Debug_DEMCR_VC_INTERR = 1U << 9 ;
  421. // Boolean field: Enable halting debug trap on HardFault exception.
  422. static const uint32_t Debug_DEMCR_VC_HARDERR = 1U << 10 ;
  423. // Boolean field: Enable the DebugMonitor exception.
  424. static const uint32_t Debug_DEMCR_MON_EN = 1U << 16 ;
  425. // Boolean field: Sets or clears the pending state of the DebugMonitor exception.
  426. static const uint32_t Debug_DEMCR_MON_PEND = 1U << 17 ;
  427. // Boolean field: When MON_EN is set to 0, this feature is disabled and the processor ignores MON_STEP. When MON_EN is set to 1, the meaning of MON_STEP is: 0 Do not step the processor, 1 Step the processor.
  428. static const uint32_t Debug_DEMCR_MON_STEP = 1U << 18 ;
  429. // Boolean field: DebugMonitor semaphore bit. The processor does not use this bit. The monitor software defines the meaning and use of this bit.
  430. static const uint32_t Debug_DEMCR_MON_REQ = 1U << 19 ;
  431. // Boolean field: Global enable for all DWT and ITM features.
  432. static const uint32_t Debug_DEMCR_TRCENA = 1U << 24 ;
  433. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  434. // Peripheral DWT
  435. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  436. //-------------------- Control Register
  437. #define DWT_CTRL (* ((volatile uint32_t *) (0xE0001000 + 0)))
  438. // Field (width: 4 bits): Number of comparators
  439. inline uint32_t DWT_CTRL_NUMCOMP (const uint32_t inValue) { return (inValue & 15) << 28 ; }
  440. // Boolean field: No trace sampling and exception tracing
  441. static const uint32_t DWT_CTRL_NOTRCPKT = 1U << 27 ;
  442. // Boolean field: No external match signals
  443. static const uint32_t DWT_CTRL_NOEXTTRIG = 1U << 26 ;
  444. // Boolean field: No cycle counter
  445. static const uint32_t DWT_CTRL_NOCYCCNT = 1U << 25 ;
  446. // Boolean field: No profiling counters
  447. static const uint32_t DWT_CTRL_NOPRFCNT = 1U << 24 ;
  448. // Boolean field: Reserved bit 23
  449. static const uint32_t DWT_CTRL_Reserved_23 = 1U << 23 ;
  450. // Boolean field: enable Cycle count event
  451. static const uint32_t DWT_CTRL_CYCEVTENA = 1U << 22 ;
  452. // Boolean field: enable Folded instruction count event
  453. static const uint32_t DWT_CTRL_FOLDEVTENA = 1U << 21 ;
  454. // Boolean field: enable Load Store Unit (LSU) count event
  455. static const uint32_t DWT_CTRL_LSUEVTENA = 1U << 20 ;
  456. // Boolean field: enable Sleep count event
  457. static const uint32_t DWT_CTRL_SLEEPEVTENA = 1U << 19 ;
  458. // Boolean field: enable interrupt overhead event
  459. static const uint32_t DWT_CTRL_EXCEVTENA = 1U << 18 ;
  460. // Boolean field: enable CPI count event
  461. static const uint32_t DWT_CTRL_CPIEVTENA = 1U << 17 ;
  462. // Boolean field: enable interrupt event tracing
  463. static const uint32_t DWT_CTRL_EXCTRCENA = 1U << 16 ;
  464. // Field (width: 3 bits): Reserved bits 13..15
  465. inline uint32_t DWT_CTRL_Reserved_13_15 (const uint32_t inValue) { return (inValue & 7) << 13 ; }
  466. // Boolean field: enable POSTCNT as timer for PC sample packets
  467. static const uint32_t DWT_CTRL_PCSAMPLENA = 1U << 12 ;
  468. // Field (width: 2 bits): ???
  469. inline uint32_t DWT_CTRL_SYNCTAP (const uint32_t inValue) { return (inValue & 3) << 10 ; }
  470. // Boolean field: ???
  471. static const uint32_t DWT_CTRL_CYCTAP = 1U << 9 ;
  472. // Field (width: 4 bits): ???
  473. inline uint32_t DWT_CTRL_POSTINIT (const uint32_t inValue) { return (inValue & 15) << 5 ; }
  474. // Field (width: 4 bits): ???
  475. inline uint32_t DWT_CTRL_POSTPRESET (const uint32_t inValue) { return (inValue & 15) << 1 ; }
  476. // Boolean field: enable cycle counter
  477. static const uint32_t DWT_CTRL_CYCCNTENA = 1U << 0 ;
  478. //-------------------- Cycle Count Register
  479. #define DWT_CYCCNT (* ((volatile uint32_t *) (0xE0001000 + 4)))
  480. //-------------------- CPI Count Register
  481. #define DWT_CPICNT (* ((volatile uint32_t *) (0xE0001000 + 8)))
  482. //-------------------- Exception Overhead Count Register
  483. #define DWT_EXCCNT (* ((volatile uint32_t *) (0xE0001000 + 0xC)))
  484. //-------------------- Sleep Count Register
  485. #define DWT_SLEEPCNT (* ((volatile uint32_t *) (0xE0001000 + 0x10)))
  486. //-------------------- LSU Count Register
  487. #define DWT_LSUCNT (* ((volatile uint32_t *) (0xE0001000 + 0x14)))
  488. //-------------------- Folded-instruction Count Register
  489. #define DWT_FOLDCNT (* ((volatile uint32_t *) (0xE0001000 + 0x18)))
  490. //-------------------- Program Counter Sample Register
  491. #define DWT_PCSR (* ((const volatile uint32_t *) (0xE0001000 + 0x1C)))
  492. //-------------------- Comparator Register 0
  493. #define DWT_COMP0 (* ((volatile uint32_t *) (0xE0001000 + 0x20)))
  494. //-------------------- Mask Register 0
  495. #define DWT_MASK0 (* ((volatile uint32_t *) (0xE0001000 + 0x24)))
  496. //-------------------- Function Register 0
  497. #define DWT_FUNCTION0 (* ((volatile uint32_t *) (0xE0001000 + 0x28)))
  498. //-------------------- Comparator Register 1
  499. #define DWT_COMP1 (* ((volatile uint32_t *) (0xE0001000 + 0x30)))
  500. //-------------------- Mask Register 1
  501. #define DWT_MASK1 (* ((volatile uint32_t *) (0xE0001000 + 0x34)))
  502. //-------------------- Function Register 1
  503. #define DWT_FUNCTION1 (* ((volatile uint32_t *) (0xE0001000 + 0x38)))
  504. //-------------------- Comparator Register 2
  505. #define DWT_COMP2 (* ((volatile uint32_t *) (0xE0001000 + 0x40)))
  506. //-------------------- Mask Register 2
  507. #define DWT_MASK2 (* ((volatile uint32_t *) (0xE0001000 + 0x44)))
  508. //-------------------- Function Register 2
  509. #define DWT_FUNCTION2 (* ((volatile uint32_t *) (0xE0001000 + 0x48)))
  510. //-------------------- Comparator Register 3
  511. #define DWT_COMP3 (* ((volatile uint32_t *) (0xE0001000 + 0x50)))
  512. //-------------------- Mask Register 3
  513. #define DWT_MASK3 (* ((volatile uint32_t *) (0xE0001000 + 0x54)))
  514. //-------------------- Function Register 3
  515. #define DWT_FUNCTION3 (* ((volatile uint32_t *) (0xE0001000 + 0x58)))
  516. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  517. // Peripheral SYST
  518. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
  519. //-------------------- SysTick Control and Status
  520. #define SYST_CSR (* ((volatile uint32_t *) (0xE000E000 + 0x10)))
  521. // Boolean field: Enable the Counter
  522. static const uint32_t SYST_CSR_ENABLE = 1U << 0 ;
  523. // Boolean field: Enables SysTick exception request
  524. static const uint32_t SYST_CSR_TICKINT = 1U << 1 ;
  525. // Boolean field: Clock Source Selection
  526. static const uint32_t SYST_CSR_CLKSOURCE = 1U << 2 ;
  527. // Boolean field: Returns 1 if timer counted to 0 since last time this was read
  528. static const uint32_t SYST_CSR_COUNTFLAG = 1U << 16 ;
  529. //-------------------- SysTick Reload Value Register
  530. #define SYST_RVR (* ((volatile uint32_t *) (0xE000E000 + 0x14)))
  531. //-------------------- SysTick Current Value Register
  532. #define SYST_CVR (* ((volatile uint32_t *) (0xE000E000 + 0x18)))
  533. //-------------------- SysTick Calibration Value Register
  534. #define SYST_CALIB (* ((const volatile uint32_t *) (0xE000E000 + 0x1C)))
  535. //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————