BCM43907.JLinkScript 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*********************************************************************
  2. * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
  3. * The Embedded Experts *
  4. * www.segger.com *
  5. **********************************************************************
  6. -------------------------- END-OF-HEADER -----------------------------
  7. File : BCM43907.JLinkScript
  8. Purpose : Handle reset for Broadcom BCM43907 series
  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. * Constants (similar to defines)
  17. *
  18. **********************************************************************
  19. */
  20. //
  21. // User-specified constants to be used by PCode
  22. //
  23. __constant U32 _DBG_REG_VCR = 0x007; // Vector Catch Register
  24. __constant U32 _DBG_REG_PRCR = 0x0C4; // Device Power-down and Reset Control Register
  25. __constant U32 _DBG_REG_PRSR = 0x0C5; // Device Power-down and Reset Status Register
  26. __constant U32 _DBG_REG_LOCKACCESS = 0x3EC;
  27. __constant U32 _DBG_REG_LOCKSTATUS = 0x3ED;
  28. __constant U32 _ACTIVATION_KEY = 0xC5ACCE55;
  29. __constant U32 _DBG_REG_DSCR = 0x022; // Debug Status and Control Register
  30. __constant U32 _DBG_REG_DRCR = 0x024; // Debug Run Control Register
  31. /*********************************************************************
  32. *
  33. * ResetTarget
  34. */
  35. void ResetTarget(void) {
  36. int Ctrl;
  37. int v;
  38. int BaseAddr;
  39. BaseAddr = 0x80001000;
  40. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_DP_REG_SELECT, 0, (0 << 24) | (0 << 4)); // Select AP[0], bank 0
  41. Ctrl = 0
  42. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  43. | (0 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  44. | (1 << 31) // Enable software access to the Debug APB bus.
  45. ;
  46. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_CTRL, 1, Ctrl);
  47. //
  48. // Prepare CPU to be halted immediately after reset (vector catch)
  49. //
  50. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_VCR << 2)); // DBG_REG_VCR
  51. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, 1); // Set reset vector catch
  52. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_PRCR << 2)); // DBG_REG_PRCR
  53. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, 1); // Make sure that device is not held in reset
  54. //
  55. // Reset CPU by toggling reset pin
  56. // Wait some time after reset release to give pin some time to get HIGH
  57. // and to give ROM BTL of SAMA5 some time to finish its work and enable debug access
  58. //
  59. JLINK_JTAG_ResetPin = 0;
  60. JLINK_SYS_Sleep(100);
  61. JLINK_JTAG_ResetPin = 1;
  62. JLINK_SYS_Sleep(100);
  63. //
  64. // Check if CPU is halted. If not, halt it.
  65. // Select & setup APB-AP
  66. //
  67. Report("J-Link script: Reset");
  68. JTAG_Write(0x1F, 0, 6); // Perform TAP reset
  69. v = (1 << 1) | (1 << 30) | (1 << 28); // Request power-up on debug and system port, Make sure that sticky overrun bit gets cleared
  70. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_DP_REG_CTRL_STAT, 0, v);
  71. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_DP_REG_SELECT, 0, (0 << 24) | (0 << 4)); // Select AP[0], bank 0
  72. Ctrl = 0
  73. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  74. | (0 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  75. | (1 << 31) // Enable software access to the Debug APB bus.
  76. ;
  77. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_CTRL, 1, Ctrl);
  78. //
  79. // Init debug logic
  80. //
  81. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_LOCKACCESS << 2));
  82. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, _ACTIVATION_KEY); // Unlock access to the debug registers
  83. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_LOCKSTATUS << 2));
  84. v = JLINK_CORESIGHT_ReadAP(JLINK_CORESIGHT_AP_REG_DATA);
  85. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_PRCR << 2));
  86. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, 0x1); // Disable power-down mode
  87. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_PRSR << 2));
  88. v = JLINK_CORESIGHT_ReadAP(JLINK_CORESIGHT_AP_REG_DATA);
  89. //
  90. // Read DSCR to check if CPU is halted and halt it, if necessary
  91. //
  92. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_DSCR << 2));
  93. v = JLINK_CORESIGHT_ReadAP(JLINK_CORESIGHT_AP_REG_DATA);
  94. v = JLINK_CORESIGHT_ReadAP(JLINK_CORESIGHT_AP_REG_DATA);
  95. if ((v & 1) == 0) {
  96. JLINK_SYS_Report("J-Link script: Core did not halt after reset. Halting core...");
  97. v |= (1 << 14);
  98. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_DSCR << 2)); // Enable debug halt mode by writing the DSCR
  99. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, v);
  100. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_DRCR << 2)); // Write DRCR to halt CPU
  101. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, 1);
  102. v = JLINK_CORESIGHT_ReadAP(JLINK_CORESIGHT_AP_REG_DATA); // Write to AP may be delayed until next read/write, so perform a dummy read
  103. }
  104. //
  105. // Clear vector catch
  106. //
  107. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_ADDR, 1, BaseAddr + (_DBG_REG_VCR << 2));
  108. JLINK_CORESIGHT_WriteDAP(JLINK_CORESIGHT_AP_REG_DATA, 1, 0);
  109. Report("J-Link script: Done");
  110. }