Renesas_RZG1M_ConnectCore0.JLinkScript 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ----------------------------------------------------------------------
  12. Purpose :
  13. ---------------------------END-OF-HEADER------------------------------
  14. */
  15. /*********************************************************************
  16. *
  17. * SetupTarget
  18. */
  19. void SetupTarget(void) {
  20. Report("******************************************************");
  21. Report("J-Link script: SetupTarget()");
  22. Report("Power up and enable Core 1");
  23. Report("******************************************************");
  24. MEM_WriteU32(0xE6152010, 0x00000002); // CA15WUPCR: Wake up core 1
  25. MEM_WriteU32(0xE6160040, 0xA5A50003); // CA15RESCNT: Enable core 1
  26. }
  27. /*********************************************************************
  28. *
  29. * ResetTarget
  30. */
  31. void ResetTarget(void) {
  32. int v;
  33. int Speed;
  34. int Ctrl;
  35. Report("******************************************************");
  36. Report("J-Link script: ResetTarget()");
  37. Report("******************************************************");
  38. Speed = JTAG_Speed;
  39. JTAG_Speed = 100;
  40. JTAG_WriteClocks(1);
  41. //
  42. // Select APB-AP and prepare control register
  43. //
  44. JLINK_CORESIGHT_WriteDP(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  45. Ctrl = 0
  46. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  47. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  48. | (1 << 31) // Enable software access to the Debug APB bus.
  49. ;
  50. JLINK_CORESIGHT_WriteAP(0, Ctrl);
  51. //
  52. // Perform some other init steps which are required to get full control of the debug logic
  53. //
  54. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0xFB0);
  55. JLINK_CORESIGHT_WriteAP(3, 0xC5ACCE55);
  56. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0x310);
  57. JLINK_CORESIGHT_WriteAP(3, 1);
  58. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0x314);
  59. JLINK_CORESIGHT_ReadAP(3);
  60. v = JLINK_CORESIGHT_ReadDP(3);
  61. //
  62. // Read & modify DSCR in order to enable debug halt mode
  63. //
  64. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0x88);
  65. JLINK_CORESIGHT_ReadAP(3);
  66. v = JLINK_CORESIGHT_ReadDP(3);
  67. v |= (1 << 14);
  68. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0x88); // Enable debug halt mode by writing the DSCR
  69. JLINK_CORESIGHT_WriteAP(3, v);
  70. //
  71. // Halt CPU by writing the halt request bit in the DRCR
  72. //
  73. JLINK_CORESIGHT_WriteAP(1, 0x800B0000 + 0x90);
  74. JLINK_CORESIGHT_WriteAP(3, 1);
  75. JTAG_WriteClocks(1);
  76. JTAG_Speed = Speed;
  77. }
  78. /*********************************************************************
  79. *
  80. * InitTarget
  81. *
  82. * Notes
  83. * (1) High-level functions like MEM_xxx functions must not be used here.
  84. * They may only be used in SetupTarget() which is called later in the connect process.
  85. */
  86. void InitTarget(void) {
  87. Report("******************************************************");
  88. Report("J-Link script: RZ/G1M (Cortex-A15 CPU0) J-Link script");
  89. Report("******************************************************");
  90. if (MAIN_ActiveTIF == JLINK_TIF_JTAG) {
  91. JLINK_CORESIGHT_Configure("IRPre=0;DRPre=0;IRPost=0;DRPost=0;IRLenDevice=4");
  92. JTAG_AllowTAPReset = 1; // J-Link is allowed to use a TAP reset for JTAG-chain auto-detection
  93. JTAG_SetDeviceId(0, 0x4BA00477); // 4-bits IRLen
  94. } else {
  95. JLINK_CORESIGHT_Configure(""); // Perform SWD init sequence
  96. }
  97. //
  98. // For the RZ/G1M there is 1 JTAG/SWD device
  99. // For Cortex-A devices: Each core has its own set of debug registers in the APB-AP memory map
  100. // To connect to a specific core, just tell J-Link which debug registers to use
  101. // NOTE: The selected core *must* be powered and enabled when leaving this function (InitTarget())
  102. //
  103. // For RZ/G1M:
  104. // 0x800B0000: Debug register Cortex-A15 core0
  105. // 0x800B2000: Debug register Cortex-A15 core1
  106. //
  107. CORESIGHT_CoreBaseAddr = 0x800B0000;
  108. CORESIGHT_AddAP(0, CORESIGHT_CUSTOM_AP);
  109. CORESIGHT_AddAP(1, CORESIGHT_APB_AP);
  110. CORESIGHT_IndexAPBAPToUse = 1;
  111. CPU = CORTEX_A15;
  112. ResetTarget(); // Reset and Halt Core
  113. }