DigiConnectCoreWi-iMX51.JLinkScript 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
  7. * *
  8. * www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ----------------------------------------------------------------------
  12. File : DigiConnectCoreWi-iMX51.JLinkScript
  13. Purpose : J-Link target setup file for Digi ConnectCore Wi-i.MX51 Eval board
  14. ---------------------------END-OF-HEADER------------------------------
  15. */
  16. /*********************************************************************
  17. *
  18. * _StoreSelDP
  19. */
  20. void _StoreSelDP(void) {
  21. JTAG_StoreIR(0xA); // DPACC command
  22. JTAG_StoreClocks(1);
  23. }
  24. /*********************************************************************
  25. *
  26. * _StoreSelAP
  27. */
  28. void _StoreSelAP(void) {
  29. JTAG_StoreIR(0xB); // APACC command
  30. JTAG_StoreClocks(1);
  31. }
  32. /*********************************************************************
  33. *
  34. * _StoreTriggerReadAPDPReg
  35. *
  36. * Function description
  37. * Triggers a read of an AP or DP register. Depends on the previous command (DPACC / APACC)
  38. */
  39. int _StoreTriggerReadAPDPReg(unsigned int RegIndex) {
  40. U32 v;
  41. int BitPos;
  42. //
  43. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  44. //
  45. v = 1; // 1 indicates read access
  46. v |= (RegIndex << 1);
  47. JLINK_JTAG_StartDR();
  48. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  49. v = 0;
  50. JLINK_JTAG_WriteDREnd(v, 32);
  51. JTAG_StoreClocks(8);
  52. return BitPos;
  53. }
  54. /*********************************************************************
  55. *
  56. * _StoreWriteAPDPReg
  57. *
  58. * Function description
  59. * Writes an AP or DP register. Depends on the previous command (DPACC / APACC)
  60. */
  61. int _StoreWriteAPDPReg(unsigned int RegIndex, U32 Data) {
  62. U32 v;
  63. int BitPos;
  64. //
  65. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  66. //
  67. v = 0; // 0 indicates write access
  68. v |= (RegIndex << 1);
  69. JLINK_JTAG_StartDR();
  70. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  71. v = Data;
  72. JLINK_JTAG_WriteDREnd(v, 32);
  73. JTAG_StoreClocks(8);
  74. return BitPos;
  75. }
  76. /*********************************************************************
  77. *
  78. * ResetTarget
  79. */
  80. void ResetTarget(void) {
  81. int Speed;
  82. int v;
  83. int BitPos;
  84. int Speed;
  85. int Ctrl;
  86. Speed = JTAG_Speed;
  87. JTAG_Speed = 100;
  88. JTAG_WriteClocks(1);
  89. JTAG_ResetPin = 0;
  90. SYS_Sleep(50);
  91. JTAG_ResetPin = 1;
  92. SYS_Sleep(50);
  93. JTAG_Write(0x1F, 0, 6);
  94. //
  95. // Power-up debug- and system-port by writing the debug port ctrl/stat register
  96. //
  97. _StoreSelDP();
  98. _StoreWriteAPDPReg(1, 0x50000033);
  99. JTAG_WriteClocks(10); // Give the system some time to power-up
  100. //
  101. // Select APB-AP and prepare control register
  102. //
  103. _StoreSelDP();
  104. _StoreWriteAPDPReg(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  105. _StoreSelAP();
  106. Ctrl = 0
  107. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  108. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  109. | (1 << 31) // Enable software access to the Debug APB bus.
  110. ;
  111. _StoreWriteAPDPReg(0, Ctrl);
  112. //
  113. // Perform some other init steps which are required to get full control of the debug logic
  114. //
  115. _StoreWriteAPDPReg(1, 0x60008000 + (0x3EC << 2));
  116. _StoreWriteAPDPReg(3, 0xC5ACCE55);
  117. _StoreWriteAPDPReg(1, 0x60008000 + (0x0C4 << 2));
  118. _StoreWriteAPDPReg(3, 1);
  119. _StoreWriteAPDPReg(1, 0x60008000 + (0x0C5 << 2));
  120. _StoreTriggerReadAPDPReg(3);
  121. _StoreSelDP();
  122. BitPos = _StoreTriggerReadAPDPReg(3);
  123. v = JTAG_GetU32(BitPos + 3);
  124. _StoreSelAP();
  125. //
  126. // Read & modify DSCR in order to enable debug halt mode
  127. //
  128. _StoreWriteAPDPReg(1, 0x60008000 + (0x22 << 2));
  129. _StoreTriggerReadAPDPReg(3);
  130. _StoreSelDP();
  131. BitPos = _StoreTriggerReadAPDPReg(3);
  132. v = JTAG_GetU32(BitPos + 3);
  133. _StoreSelAP();
  134. v |= (1 << 14);
  135. _StoreWriteAPDPReg(1, 0x60008000 + (0x22 << 2)); // Enable debug halt mode by writing the DSCR
  136. _StoreWriteAPDPReg(3, v);
  137. //
  138. // Halt CPU by writing the halt request bit in the DRCR
  139. //
  140. _StoreWriteAPDPReg(1, 0x60008000 + (0x24 << 2));
  141. _StoreWriteAPDPReg(3, 1);
  142. JTAG_WriteClocks(1);
  143. JTAG_Speed = Speed;
  144. }
  145. /*********************************************************************
  146. *
  147. * InitTarget
  148. */
  149. void InitTarget(void) {
  150. int Speed;
  151. Report("Digi ConnectCore Wi-i.MX51 (Cortex-A8 core) J-Link script");
  152. Speed = JTAG_Speed;
  153. JTAG_Speed = 100;
  154. JTAG_Reset(); // Perform TAP reset and J-Link JTAG auto-detection
  155. if (JTAG_TotalIRLen != 13) {
  156. MessageBox("Can not find Digi ConnectCore Wi-i.MX51 Eval board (Total IRLen mismatch)");
  157. return 1;
  158. }
  159. JTAG_DRPre = 0;
  160. JTAG_DRPost = 2;
  161. JTAG_IRPre = 0;
  162. JTAG_IRPost = 9;
  163. JTAG_IRLen = 4;
  164. CPU=CORTEX_A8;
  165. JTAG_AllowTAPReset=1;
  166. //
  167. // It seems if the linux system has already booted
  168. // We are no longer able to power the debug port.
  169. // So when connecting, we reset the device and halt it as fast as possible, after reset.
  170. //
  171. ResetTarget();
  172. //
  173. // Set IDs of the 3 devices
  174. //
  175. JTAG_SetDeviceId(0, 0x1BA00477);
  176. JTAG_SetDeviceId(1, 0x00000001);
  177. JTAG_SetDeviceId(2, 0x1190C01D);
  178. JTAG_Speed = Speed;
  179. }