CogentCSB740Board_OMAP3550.JLinkScript 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. Purpose : J-Link script file for TI AM3517 device.
  13. By default, only the TI ICEPick is in the JTAG chain
  14. which means that we have to add the Cortex-A8 by configuring the ICEPick.
  15. Moreover, the AM3517 also requires to set the DEBGEN signal in order to allow debugging.
  16. ---------------------------END-OF-HEADER------------------------------
  17. */
  18. /*********************************************************************
  19. *
  20. * _StoreSelDP
  21. */
  22. void _StoreSelDP(void) {
  23. JTAG_StoreIR(0xA); // DPACC command
  24. JTAG_StoreClocks(1);
  25. }
  26. /*********************************************************************
  27. *
  28. * _StoreSelAP
  29. */
  30. void _StoreSelAP(void) {
  31. JTAG_StoreIR(0xB); // APACC command
  32. JTAG_StoreClocks(1);
  33. }
  34. /*********************************************************************
  35. *
  36. * _StoreTriggerReadAPDPReg
  37. *
  38. * Function description
  39. * Triggers a read of an AP or DP register. Depends on the previous command (DPACC / APACC)
  40. */
  41. int _StoreTriggerReadAPDPReg(unsigned int RegIndex) {
  42. U32 v;
  43. int BitPos;
  44. //
  45. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  46. //
  47. v = 1; // 1 indicates read access
  48. v |= (RegIndex << 1);
  49. JLINK_JTAG_StartDR();
  50. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  51. v = 0;
  52. JLINK_JTAG_WriteDREnd(v, 32);
  53. JTAG_StoreClocks(8);
  54. return BitPos;
  55. }
  56. /*********************************************************************
  57. *
  58. * _StoreWriteAPDPReg
  59. *
  60. * Function description
  61. * Writes an AP or DP register. Depends on the previous command (DPACC / APACC)
  62. */
  63. int _StoreWriteAPDPReg(unsigned int RegIndex, U32 Data) {
  64. U32 v;
  65. int BitPos;
  66. //
  67. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  68. //
  69. v = 0; // 0 indicates write access
  70. v |= (RegIndex << 1);
  71. JLINK_JTAG_StartDR();
  72. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  73. v = Data;
  74. JLINK_JTAG_WriteDREnd(v, 32);
  75. JTAG_StoreClocks(8);
  76. return BitPos;
  77. }
  78. /*********************************************************************
  79. *
  80. * _InitIcePick
  81. *
  82. * Function description
  83. * Configures the ICEPick so that the CPU core also becomes
  84. * visible in the JTAG chain.
  85. */
  86. void _InitIcePick(void) {
  87. int BitPos;
  88. int v;
  89. int DPIdCode;
  90. int i;
  91. int Speed;
  92. Report("J-Link script: Init ICEPick");
  93. JTAG_Reset(); // Perform TAP reset and J-Link JTAG auto-detection
  94. if (JTAG_TotalIRLen != 14) {
  95. MessageBox("Can not find Cogent CSB740 eval board (IRLen mismatch)");
  96. }
  97. JTAG_DRPre = 1;
  98. JTAG_DRPost = 0;
  99. JTAG_IRPre = 8;
  100. JTAG_IRPost = 0;
  101. JTAG_IRLen = 6;
  102. Speed = JTAG_Speed;
  103. JTAG_Speed = 50;
  104. //
  105. // Check IDCODE of ICEPick (do not confuse with ICEPICKCODE or IDCODE of JTAG-DP)
  106. //
  107. JTAG_WriteIR(4); // IDCODE instruction for ICEPick device
  108. BitPos = JTAG_WriteDR(0x00000000, 32);
  109. v = JTAG_GetU32(BitPos);
  110. if ((v & 0x0FFFFFFF) != 0x0B7AE02F) { // highest nibble holds version information, so it can not be used for verification.
  111. MessageBox1("Can not find ICE-Pick (IDCODE mismatch). Expected 0x0B7AE02F, found: ", v);
  112. return 1;
  113. }
  114. //
  115. // Read ICEPICKCODE
  116. //
  117. JTAG_WriteIR(5);
  118. BitPos = JTAG_WriteDR(0x00000000, 32);
  119. v = JTAG_GetU32(BitPos);
  120. if ((v & 0x0000FFF0) != 0x00001CC0) {
  121. MessageBox("Connected module is not an ICEPick Module (ICEPICKCODE mismatch)");
  122. return 1;
  123. }
  124. //
  125. // Put ARM core in JTAG chain
  126. //
  127. JTAG_WriteIR(7); // CONNECT
  128. JTAG_WriteDR(0x89, 8); // The ICEPick documentation (SPRUE64, 2.6 CONNECT instruction: Accessing the debug connect register). Bit 7 set means: Write debug connect register. We write 0x9 to the debug connect register which is the debug connect key.
  129. JTAG_WriteIR(2); // ROUTER (Accessing the mapped registers)
  130. v = 0
  131. | (1 << 31) // Write mapped register
  132. | (0x23 << 24) // SDTAP3 register
  133. | (1 << 13) // Debug connect
  134. | (1 << 8) // TAP select
  135. | (1 << 3) // Force active
  136. ;
  137. JTAG_WriteDR(v, 32);
  138. JTAG_WriteIR(0x3F); // Bypass
  139. JTAG_WriteClocks(10);
  140. //
  141. // Configure JTAG chain, so J-Link knows to which devices it has to "talk" to.
  142. // CPU core is in scan chain now, so we have to re-configure the JTAG chain settings
  143. //
  144. JTAG_DRPre = 1;
  145. JTAG_DRPost = 1;
  146. JTAG_IRPre = 8;
  147. JTAG_IRPost = 6;
  148. JTAG_IRLen = 4;
  149. CPU=CORTEX_A8;
  150. JTAG_AllowTAPReset=0;
  151. //
  152. // Check core ID
  153. //
  154. JTAG_StoreIR(0xE); // Read JTAG-DP IDCODE register
  155. v = 0;
  156. BitPos = JTAG_StoreDR(v, 32); // Get ID
  157. v = JTAG_GetU32(BitPos);
  158. if (v != 0x0B6D602F) {
  159. MessageBox("Can not find Cortex-A8 (IDCODE mismatch)");
  160. }
  161. //
  162. // Set JTAG Ids for all devices in the JTAG chain
  163. //
  164. JTAG_SetDeviceId(0, 0x00000000); // XLinkx FPGA
  165. JTAG_SetDeviceId(1, 0x0B6D602F); // JTAG-DP
  166. JTAG_SetDeviceId(2, 0x0B7AE02F); // ICEPick
  167. //
  168. // Set DBGEN signal in order to enable invasive debugging
  169. //
  170. _StoreSelDP();
  171. _StoreWriteAPDPReg(1, 0xF0000000); // Write JTAG-DP CTRL/STAT in order to power-up debug port
  172. v = 0
  173. | (1 << 24) // Select AP 1 which is the APB-AP
  174. | (0 << 4) // Select Bank 0
  175. ;
  176. _StoreWriteAPDPReg(2, v); // Write JTAG-DP SELECT register, in order to select the APB-AP. On the OMAP3550 AP[1] is the APB-AP
  177. _StoreSelAP();
  178. _StoreWriteAPDPReg(0, 0x80000012); // Write APB-AP CSW
  179. _StoreWriteAPDPReg(1, 0xD401D030); // Write APB-AP TAR
  180. v = (1 << 13); // Set DBGEN signal
  181. _StoreWriteAPDPReg(3, v); // Write APB-AP DRW
  182. _StoreSelDP();
  183. JTAG_WriteClocks(1); // Make sure all JTAG buffers are cleared
  184. JTAG_Speed = Speed;
  185. }
  186. /*********************************************************************
  187. *
  188. * _SetBP
  189. */
  190. void _SetBP(int DbgRegBaseAddr) {
  191. __int64 Ctrl;
  192. //
  193. // Select & setup APB-AP
  194. //
  195. _StoreSelDP();
  196. _StoreWriteAPDPReg(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  197. _StoreSelAP();
  198. Ctrl = 0
  199. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  200. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  201. | (1 << 31) // Enable software access to the Debug APB bus.
  202. ;
  203. _StoreWriteAPDPReg(0, Ctrl);
  204. //
  205. // Step 1. Disable the breakpoint being set.
  206. //
  207. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  208. _StoreWriteAPDPReg(3, 0x00000000);
  209. //
  210. // Step 2. Write address to the BVR, leaving the bottom 2 bits zero.
  211. //
  212. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x40 << 2));
  213. _StoreWriteAPDPReg(3, 0x00014000);
  214. //
  215. // Step 3. Write the mask and control register to enable the breakpoint.
  216. //
  217. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  218. _StoreWriteAPDPReg(3, 7 | (0xF << 5) | (0 << 20));
  219. JTAG_WriteClocks(1); // Make sure that JTAG buffers are empty and breakpoint is set
  220. }
  221. /*********************************************************************
  222. *
  223. * ResetTarget
  224. */
  225. void ResetTarget(void) {
  226. int DbgRegBaseAddr;
  227. int Speed;
  228. int BitPos;
  229. int Ctrl;
  230. __int64 v;
  231. Report("J-Link script: Reset");
  232. Speed = JTAG_Speed;
  233. JTAG_Speed = 100;
  234. DbgRegBaseAddr = 0x54011000;
  235. //
  236. // Set breakpoint to halt target as fast as possible after reset
  237. //
  238. _SetBP(DbgRegBaseAddr);
  239. //
  240. // Setup JTAG config to "talk" to the ICEPick, so we can use the JTAG API functions
  241. //
  242. JTAG_DRPre = 2;
  243. JTAG_DRPost = 0;
  244. JTAG_IRPre = 12;
  245. JTAG_IRPost = 0;
  246. JTAG_IRLen = 6;
  247. //
  248. // Perform reset via ICEPick system control register, by setting the SysReset bit
  249. //
  250. JTAG_StoreIR(2); // Cmd: ROUTER
  251. v = 0x01000000; // Read SYS_CNTL
  252. JTAG_StoreDR(v, 32); // Send read register command
  253. BitPos = JTAG_StoreDR(v, 32); // Shift out register content
  254. v = JTAG_GetU32(BitPos);
  255. v &= 0x00FFFFFF;
  256. v |= 0x81000001; // Write SYS_CNTL and set SysReset bit
  257. JTAG_StoreDR(v, 32);
  258. JTAG_WriteClocks(10); // The reset needs some time to get active
  259. //
  260. // Setup JTAG config to "talk" to the CPU core again
  261. //
  262. JTAG_DRPre = 1;
  263. JTAG_DRPost = 1;
  264. JTAG_IRPre = 8;
  265. JTAG_IRPost = 6;
  266. JTAG_IRLen = 4;
  267. //
  268. // Check if CPU is halted. If not, halt it.
  269. // Select & setup APB-AP
  270. //
  271. _StoreSelDP();
  272. _StoreWriteAPDPReg(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  273. _StoreSelAP();
  274. Ctrl = 0
  275. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  276. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  277. | (1 << 31) // Enable software access to the Debug APB bus.
  278. ;
  279. _StoreWriteAPDPReg(0, Ctrl);
  280. //
  281. // Read DSCR to check if CPU is halted
  282. //
  283. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x22 << 2));
  284. _StoreTriggerReadAPDPReg(3);
  285. _StoreSelDP();
  286. BitPos = _StoreTriggerReadAPDPReg(3);
  287. v = JTAG_GetU32(BitPos + 3);
  288. _StoreSelAP();
  289. if ((v & 1) == 0) {
  290. //
  291. // If CPU did not halt after reset, halt it
  292. //
  293. Report("J-Link script: Core did not halt after reset. Halting core...");
  294. v |= (1 << 14);
  295. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x22 << 2)); // Enable debug halt mode by writing the DSCR
  296. _StoreWriteAPDPReg(3, v);
  297. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x24 << 2)); // Write DRCR to halt CPU
  298. _StoreWriteAPDPReg(3, 1);
  299. JTAG_WriteClocks(1);
  300. }
  301. //
  302. // Remove breakpoint
  303. //
  304. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  305. _StoreWriteAPDPReg(3, 0);
  306. _StoreSelDP();
  307. JTAG_WriteClocks(1);
  308. JTAG_Speed = Speed;
  309. }
  310. /*********************************************************************
  311. *
  312. * InitEMU
  313. */
  314. void InitEMU(void) {
  315. EMU_ETB_IsPresent = 0;
  316. }
  317. /*********************************************************************
  318. *
  319. * InitTarget
  320. */
  321. void InitTarget(void) {
  322. Report("Cogent CSB740, TI OMAP3530 (Cortex-A8 core) J-Link script");
  323. //
  324. // By performing a TRST reset, we make sure that only the ICEPick module and the XLinkx FPGA are in the scan chain
  325. //
  326. JTAG_TRSTPin = 0;
  327. SYS_Sleep(50);
  328. JTAG_TRSTPin = 1;
  329. SYS_Sleep(50);
  330. JTAG_Write(0x1F, 0, 6);
  331. _InitIcePick();
  332. }