CM41x_M4.JLinkScript 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Reset script for ADSP-CM41x, Cortex-M4 core.
  2. // Copyright (c) 2016 Analog Devices, Inc. All Rights Reserved.
  3. //
  4. // This script is for use with Segger JLink Lite emulators, to
  5. // connect to the Cortex-M4 core of the ADSP-CM41x processor.
  6. //
  7. // When the processor's security is enabled, debugger access is
  8. // disabled until secure keys are provided. If using custom key
  9. // values instead of the default key values, modify the values
  10. // passed by this script.
  11. // Note that there TWO sets of locations to change in this script
  12. // - one for JTAG connections, and one for SWD connections.
  13. int GetScriptVersion(void) {
  14. //
  15. // Make sure that J-Link DLL does not ignore InitTraget() from script file
  16. // Return values for Analog Devices:
  17. // < 100: Perform DLL internal connect sequence
  18. // >= 100: Perform InitTarget() from script file
  19. //
  20. return 100;
  21. }
  22. void ResetTarget(void) {
  23. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe0002008);
  24. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x8001031b); // don't vector flash
  25. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe000200c);
  26. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x800102f7); // don't vector uart
  27. SYS_Sleep(300);
  28. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe0002000);
  29. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x00000007); // enable fpb patch 0+1
  30. SYS_Sleep(300);
  31. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe000ed0c);
  32. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x05fa0004); // reset
  33. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe000edf0);
  34. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0xa05f0001); // enable debug
  35. SYS_Sleep(300);
  36. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0xe000edf0);
  37. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0xa05f0003); // halt
  38. Report("CM41x_M4.JLinkScript-v1.0.0.0: Resetting and halting Cortex-M4 core.");
  39. }
  40. /*********************************************************************
  41. *
  42. * _InitTargetSWD
  43. *
  44. **********************************************************************/
  45. int _InitTargetSWD(void) {
  46. CPU = CORTEX_M4;
  47. JTAG_AllowTAPReset = 0;
  48. // reset the board
  49. Report("CM41x_M4.JLinkScript-v1.0.0.0: SWD connection");
  50. JTAG_ResetPin=0;
  51. SYS_Sleep(300);
  52. JTAG_ResetPin=1;
  53. SYS_Sleep(300);
  54. Report("CM41x_M4.JLinkScript-v1.0.0.0: SWD: send secure keys");
  55. JLINK_CORESIGHT_WriteDP(JLINK_CORESIGHT_DP_REG_CTRL_STAT, 0x50000031); // Set SYSPWRUPREQ and DBGPWRUPREQ and overrun detection
  56. JLINK_CORESIGHT_WriteDP(JLINK_CORESIGHT_DP_REG_SELECT, (0 << 24) | (0 << 4)); // Select AHB-AP bank 0 (data read/write registers)
  57. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_CTRL, 0x23000042);
  58. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0x40017050); // SDBGKEYCOMP0
  59. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x11111111); // Replace 0x11111111 with your value
  60. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0x40017054); // SDBGKEYCOMP1
  61. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x22222222); // Replace 0x22222222 with your value
  62. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0x40017058); // SDBGKEYCOMP2
  63. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x33333333); // Replace 0x33333333 with your value
  64. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_ADDR, 0x4001705c); // SDBGKEYCOMP3
  65. JLINK_CORESIGHT_WriteAP(JLINK_CORESIGHT_AP_REG_DATA, 0x44444444); // Replace 0x44444444 with your value
  66. return 0;
  67. }
  68. /*********************************************************************
  69. *
  70. * _InitTargetJTAG
  71. *
  72. **********************************************************************/
  73. int _InitTargetJTAG(void) {
  74. int TAPCIdCode;
  75. int DPIdCode;
  76. int BitPos;
  77. int TryAgain;
  78. Report("CM41x_M4.JLinkScript-v1.0.0.0: JTAG connection");
  79. TryAgain = 0;
  80. Reconnect:
  81. JTAG_Reset(); // Perform TAP reset and J-Link JTAG auto-detection
  82. if (JTAG_TotalIRLen != 5) {
  83. if (TryAgain == 0) {
  84. //
  85. // Toggle reset and retry the connect sequence
  86. //
  87. Report("CM41x_M4.JLinkScript-v1.0.0.0: ADI TAPC not found (IRLen mismatch). Performing recovery sequence");
  88. JTAG_ResetPin = 0;
  89. SYS_Sleep(300);
  90. JTAG_ResetPin = 1;
  91. SYS_Sleep(300);
  92. TryAgain = 1;
  93. goto Reconnect;
  94. }
  95. Report1("CM41x_M4.JLinkScript-v1.0.0.0: ADI TAPC not found (IRLen mismatch), Found: ", JTAG_TotalIRLen);
  96. return -1;
  97. }
  98. //
  99. // Configure JTAG chain
  100. //
  101. JLINK_CORESIGHT_Configure("IRPre=0;DRPre=0;IRPost=0;DRPost=0;IRLenDevice=5"); // Does not hurt to configure the JTAG chain if SWD is used, as these params are simply not used for SWD
  102. //
  103. // Check TAPC device ID
  104. //
  105. JTAG_WriteIR(0x2); // IDCODE instruction for TAPC device
  106. BitPos = JTAG_WriteDR(0x00000000, 32);
  107. TAPCIdCode = JTAG_GetU32(BitPos);
  108. if ((TAPCIdCode & 0x0FFFFFFF) != 0x0280b0cb) { // Highest nibble holds version information, so it can not be used for verification.
  109. Report1("CM41x_M4.JLinkScript-v1.0.0.0: Can not find TAPC (IDCODE mismatch). Expected 0x0280b0cb, found: ", TAPCIdCode & 0x0FFFFFFF);
  110. return -1;
  111. }
  112. //
  113. // Send 128-bit unlock key to device
  114. //
  115. Report("CM41x_M4.JLinkScript-v1.0.0.0: JTAG: Send secure keys");
  116. JTAG_WriteIR(0xA);
  117. JTAG_StartDR();
  118. JTAG_WriteDRCont(0x11111111, 32); // SDBKEY 0: Replace 0x11111111 with your value
  119. JTAG_WriteDRCont(0x22222222, 32); // SDBKEY 1: Replace 0x22222222 with your value
  120. JTAG_WriteDRCont(0x33333333, 32); // SDBKEY 2: Replace 0x33333333 with your value
  121. JTAG_WriteDREnd(0x44444444, 32); // SDBKEY 3: Replace 0x44444444 with your value
  122. JTAG_WriteClocks(1); // Make sure that we go through Idle state in TAP controller
  123. // set bit 0 in JTAG_CTL
  124. // This adds the M4 and M0 to the chain
  125. // New chain layout:
  126. // #0 M0 (closest to TDO)
  127. // #1 M4
  128. // #2 TAPC
  129. //
  130. JTAG_WriteIR(5);
  131. BitPos = JTAG_WriteDR(0x5, 0x8);
  132. //
  133. // Select M4 TAP to communicate with
  134. // Get DAP-Id
  135. // Set DLL variables for further debugging
  136. //
  137. JTAG_AllowTAPReset = 0;
  138. JLINK_CORESIGHT_Configure("IRPre=4;DRPre=1;IRPost=5;DRPost=1;IRLenDevice=4; PerformTIFInit=0"); // Does not hurt to configure the JTAG chain if SWD is used, as these params are simply not used for SWD
  139. CPU=CORTEX_M4;
  140. Report("CM41x_M4.JLinkScript-v1.0.0.0: starting Cortex-M4 core");
  141. JTAG_WriteIR(0xE);
  142. BitPos = JTAG_WriteDR(0x00000000, 32);
  143. DPIdCode = JTAG_GetU32(BitPos);
  144. if (((DPIdCode & 0xFFFFFFFF) != 0x4BA00477)) {
  145. Report1("CM41x_M4.JLinkScript-v1.0.0.0: Can not find Cortex-M4 (IDCODE mismatch). Expected 0x4BA00477, found: ", DPIdCode);
  146. return -1;
  147. } else {
  148. Report ("CM41x_M4.JLinkScript-v1.0.0.0: Found Cortex-M4");
  149. //
  150. // Set Device Ids (needed by DLL in case JTAG is used)
  151. //
  152. JTAG_SetDeviceId(0, 0x0BA00000); // M0
  153. Report ("CM41x_M4.JLinkScript-v1.0.0.0: set device id 0");
  154. JTAG_SetDeviceId(1, DPIdCode); // M4
  155. Report ("CM41x_M4.JLinkScript-v1.0.0.0: set device id 1");
  156. JTAG_SetDeviceId(2, TAPCIdCode); // TAPC
  157. Report ("CM41x_M4.JLinkScript-v1.0.0.0: set device id 2");
  158. }
  159. return 0;
  160. }
  161. void InitTarget(void) {
  162. int r;
  163. int Speed;
  164. Report("*********************************");
  165. Report("* CM41x_M4.JLinkScript-v1.0.0.0 *");
  166. Report("*********************************");
  167. //
  168. // Remember original target interface speed and set new one
  169. //
  170. Speed = JTAG_Speed;
  171. JTAG_Speed = 0x1000;
  172. //
  173. // Perform target interface specific connect sequence
  174. //
  175. if (MAIN_ActiveTIF == JLINK_TIF_JTAG) {
  176. r = _InitTargetJTAG();
  177. } else {
  178. r = _InitTargetSWD();
  179. }
  180. //
  181. // Restore original target interface speed settings
  182. //
  183. JTAG_Speed = Speed;
  184. return r;
  185. }