cortexm4.pp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. System register definitions and utility code for Cortex-M4
  3. Created by Jeppe Johansen 2012 - [email protected]
  4. }
  5. unit cortexm4;
  6. interface
  7. {$PACKRECORDS 2}
  8. const
  9. SCS_BASE = $E000E000;
  10. DWT_BASE = $E0001000;
  11. FP_BASE = $E0002000;
  12. ITM_BASE = $E0000000;
  13. TPIU_BASE = $E0040000;
  14. ETM_BASE = $E0041000;
  15. type
  16. TNVICRegisters = record
  17. ISER: array[0..7] of longword;
  18. reserved0: array[0..23] of longword;
  19. ICER: array[0..7] of longword;
  20. reserved1: array[0..23] of longword;
  21. ISPR: array[0..7] of longword;
  22. reserved2: array[0..23] of longword;
  23. ICPR: array[0..7] of longword;
  24. reserved3: array[0..23] of longword;
  25. IABR: array[0..7] of longword;
  26. reserved4: array[0..55] of longword;
  27. IP: array[0..239] of byte;
  28. reserved5: array[0..643] of longword;
  29. STIR: longword;
  30. end;
  31. TSCBRegisters = record
  32. CPUID, {!< CPU ID Base Register }
  33. ICSR, {!< Interrupt Control State Register }
  34. VTOR, {!< Vector Table Offset Register }
  35. AIRCR, {!< Application Interrupt / Reset Control Register }
  36. SCR, {!< System Control Register }
  37. CCR: longword; {!< Configuration Control Register }
  38. SHP: array[0..11] of byte; {!< System Handlers Priority Registers (4-7, 8-11, 12-15) }
  39. SHCSR, {!< System Handler Control and State Register }
  40. CFSR, {!< Configurable Fault Status Register }
  41. HFSR, {!< Hard Fault Status Register }
  42. DFSR, {!< Debug Fault Status Register }
  43. MMFAR, {!< Mem Manage Address Register }
  44. BFAR, {!< Bus Fault Address Register }
  45. AFSR: longword; {!< Auxiliary Fault Status Register }
  46. // CPUID registers
  47. PFR: array[0..1] of longword; {!< Processor Feature Register }
  48. DFR, {!< Debug Feature Register }
  49. ADR: longword; {!< Auxiliary Feature Register }
  50. MMFR: array[0..3] of longword; {!< Memory Model Feature Register }
  51. ISAR: array[0..5] of longword; {!< ISA Feature Register }
  52. CLIDR,
  53. CTR,
  54. CCSIDR,
  55. CSSELR: longword;
  56. CPACR: longword;
  57. end;
  58. TSysTickRegisters = record
  59. Ctrl,
  60. Load,
  61. Val,
  62. Calib: longword;
  63. end;
  64. TIDRegisters = record
  65. PID4_7: array[0..3] of longword;
  66. PID0_3: array[0..3] of longword;
  67. CID: array[0..3] of longword;
  68. end;
  69. TCoreDebugRegisters = record
  70. DHCSR,
  71. DCRSR,
  72. DCRDR,
  73. DEMCR: longword;
  74. end;
  75. TFPRegisters = record
  76. Ctrl,
  77. Remap: longword;
  78. Comp: array[0..7] of longword;
  79. res: array[0..987] of longword;
  80. ID: TIDRegisters;
  81. end;
  82. TDWTEntry = record
  83. Comp,
  84. Mask,
  85. Func,
  86. res: longword;
  87. end;
  88. TDWTRegisters = record
  89. Ctrl,
  90. CycCnt,
  91. CPICnt,
  92. ExcCnt,
  93. SleepCnt,
  94. LSUCnt,
  95. FoldCnt,
  96. PCSR: longword;
  97. Entries: array[0..3] of TDWTEntry;
  98. end;
  99. TITMRegisters = record
  100. Stimulus: array[0..31] of longword;
  101. res0: array[0..($E00-$7C-4)-1] of byte;
  102. TraceEnable: longword;
  103. res1: array[0..($E40-$E00-4)-1] of byte;
  104. TracePrivilege: longword;
  105. res2: array[0..($E80-$E40-4)-1] of byte;
  106. TraceControl: longword;
  107. res3: array[0..($EF8-$E80-4)-1] of byte;
  108. IntegrationWrite,
  109. IntegrationRead,
  110. IntegrationModeCtrl: longword;
  111. res4: array[0..($FB0-$F00-4)-1] of byte;
  112. LockAccess,
  113. LockStatus: longword;
  114. res5: array[0..($FD0-$FB4-4)-1] of byte;
  115. ID: TIDRegisters;
  116. end;
  117. TTPIURegisters = record
  118. SupportedSyncPortSizes,
  119. CurrentSyncPortSize: longword;
  120. res0: array[0..($10-$04-4)-1] of byte;
  121. AsyncColckPrescaler: longword;
  122. res1: array[0..($F0-$10-4)-1] of byte;
  123. SelectedPinProtocol: longword;
  124. res2: array[0..($100-$F0-4)-1] of byte;
  125. TriggerControl: array[0..2] of longword;
  126. res3: array[0..($200-$108-4)-1] of byte;
  127. TestPattern: array[0..2] of longword;
  128. res4: array[0..($300-$208-4)-1] of byte;
  129. FormatFlushStatus,
  130. FormatControl,
  131. FormatSyncCounter: longword;
  132. res5: array[0..($EF0-$308-4)-1] of byte;
  133. ITATBCTR2: longword;
  134. res6: longword;
  135. ITATBCTR0: longword;
  136. end;
  137. TFPExtRegisters = record
  138. FPCCR,
  139. FPCAR,
  140. FPDSCR: longword;
  141. MVFR: array[0..2] of longword;
  142. end;
  143. var
  144. // System Control
  145. InterruptControlType: longword absolute (SCS_BASE+$0004);
  146. SCB: TSCBRegisters absolute (SCS_BASE+$0D00);
  147. SysTick: TSysTickRegisters absolute (SCS_BASE+$0010);
  148. NVIC: TNVICRegisters absolute (SCS_BASE+$0100);
  149. SoftwareTriggerInterrupt: longword absolute (SCS_BASE+$0000);
  150. FPExt: TFPExtRegisters absolute (SCS_BASE+$0F34);
  151. // Core Debug
  152. CoreDebug: TCoreDebugRegisters absolute (SCS_BASE+$0DF0);
  153. // Flash Patch
  154. FP: TFPRegisters absolute FP_BASE;
  155. DWT: TDWTRegisters absolute DWT_BASE;
  156. ITM: TITMRegisters absolute ITM_BASE;
  157. TPIU: TTPIURegisters absolute TPIU_BASE;
  158. type
  159. TITM_Port = 0..31;
  160. procedure ITM_SendData(Port: TITM_Port; Data: longword); inline;
  161. implementation
  162. const
  163. CoreDebug_DEMCR_TRCENA = $01000000;
  164. ITM_TCR_ITMENA = $00000001;
  165. procedure ITM_SendData(Port: TITM_Port; Data: longword);
  166. begin
  167. if ((CoreDebug.DEMCR and CoreDebug_DEMCR_TRCENA) <> 0) and
  168. ((itm.TraceControl and ITM_TCR_ITMENA) <> 0) and
  169. ((ITM.TraceEnable and (1 shl Port)) <> 0) then
  170. begin
  171. while ITM.Stimulus[Port] = 0 do;
  172. ITM.Stimulus[Port] := Data;
  173. end;
  174. end;
  175. end.