Guest User

am335x.JLinkScript

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