TI_CC3200.JLinkScript 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*********************************************************************
  2. * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
  3. * The Embedded Experts *
  4. * www.segger.com *
  5. **********************************************************************
  6. -------------------------- END-OF-HEADER -----------------------------
  7. File : TI_CC3200.JLinkScript
  8. Purpose : J-Link script file for TI CC3200 support
  9. Literature:
  10. [1] J-Link User Guide
  11. Additional information:
  12. For more information about public functions that can be implemented in order to customize J-Link actions, please refer to [1]
  13. */
  14. /*********************************************************************
  15. *
  16. * ResetTarget
  17. *
  18. * Notes
  19. * (1) DLL expects target CPU to be halted / in debug mode, when leaving this function
  20. * (2) May use MEM_ API functions
  21. */
  22. void ResetTarget(void) {
  23. //
  24. // Standard Cortex-M reset + vector catch does not work for this device
  25. // as ROM BTL needs to run after reset but CPU needs to be halted before it can execute the first instruction of the user application, a custom reset is necessary
  26. // As J-Link does not know what is loaded from SPI flash after reset (it may have been reprogrammed in the current session, before reset is issued)
  27. // we do not know the application entry point the ROM BTL jumps to
  28. // Therefore the reset needs to be customized and adapted to the appropriate target application
  29. //
  30. // As default reset does not work for this device, we do not perform any reset for know
  31. //
  32. }
  33. /*********************************************************************
  34. *
  35. * _ICEPick_AddTAP
  36. */
  37. void _ICEPick_AddTAP(int SDTRReg) {
  38. int v;
  39. int TAPRegVal;
  40. int _ICEPICK_IR_BYPASS;
  41. int _ICEPICK_IR_ROUTER;
  42. int _ICEPICK_IR_IDCODE;
  43. int _ICEPICK_IR_CONNECT;
  44. int _ICEPICK_IR_USERCODE;
  45. int _ICEPICK_CONNECT_WRITE_KEY;
  46. int _ICEPICK_ROUTER_WRITE_REG;
  47. int _ICEPICK_BLOCKSEL_SDTR;
  48. //
  49. // Setup constants
  50. //
  51. _ICEPICK_IR_BYPASS = 0x3F;
  52. _ICEPICK_IR_ROUTER = 0x02;
  53. _ICEPICK_IR_IDCODE = 0x04;
  54. _ICEPICK_IR_CONNECT = 0x07;
  55. _ICEPICK_CONNECT_WRITE_KEY = 0x89;
  56. _ICEPICK_ROUTER_WRITE_REG = 1;
  57. _ICEPICK_BLOCKSEL_SDTR = 2;
  58. //
  59. // Add TAP to ICEPick
  60. //
  61. JTAG_StoreIR(_ICEPICK_IR_CONNECT);
  62. v = _ICEPICK_CONNECT_WRITE_KEY;
  63. JTAG_StoreDR(v, 8); // Put ICEPick module into connected state
  64. JTAG_StoreIR(_ICEPICK_IR_ROUTER);
  65. TAPRegVal = 0
  66. | (1 << 3) // ForceActive: Enable clock to TAP if currently not powered.
  67. | (0 << 8) // SelectTAP: 1: TAP is added to JTAG chain once Run-Test-Idle is entered
  68. | (0 << 14) // ResetControl: Override the application controls of the functional warm reset to a module (0: Normal operation, 1: Wait in reset)
  69. | (1 << 17) // ReleaseFromWIR: 1: Releases module from reset if currently held in reset
  70. | (1 << 20) // InhibitSleep: 1: Clock and power to TAP is not turned off in case of low power requests
  71. ;
  72. v = (_ICEPICK_ROUTER_WRITE_REG << 31) | (_ICEPICK_BLOCKSEL_SDTR << 28) | (SDTRReg << 24) | (TAPRegVal << 0);
  73. JTAG_StoreDR(v, 32);
  74. TAPRegVal = 0
  75. | (1 << 3) // ForceActive: Enable clock to TAP if currently not powered.
  76. | (1 << 8) // SelectTAP: 1: TAP is added to JTAG chain once Run-Test-Idle is entered
  77. | (1 << 13) // Enable debug logic
  78. | (0 << 14) // ResetControl: Override the application controls of the functional warm reset to a module (0: Normal operation, 1: Wait in reset)
  79. | (1 << 17) // ReleaseFromWIR: 1: Releases module from reset if currently held in reset
  80. | (1 << 20) // InhibitSleep: 1: Clock and power to TAP is not turned off in case of low power requests
  81. ;
  82. v = (_ICEPICK_ROUTER_WRITE_REG << 31) | (_ICEPICK_BLOCKSEL_SDTR << 28) | (SDTRReg << 24) | (TAPRegVal << 0);
  83. JTAG_StoreDR(v, 32);
  84. JTAG_StoreIR(_ICEPICK_IR_BYPASS);
  85. JTAG_WriteClocks(10); // Necessary according to ICEPick documentation to give the target some time to reconfigure the JTAG chain
  86. }
  87. /*********************************************************************
  88. *
  89. * _InitICEPick
  90. */
  91. int _InitICEPick(void) {
  92. int ICEPickId;
  93. int DAPId;
  94. int Speed;
  95. int Result;
  96. int BitPos;
  97. int _ICEPICK_IR_BYPASS;
  98. int _ICEPICK_IR_ROUTER;
  99. int _ICEPICK_IR_IDCODE;
  100. int _ICEPICK_IR_CONNECT;
  101. int _ICEPICK_CONNECT_WRITE_KEY;
  102. int _ICEPICK_ROUTER_WRITE_REG;
  103. int _ICEPICK_BLOCKSEL_SDTR;
  104. int _ICEPICK_SDTR0;
  105. int _DAP_IR_IDCODE;
  106. _ICEPICK_SDTR0 = 0;
  107. _DAP_IR_IDCODE = 0xE;
  108. //
  109. // ICEPick does not seem to like high JTAG speeds during the init...
  110. // so reduce the JTAG speed
  111. //
  112. Result = 0;
  113. Speed = JTAG_Speed;
  114. JTAG_Speed = 100;
  115. //
  116. // Perform a TAP reset to make sure that only the ICEPick is in the JTAG chain
  117. //
  118. JTAG_Write(0x1F, 0, 6);
  119. //
  120. // Basic configuration of the JTAG chain to enable use of high-level JTAG API
  121. // JTAG Device #0 is the TAP closest to TDO
  122. // JTAG chain: TDI -> ICEPick (IR6) -> -> TDO
  123. //
  124. JTAG_DRPre = 0;
  125. JTAG_DRPost = 0;
  126. JTAG_IRPre = 0;
  127. JTAG_IRPost = 0;
  128. JTAG_IRLen = 6;
  129. JTAG_StoreIR(_ICEPICK_IR_IDCODE);
  130. BitPos = JTAG_StoreDR(0x00000000, 32);
  131. ICEPickId = JTAG_GetU32(BitPos);
  132. Report1("ICEPick IDCODE: ", ICEPickId);
  133. //
  134. // Put the CPU core TAP (SDTR0) in the JTAG chain
  135. //
  136. _ICEPick_AddTAP(_ICEPICK_SDTR0);
  137. //
  138. // Re-configure JTAG chain as DAP is now in the chain, too
  139. // JTAG Device #0 is the TAP closest to TDO
  140. // JTAG chain: TDI -> ICEPick (IR6) -> CoreSight-DAP (IR4) -> TDO
  141. //
  142. JTAG_DRPre = 0;
  143. JTAG_DRPost = 1;
  144. JTAG_IRPre = 0;
  145. JTAG_IRPost = 6;
  146. JTAG_IRLen = 4;
  147. //
  148. // Get Id of DAP
  149. //
  150. JTAG_StoreIR(_DAP_IR_IDCODE);
  151. BitPos = JTAG_StoreDR(0x00000000, 32);
  152. DAPId = JTAG_GetU32(BitPos);
  153. if ((DAPId & 0x00000FFF) != 0x00000477) {
  154. Report1("Cannot read DAP IDCODE. Expected 0xXXXXX477, read: ", DAPId);
  155. Result = -1;
  156. }
  157. //
  158. // Set TAP-Ids of devices in the JTAG chain
  159. //
  160. JLINK_JTAG_SetDeviceId(0, DAPId);
  161. JLINK_JTAG_SetDeviceId(1, ICEPickId);
  162. //
  163. // Restore JTAG speed settings
  164. //
  165. JTAG_Speed = Speed;
  166. return Result;
  167. }
  168. /*********************************************************************
  169. *
  170. * InitTarget()
  171. *
  172. * Function description
  173. * If present, called right before performing generic connect sequence.
  174. * Usually used for targets which need a special connect sequence.
  175. * E.g.: TI devices with ICEPick TAP on them where core TAP needs to be enabled via specific ICEPick sequences first
  176. *
  177. * Return value
  178. * >= 0: O.K.
  179. * < 0: Error
  180. *
  181. * Notes
  182. * (1) Must not use high-level API functions like JLINK_MEM_ etc.
  183. * (2) For target interface JTAG, this device has to setup the JTAG chain + JTAG TAP Ids.
  184. */
  185. void InitTarget(void) {
  186. int r;
  187. //
  188. // The TI CC3200 supports JTAG only because the ICEPick on it only supports JTAG
  189. //
  190. r = -1;
  191. if (JLINK_ActiveTIF == JLINK_TIF_JTAG) {
  192. r = _InitICEPick();
  193. } else if (JLINK_ActiveTIF == JLINK_TIF_SWD) {
  194. r = 0;
  195. }
  196. //
  197. // Set other global variables needed by the DLL
  198. //
  199. JLINK_CPU = CORTEX_M4; // For a complete list of known CPU constants, please refer to UM08001 (J-Link User Guide)
  200. JLINK_CORESIGHT_AddAP(0, CORESIGHT_AHB_AP); // AHB-AP to System Bus
  201. JLINK_CORESIGHT_IndexAHBAPToUse = 0; // Cortex-M: AP-Index of AHB-AP to use for communication with core. Cortex-A/R: AP-Index of AHB-AP that can be used for SEGGER RTT
  202. JLINK_JTAG_AllowTAPReset = 0; // J-Link must not use TAP reset (avoid TAP state machine going reset state) as this would reset the ICEPick and kick the Cortex-M4 core out of the JTAG chain
  203. if (r < 0) {
  204. Report("ERROR: Cannot connect to target device");
  205. }
  206. }