cortexm7.pp 17 KB

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