|
1 | 1 | __constant U32 _CPUCONF_ADDR = 0x52011000;
|
2 | 2 | __constant U32 _CPUCONF_CPUWAIT_OFFSET = 0x50C;
|
3 | 3 |
|
| 4 | +// ATBFUNNEL |
| 5 | +__constant U32 _ATBFUNNEL211_ADDR = 0xBF04D000; |
| 6 | +__constant U32 _ATBFUNNEL212_ADDR = 0xBF04E000; |
| 7 | +__constant U32 _ATBFUNNEL_CTRLREG_OFFSET = 0x0; |
| 8 | +__constant U32 _HOLDTIME_4 = 0x300; |
| 9 | +__constant U32 _ENS0 = 0x1; |
| 10 | +__constant U32 _ENS1 = 0x2; |
| 11 | +__constant U32 _ENS2 = 0x4; |
| 12 | + |
| 13 | +// ATBREPLICATOR |
| 14 | +__constant U32 _ATBREPLICATOR212_ADDR = 0xBF04A000; |
| 15 | +__constant U32 _ATBREPLICATOR213_ADDR = 0xBF04B000; |
| 16 | +__constant U32 _ATBREPLICATOR_IDFILTER0_OFFSET = 0x0; |
| 17 | +__constant U32 _ATBREPLICATOR_IDFILTER1_OFFSET = 0x4; |
| 18 | +__constant U32 _ID_NONE = 0xFFFFFFFF; |
| 19 | +__constant U32 _ID1x = 0xFFFFFFFD; |
| 20 | + |
| 21 | +// TSGEN |
| 22 | +__constant U32 _TSGEN_ADDR = 0xBF041000; |
| 23 | +__constant U32 _TSGEN_CNTCR_OFFSET = 0x0; |
| 24 | +__constant U32 _TSGEN_CNTFID0_OFFSET = 0x20; |
| 25 | +// Clock rate = TDD Freq. / 8 |
| 26 | +__constant U32 _TS_CLOCKRATE = 40000000; |
| 27 | + |
| 28 | +// CTI |
| 29 | +__constant U32 _CTI210_ADDR = 0xBF046000; |
| 30 | +__constant U32 _CTICONTROL_OFFSET = 0x0; |
| 31 | +__constant U32 _CTIOUTEN_OFFSET = 0xA0; |
| 32 | +__constant U32 _CTIGATE_OFFSET = 0x140; |
| 33 | +__constant U32 _TPIU_FLUSH_TRIG = 0x2; |
| 34 | + |
| 35 | +// TPIU |
| 36 | +__constant U32 _TPIU_ADDR = 0xBF043000; |
| 37 | +__constant U32 _CURRENTPORTSIZE_OFFSET = 0x4; |
| 38 | +__constant U32 _FFCR_OFFSET = 0x304; |
| 39 | +__constant U32 _FSCR_OFFSET = 0x308; |
| 40 | +__constant U32 _ENFCONT = 0x02; |
| 41 | +__constant U32 _FONFLIN = 0x10; |
| 42 | +__constant U32 _ENFTC = 0x1; |
| 43 | +__constant U32 _TPIU_SYNC_FRAME_COUNT = 0x8; |
| 44 | +__constant U32 _CURRENTPORTSIZE_4 = 0x8; |
| 45 | + |
| 46 | +// TDDCONF |
| 47 | +__constant U32 _TDDCONF_ADDR = 0xBF001000; |
| 48 | +__constant U32 _TRACEPORTSPEED_OFFSET = 0x408; |
| 49 | +__constant U32 _SPEED80MHZ = 0x0; |
| 50 | + |
| 51 | +// CoreSight general |
| 52 | +__constant U32 _CORESIGHT_CLAIMSET_OFFSET = 0xFA0; |
| 53 | +__constant U32 _CORESIGHT_CLAIMCLR_OFFSET = 0xFA4; |
| 54 | +__constant U32 _CORESIGHT_LAR_OFFSET = 0xFB0; |
| 55 | +__constant U32 _CORESIGHT_UNLOCK_KEY = 0xC5ACCE55; |
| 56 | + |
| 57 | +// GPIO P7 |
| 58 | +__constant U32 _P7_ADDR = 0x5F938E00; |
| 59 | +__constant U32 _PIN_CNF3_OFFSET = 0x8C; |
| 60 | +__constant U32 _PIN_CNF4_OFFSET = 0x90; |
| 61 | +__constant U32 _PIN_CNF5_OFFSET = 0x94; |
| 62 | +__constant U32 _PIN_CNF6_OFFSET = 0x98; |
| 63 | +__constant U32 _PIN_CNF7_OFFSET = 0x9C; |
| 64 | +__constant U32 _PIN_CNF_TPIU_CLOCK_VALUE = 0x80000503; |
| 65 | +__constant U32 _PIN_CNF_TPIU_DATA_VALUE = 0x00000502; |
| 66 | + |
| 67 | +// Settings |
| 68 | +__constant U32 _DEBUGGER_CLAIM_MASK = 0x2; |
| 69 | + |
| 70 | +// Used to check if we have already set up tracing |
| 71 | +int _needCoresightSetup = 1; |
| 72 | + |
| 73 | +// Unlock a CoreSight peripheral |
| 74 | +void _CSUnlock(U32 addr) |
| 75 | +{ |
| 76 | + JLINK_MEM_WriteU32(addr + _CORESIGHT_LAR_OFFSET, _CORESIGHT_UNLOCK_KEY); |
| 77 | +} |
| 78 | + |
| 79 | +// Lock a CoreSight peripheral |
| 80 | +void _CSLock(U32 addr) |
| 81 | +{ |
| 82 | + JLINK_MEM_WriteU32(addr + _CORESIGHT_LAR_OFFSET, 0); |
| 83 | +} |
| 84 | + |
| 85 | +// Set claim bits in the CoreSight peripheral to indicate to the firmware that it |
| 86 | +// has been configured by the host debugger |
| 87 | +void _CSClaim(U32 addr) |
| 88 | +{ |
| 89 | + JLINK_MEM_WriteU32(addr + _CORESIGHT_CLAIMSET_OFFSET, _DEBUGGER_CLAIM_MASK); |
| 90 | +} |
| 91 | + |
| 92 | +// Set up CoreSight and other necessary configuration so to enable ETM -> TPIU tracing. |
| 93 | +int _SetupETMTPIUTrace(void) |
| 94 | +{ |
| 95 | + // Set up ATB funnels/replicators to route ApplicationDomain ETM to TPIU |
| 96 | + _CSUnlock(_ATBFUNNEL212_ADDR); |
| 97 | + JLINK_MEM_WriteU32(_ATBFUNNEL212_ADDR + _ATBFUNNEL_CTRLREG_OFFSET, _HOLDTIME_4 | _ENS0); |
| 98 | + _CSClaim(_ATBFUNNEL212_ADDR); |
| 99 | + _CSLock(_ATBFUNNEL212_ADDR); |
| 100 | + |
| 101 | + _CSUnlock(_ATBREPLICATOR212_ADDR); |
| 102 | + JLINK_MEM_WriteU32(_ATBREPLICATOR212_ADDR + _ATBREPLICATOR_IDFILTER0_OFFSET, _ID_NONE); |
| 103 | + JLINK_MEM_WriteU32(_ATBREPLICATOR212_ADDR + _ATBREPLICATOR_IDFILTER1_OFFSET, _ID1x); |
| 104 | + _CSLock(_ATBREPLICATOR212_ADDR); |
| 105 | + _CSClaim(_ATBREPLICATOR212_ADDR); |
| 106 | + _CSLock(_ATBREPLICATOR212_ADDR); |
| 107 | + |
| 108 | + _CSUnlock(_ATBFUNNEL211_ADDR); |
| 109 | + JLINK_MEM_WriteU32(_ATBFUNNEL211_ADDR + _ATBFUNNEL_CTRLREG_OFFSET, _HOLDTIME_4 | _ENS0); |
| 110 | + _CSClaim(_ATBFUNNEL211_ADDR); |
| 111 | + _CSLock(_ATBFUNNEL211_ADDR); |
| 112 | + |
| 113 | + _CSUnlock(_ATBREPLICATOR213_ADDR); |
| 114 | + JLINK_MEM_WriteU32(_ATBREPLICATOR213_ADDR + _ATBREPLICATOR_IDFILTER0_OFFSET, _ID1x); |
| 115 | + JLINK_MEM_WriteU32(_ATBREPLICATOR213_ADDR + _ATBREPLICATOR_IDFILTER1_OFFSET, _ID_NONE); |
| 116 | + _CSClaim(_ATBREPLICATOR213_ADDR); |
| 117 | + _CSLock(_ATBREPLICATOR213_ADDR); |
| 118 | + |
| 119 | + // Configure timestamp generator for the correct clock rate |
| 120 | + JLINK_MEM_WriteU32(_TSGEN_ADDR + _TSGEN_CNTFID0_OFFSET, _TS_CLOCKRATE); |
| 121 | + JLINK_MEM_WriteU32(_TSGEN_ADDR + _TSGEN_CNTCR_OFFSET, 1); |
| 122 | + _CSClaim(_TSGEN_ADDR); |
| 123 | + |
| 124 | + // Configure CTI1 for TPIU formatter flushing |
| 125 | + _CSUnlock(_CTI210_ADDR); |
| 126 | + JLINK_MEM_WriteU32(_CTI210_ADDR + _CTIOUTEN_OFFSET, _TPIU_FLUSH_TRIG); |
| 127 | + JLINK_MEM_WriteU32(_CTI210_ADDR + _CTIGATE_OFFSET, _TPIU_FLUSH_TRIG); |
| 128 | + JLINK_MEM_WriteU32(_CTI210_ADDR + _CTICONTROL_OFFSET, 1); |
| 129 | + _CSClaim(_CTI210_ADDR); |
| 130 | + _CSLock(_CTI210_ADDR); |
| 131 | + |
| 132 | + // Configure TPIU for port size 4, continuous formatting |
| 133 | + _CSUnlock(_TPIU_ADDR); |
| 134 | + JLINK_MEM_WriteU32(_TPIU_ADDR + _CURRENTPORTSIZE_OFFSET, _CURRENTPORTSIZE_4); |
| 135 | + JLINK_MEM_WriteU32(_TPIU_ADDR + _FFCR_OFFSET, _ENFCONT | _FONFLIN | _ENFTC); |
| 136 | + JLINK_MEM_WriteU32(_TPIU_ADDR + _FSCR_OFFSET, _TPIU_SYNC_FRAME_COUNT); |
| 137 | + _CSClaim(_TPIU_ADDR); |
| 138 | + _CSLock(_TPIU_ADDR); |
| 139 | + |
| 140 | + // Configure the trace pins |
| 141 | + JLINK_MEM_WriteU32(_P7_ADDR + _PIN_CNF3_OFFSET, _PIN_CNF_TPIU_CLOCK_VALUE); |
| 142 | + JLINK_MEM_WriteU32(_P7_ADDR + _PIN_CNF4_OFFSET, _PIN_CNF_TPIU_DATA_VALUE); |
| 143 | + JLINK_MEM_WriteU32(_P7_ADDR + _PIN_CNF5_OFFSET, _PIN_CNF_TPIU_DATA_VALUE); |
| 144 | + JLINK_MEM_WriteU32(_P7_ADDR + _PIN_CNF6_OFFSET, _PIN_CNF_TPIU_DATA_VALUE); |
| 145 | + JLINK_MEM_WriteU32(_P7_ADDR + _PIN_CNF7_OFFSET, _PIN_CNF_TPIU_DATA_VALUE); |
| 146 | + |
| 147 | + return 0; |
| 148 | +} |
| 149 | + |
| 150 | +int ConfigTargetSettings(void) |
| 151 | +{ |
| 152 | + JLINK_ExecCommand("CORESIGHT_AddAP = Index=0 Type=AHB-AP"); |
| 153 | + CORESIGHT_IndexAHBAPToUse = 0; |
| 154 | + |
| 155 | + // Adjust trace sample delay to compensate for timing when using 320MHz |
| 156 | + JLINK_ExecCommand("TraceSampleAdjust TD = 1000"); |
| 157 | + |
| 158 | + return 0; |
| 159 | +} |
| 160 | + |
| 161 | +int OnTraceStart(void) |
| 162 | +{ |
| 163 | + // Set up CoreSight if not already configured |
| 164 | + if (_needCoresightSetup) { |
| 165 | + _SetupETMTPIUTrace(); |
| 166 | + _needCoresightSetup = 0; |
| 167 | + } |
| 168 | + |
| 169 | + return 0; |
| 170 | +} |
| 171 | + |
| 172 | + |
4 | 173 | int SetupTarget(void)
|
5 | 174 | {
|
6 | 175 | JLINK_TARGET_Halt();
|
|
0 commit comments