cortexm3.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {
  2. System register definitions and utility code for Cortex-M3
  3. Created by Jeppe Johansen 2012 - [email protected]
  4. }
  5. unit cortexm3;
  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. PFR: array[0..1] of longword; {!< Processor Feature Register }
  47. DFR, {!< Debug Feature Register }
  48. ADR: longword; {!< Auxiliary Feature Register }
  49. MMFR: array[0..3] of longword; {!< Memory Model Feature Register }
  50. ISAR: array[0..4] of longword; {!< ISA Feature Register }
  51. end;
  52. TSysTickRegisters = record
  53. Ctrl,
  54. Load,
  55. Val,
  56. Calib: longword;
  57. end;
  58. TIDRegisters = record
  59. PID4_7: array[0..3] of longword;
  60. PID0_3: array[0..3] of longword;
  61. CID: array[0..3] of longword;
  62. end;
  63. TCoreDebugRegisters = record
  64. DHCSR,
  65. DCRSR,
  66. DCRDR,
  67. DEMCR: longword;
  68. end;
  69. TFPRegisters = record
  70. Ctrl,
  71. Remap: longword;
  72. Comp: array[0..7] of longword;
  73. res: array[0..987] of longword;
  74. ID: TIDRegisters;
  75. end;
  76. TDWTEntry = record
  77. Comp,
  78. Mask,
  79. Func,
  80. res: longword;
  81. end;
  82. TDWTRegisters = record
  83. Ctrl,
  84. CycCnt,
  85. CPICnt,
  86. ExcCnt,
  87. SleepCnt,
  88. LSUCnt,
  89. FoldCnt,
  90. PCSR: longword;
  91. Entries: array[0..3] of TDWTEntry;
  92. end;
  93. TITMRegisters = record
  94. Stimulus: array[0..31] of longword;
  95. res0: array[0..($E00-$7C-4)-1] of byte;
  96. TraceEnable: longword;
  97. res1: array[0..($E40-$E00-4)-1] of byte;
  98. TracePrivilege: longword;
  99. res2: array[0..($E80-$E40-4)-1] of byte;
  100. TraceControl: longword;
  101. res3: array[0..($EF8-$E80-4)-1] of byte;
  102. IntegrationWrite,
  103. IntegrationRead,
  104. IntegrationModeCtrl: longword;
  105. res4: array[0..($FB0-$F00-4)-1] of byte;
  106. LockAccess,
  107. LockStatus: longword;
  108. res5: array[0..($FD0-$FB4-4)-1] of byte;
  109. ID: TIDRegisters;
  110. end;
  111. TTPIURegisters = record
  112. SupportedSyncPortSizes,
  113. CurrentSyncPortSize: longword;
  114. res0: array[0..($10-$04-4)-1] of byte;
  115. AsyncColckPrescaler: longword;
  116. res1: array[0..($F0-$10-4)-1] of byte;
  117. SelectedPinProtocol: longword;
  118. res2: array[0..($100-$F0-4)-1] of byte;
  119. TriggerControl: array[0..2] of longword;
  120. res3: array[0..($200-$108-4)-1] of byte;
  121. TestPattern: array[0..2] of longword;
  122. res4: array[0..($300-$208-4)-1] of byte;
  123. FormatFlushStatus,
  124. FormatControl,
  125. FormatSyncCounter: longword;
  126. res5: array[0..($EF0-$308-4)-1] of byte;
  127. ITATBCTR2: longword;
  128. res6: longword;
  129. ITATBCTR0: longword;
  130. end;
  131. var
  132. // System Control
  133. InterruptControlType: longword absolute (SCS_BASE+$0004);
  134. SCB: TSCBRegisters absolute (SCS_BASE+$0D00);
  135. SysTick: TSysTickRegisters absolute (SCS_BASE+$0010);
  136. NVIC: TNVICRegisters absolute (SCS_BASE+$0100);
  137. SoftwareTriggerInterrupt: longword absolute (SCS_BASE+$0000);
  138. SCBID: TIDRegisters absolute (SCS_BASE+$EFD0);
  139. // Core Debug
  140. CoreDebug: TCoreDebugRegisters absolute (SCS_BASE+$0DF0);
  141. // Flash Patch
  142. FP: TFPRegisters absolute FP_BASE;
  143. DWT: TDWTRegisters absolute DWT_BASE;
  144. ITM: TITMRegisters absolute ITM_BASE;
  145. TPIU: TTPIURegisters absolute TPIU_BASE;
  146. type
  147. TITM_Port = 0..31;
  148. procedure ITM_SendData(Port: TITM_Port; Data: longword); inline;
  149. implementation
  150. const
  151. CoreDebug_DEMCR_TRCENA = $01000000;
  152. ITM_TCR_ITMENA = $00000001;
  153. procedure ITM_SendData(Port: TITM_Port; Data: longword);
  154. begin
  155. if ((CoreDebug.DEMCR and CoreDebug_DEMCR_TRCENA) <> 0) and
  156. ((itm.TraceControl and ITM_TCR_ITMENA) <> 0) and
  157. ((ITM.TraceEnable and (1 shl Port)) <> 0) then
  158. begin
  159. while ITM.Stimulus[Port] = 0 do;
  160. ITM.Stimulus[Port] := Data;
  161. end;
  162. end;
  163. end.