cortex-m4-control-registers.h 32 KB

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