cortexm7.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. {
  2. System register definitions and utility code for Cortex-M7
  3. Created by Jeppe Johansen 2015 - [email protected]
  4. }
  5. unit cortexm7;
  6. interface
  7. {$PACKRECORDS C}
  8. type
  9. NVIC_Type = record
  10. ISER: array [0..7] of longword; (*!< Offset: 0x000 (R/W) Interrupt Set Enable Register *)
  11. RESERVED0: array [0..23] of longword;
  12. ICER: array [0..7] of longword; (*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register *)
  13. RSERVED1: array [0..23] of longword;
  14. ISPR: array [0..7] of longword; (*!< Offset: 0x100 (R/W) Interrupt Set Pending Register *)
  15. RESERVED2: array [0..23] of longword;
  16. ICPR: array [0..7] of longword; (*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register *)
  17. RESERVED3: array [0..23] of longword;
  18. IABR: array [0..7] of longword; (*!< Offset: 0x200 (R/W) Interrupt Active bit Register *)
  19. RESERVED4: array [0..55] of longword;
  20. IP: array [0..239] of byte; (*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) *)
  21. RESERVED5: array [0..643] of longword;
  22. STIR: longword; (*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register *)
  23. end;
  24. SCB_Type = record
  25. CPUID: longword; (*!< Offset: 0x000 (R/ ) CPUID Base Register *)
  26. ICSR: longword; (*!< Offset: 0x004 (R/W) Interrupt Control and State Register *)
  27. VTOR: longword; (*!< Offset: 0x008 (R/W) Vector Table Offset Register *)
  28. AIRCR: longword; (*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register *)
  29. SCR: longword; (*!< Offset: 0x010 (R/W) System Control Register *)
  30. CCR: longword; (*!< Offset: 0x014 (R/W) Configuration Control Register *)
  31. SHPR: array [0..11] of byte; (*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) *)
  32. SHCSR: longword; (*!< Offset: 0x024 (R/W) System Handler Control and State Register *)
  33. CFSR: longword; (*!< Offset: 0x028 (R/W) Configurable Fault Status Register *)
  34. HFSR: longword; (*!< Offset: 0x02C (R/W) HardFault Status Register *)
  35. DFSR: longword; (*!< Offset: 0x030 (R/W) Debug Fault Status Register *)
  36. MMFAR: longword; (*!< Offset: 0x034 (R/W) MemManage Fault Address Register *)
  37. BFAR: longword; (*!< Offset: 0x038 (R/W) BusFault Address Register *)
  38. AFSR: longword; (*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register *)
  39. ID_PFR: array [0..1] of longword; (*!< Offset: 0x040 (R/ ) Processor Feature Register *)
  40. ID_DFR: longword; (*!< Offset: 0x048 (R/ ) Debug Feature Register *)
  41. ID_AFR: longword; (*!< Offset: 0x04C (R/ ) Auxiliary Feature Register *)
  42. ID_MFR: array [0..3] of longword; (*!< Offset: 0x050 (R/ ) Memory Model Feature Register *)
  43. ID_ISAR: array [0..4] of longword; (*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register *)
  44. RESERVED0: array [0..0] of longword;
  45. CLIDR: longword; (*!< Offset: 0x078 (R/ ) Cache Level ID register *)
  46. CTR: longword; (*!< Offset: 0x07C (R/ ) Cache Type register *)
  47. CCSIDR: longword; (*!< Offset: 0x080 (R/ ) Cache Size ID Register *)
  48. CSSELR: longword; (*!< Offset: 0x084 (R/W) Cache Size Selection Register *)
  49. CPACR: longword; (*!< Offset: 0x088 (R/W) Coprocessor Access Control Register *)
  50. RESERVED3: array [0..92] of longword;
  51. STIR: longword; (*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register *)
  52. RESERVED4: array [0..14] of longword;
  53. MVFR0: longword; (*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 *)
  54. MVFR1: longword; (*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 *)
  55. MVFR2: longword; (*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 1 *)
  56. RESERVED5: array [0..0] of longword;
  57. ICIALLU: longword; (*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU *)
  58. RESERVED6: array [0..0] of longword;
  59. ICIMVAU: longword; (*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU *)
  60. DCIMVAC: longword; (*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC *)
  61. DCISW: longword; (*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way *)
  62. DCCMVAU: longword; (*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU *)
  63. DCCMVAC: longword; (*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC *)
  64. DCCSW: longword; (*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way *)
  65. DCCIMVAC: longword; (*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC *)
  66. DCCISW: longword; (*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way *)
  67. RESERVED7: array [0..5] of longword;
  68. ITCMCR: longword; (*!< Offset: 0x290 (R/W) Instruction Tightly-Coupled Memory Control Register *)
  69. DTCMCR: longword; (*!< Offset: 0x294 (R/W) Data Tightly-Coupled Memory Control Registers *)
  70. AHBPCR: longword; (*!< Offset: 0x298 (R/W) AHBP Control Register *)
  71. CACR: longword; (*!< Offset: 0x29C (R/W) L1 Cache Control Register *)
  72. AHBSCR: longword; (*!< Offset: 0x2A0 (R/W) AHB Slave Control Register *)
  73. RESERVED8: array [0..0] of longword;
  74. ABFSR: longword; (*!< Offset: 0x2A8 (R/W) Auxiliary Bus Fault Status Register *)
  75. end;
  76. SCnSCB_Type = record
  77. RESERVED0: array [0..0] of longword;
  78. ICTR: longword; (*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register *)
  79. ACTLR: longword; (*!< Offset: 0x008 (R/W) Auxiliary Control Register *)
  80. end;
  81. SysTick_Type = record
  82. CTRL: longword; (*!< Offset: 0x000 (R/W) SysTick Control and Status Register *)
  83. LOAD: longword; (*!< Offset: 0x004 (R/W) SysTick Reload Value Register *)
  84. VAL: longword; (*!< Offset: 0x008 (R/W) SysTick Current Value Register *)
  85. CALIB: longword; (*!< Offset: 0x00C (R/ ) SysTick Calibration Register *)
  86. end;
  87. ITM_Type = record
  88. PORT: array [0..31] of record
  89. case integer of
  90. 0: (u8: byte;); (*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit *)
  91. 1: (u16: word;); (*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit *)
  92. 2: (u32: longword;); (*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit *)
  93. end;
  94. (*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers *)
  95. RESERVED0: array [0..863] of longword;
  96. TER: longword; (*!< Offset: 0xE00 (R/W) ITM Trace Enable Register *)
  97. RESERVED1: array [0..14] of longword;
  98. TPR: longword; (*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register *)
  99. RESERVED2: array [0..14] of longword;
  100. TCR: longword; (*!< Offset: 0xE80 (R/W) ITM Trace Control Register *)
  101. RESERVED3: array [0..28] of longword;
  102. IWR: longword; (*!< Offset: 0xEF8 ( /W) ITM Integration Write Register *)
  103. IRR: longword; (*!< Offset: 0xEFC (R/ ) ITM Integration Read Register *)
  104. IMCR: longword; (*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register *)
  105. RESERVED4: array [0..42] of longword;
  106. LAR: longword; (*!< Offset: 0xFB0 ( /W) ITM Lock Access Register *)
  107. LSR: longword; (*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register *)
  108. RESERVED5: array [0..5] of longword;
  109. PID4: longword; (*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 *)
  110. PID5: longword; (*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 *)
  111. PID6: longword; (*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 *)
  112. PID7: longword; (*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 *)
  113. PID0: longword; (*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 *)
  114. PID1: longword; (*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 *)
  115. PID2: longword; (*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 *)
  116. PID3: longword; (*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 *)
  117. CID0: longword; (*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 *)
  118. CID1: longword; (*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 *)
  119. CID2: longword; (*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 *)
  120. CID3: longword; (*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 *)
  121. end;
  122. DWT_Type = record
  123. CTRL: longword; (*!< Offset: 0x000 (R/W) Control Register *)
  124. CYCCNT: longword; (*!< Offset: 0x004 (R/W) Cycle Count Register *)
  125. CPICNT: longword; (*!< Offset: 0x008 (R/W) CPI Count Register *)
  126. EXCCNT: longword; (*!< Offset: 0x00C (R/W) Exception Overhead Count Register *)
  127. SLEEPCNT: longword; (*!< Offset: 0x010 (R/W) Sleep Count Register *)
  128. LSUCNT: longword; (*!< Offset: 0x014 (R/W) LSU Count Register *)
  129. FOLDCNT: longword; (*!< Offset: 0x018 (R/W) Folded-instruction Count Register *)
  130. PCSR: longword; (*!< Offset: 0x01C (R/ ) Program Counter Sample Register *)
  131. COMP0: longword; (*!< Offset: 0x020 (R/W) Comparator Register 0 *)
  132. MASK0: longword; (*!< Offset: 0x024 (R/W) Mask Register 0 *)
  133. FUNCTION0: longword; (*!< Offset: 0x028 (R/W) Function Register 0 *)
  134. RESERVED0: array [0..0] of longword;
  135. COMP1: longword; (*!< Offset: 0x030 (R/W) Comparator Register 1 *)
  136. MASK1: longword; (*!< Offset: 0x034 (R/W) Mask Register 1 *)
  137. FUNCTION1: longword; (*!< Offset: 0x038 (R/W) Function Register 1 *)
  138. RESERVED1: array [0..0] of longword;
  139. COMP2: longword; (*!< Offset: 0x040 (R/W) Comparator Register 2 *)
  140. MASK2: longword; (*!< Offset: 0x044 (R/W) Mask Register 2 *)
  141. FUNCTION2: longword; (*!< Offset: 0x048 (R/W) Function Register 2 *)
  142. RESERVED2: array [0..0] of longword;
  143. COMP3: longword; (*!< Offset: 0x050 (R/W) Comparator Register 3 *)
  144. MASK3: longword; (*!< Offset: 0x054 (R/W) Mask Register 3 *)
  145. FUNCTION3: longword; (*!< Offset: 0x058 (R/W) Function Register 3 *)
  146. RESERVED3: array [0..980] of longword;
  147. LAR: longword; (*!< Offset: 0xFB0 ( W) Lock Access Register *)
  148. LSR: longword; (*!< Offset: 0xFB4 (R ) Lock Status Register *)
  149. end;
  150. TPI_Type = record
  151. SSPSR: longword; (*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register *)
  152. CSPSR: longword; (*!< Offset: 0x004 (R/W) Current Parallel Port Size Register *)
  153. RESERVED0: array [0..1] of longword;
  154. ACPR: longword; (*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register *)
  155. RESERVED1: array [0..54] of longword;
  156. SPPR: longword; (*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register *)
  157. RESERVED2: array [0..130] of longword;
  158. FFSR: longword; (*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register *)
  159. FFCR: longword; (*!< Offset: 0x304 (R/W) Formatter and Flush Control Register *)
  160. FSCR: longword; (*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register *)
  161. RESERVED3: array [0..758] of longword;
  162. TRIGGER: longword; (*!< Offset: 0xEE8 (R/ ) TRIGGER *)
  163. FIFO0: longword; (*!< Offset: 0xEEC (R/ ) Integration ETM Data *)
  164. ITATBCTR2: longword; (*!< Offset: 0xEF0 (R/ ) ITATBCTR2 *)
  165. RESERVED4: array [0..0] of longword;
  166. ITATBCTR0: longword; (*!< Offset: 0xEF8 (R/ ) ITATBCTR0 *)
  167. FIFO1: longword; (*!< Offset: 0xEFC (R/ ) Integration ITM Data *)
  168. ITCTRL: longword; (*!< Offset: 0xF00 (R/W) Integration Mode Control *)
  169. RESERVED5: array [0..38] of longword;
  170. CLAIMSET: longword; (*!< Offset: 0xFA0 (R/W) Claim tag set *)
  171. CLAIMCLR: longword; (*!< Offset: 0xFA4 (R/W) Claim tag clear *)
  172. RESERVED7: array [0..7] of longword;
  173. DEVID: longword; (*!< Offset: 0xFC8 (R/ ) TPIU_DEVID *)
  174. DEVTYPE: longword; (*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE *)
  175. end;
  176. MPU_Type = record
  177. TYPE_: longword; (*!< Offset: 0x000 (R/ ) MPU Type Register *)
  178. CTRL: longword; (*!< Offset: 0x004 (R/W) MPU Control Register *)
  179. RNR: longword; (*!< Offset: 0x008 (R/W) MPU Region RNRber Register *)
  180. RBAR: longword; (*!< Offset: 0x00C (R/W) MPU Region Base Address Register *)
  181. RASR: longword; (*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register *)
  182. RBAR_A1: longword; (*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register *)
  183. RASR_A1: longword; (*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register *)
  184. RBAR_A2: longword; (*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register *)
  185. RASR_A2: longword; (*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register *)
  186. RBAR_A3: longword; (*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register *)
  187. RASR_A3: longword; (*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register *)
  188. end;
  189. FPU_Type = record
  190. RESERVED0: array [0..0] of longword;
  191. FPCCR: longword; (*!< Offset: 0x004 (R/W) Floating-Point Context Control Register *)
  192. FPCAR: longword; (*!< Offset: 0x008 (R/W) Floating-Point Context Address Register *)
  193. FPDSCR: longword; (*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register *)
  194. MVFR0: longword; (*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 *)
  195. MVFR1: longword; (*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 *)
  196. MVFR2: longword; (*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 *)
  197. end;
  198. CoreDebug_Type = record
  199. DHCSR: longword; (*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register *)
  200. DCRSR: longword; (*!< Offset: 0x004 ( /W) Debug Core Register Selector Register *)
  201. DCRDR: longword; (*!< Offset: 0x008 (R/W) Debug Core Register Data Register *)
  202. DEMCR: longword; (*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register *)
  203. end;
  204. (* Memory mapping of Cortex-M4 Hardware *)
  205. const
  206. SCS_BASE = $E000E000; (*!< System Control Space Base Address *)
  207. ITM_BASE = $E0000000; (*!< ITM Base Address *)
  208. DWT_BASE = $E0001000; (*!< DWT Base Address *)
  209. TPI_BASE = $E0040000; (*!< TPI Base Address *)
  210. CoreDebug_BASE = $E000EDF0; (*!< Core Debug Base Address *)
  211. SysTick_BASE = SCS_BASE + $0010; (*!< SysTick Base Address *)
  212. NVIC_BASE = SCS_BASE + $0100; (*!< NVIC Base Address *)
  213. SCB_BASE = SCS_BASE + $0D00; (*!< System Control Block Base Address *)
  214. var
  215. SCnSCB: SCnSCB_Type absolute SCS_BASE; (*!< System control Register not in SCB *)
  216. SCB: SCB_Type absolute SCB_BASE; (*!< SCB configuration struct *)
  217. SysTick: SysTick_Type absolute SysTick_BASE; (*!< SysTick configuration struct *)
  218. NVIC: NVIC_Type absolute NVIC_BASE; (*!< NVIC configuration struct *)
  219. ITM: ITM_Type absolute ITM_BASE; (*!< ITM configuration struct *)
  220. DWT: DWT_Type absolute DWT_BASE; (*!< DWT configuration struct *)
  221. TPI: TPI_Type absolute TPI_BASE; (*!< TPI configuration struct *)
  222. CoreDebug: CoreDebug_Type absolute CoreDebug_BASE; (*!< Core Debug configuration struct *)
  223. type
  224. TITM_Port = 0..31;
  225. procedure ITM_SendData(Port: TITM_Port; Data: char); inline;
  226. implementation
  227. procedure ITM_SendData(Port: TITM_Port; Data: char);
  228. begin
  229. if (((ITM.TCR and 1) <> 0) and ((ITM.TER and 1) <> 0)) then
  230. begin
  231. while (ITM.PORT[integer(Port)].u32 = 0) do ;
  232. ITM.PORT[integer(Port)].u8 := byte(Data);
  233. end;
  234. end;
  235. end.