Renesas_RZG1M_ConnectCore1.JLinkScript 4.2 KB

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