2
0

cortexm4.pp 5.7 KB

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