/********************************************************************* * Z-Wave ZG23 Embedded Trace Module script * * Initializes and enables the ETM module and drives out the default * * pins. See the code for more details. * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : ZG23_TraceConfig.JLinkScript Purpose : Example script for the Z-Wave EFR32ZG23, EFR32FG23 (and ZGM230?) Literature: [1] J-Link User Guide - https://www.segger.com/downloads/jlink/UM08001 [2] JLinkScript syntax - https://wiki.segger.com/J-Link_script_files#Using_J-Link_script_files */ /********************************************************************* * * OnTraceStart() * * Function description * If present, called right before trace is started. * Used to initialize MCU specific trace related things like configuring the trace pins for alternate function. * * Return value * >= 0: O.K. * < 0: Error * * Notes * (1) May use high-level API functions like JLINK_MEM_ etc. * (2) Should not call JLINK_TARGET_Halt(). Can rely on target being halted when entering this function */ int OnTraceStart(void) { U32 v; U32 PortWidth; // this is passed in from Ozone based on the setup chosen U32 CMU_BASE; U32 CMU_TRACECLKCTRL; U32 CMU_CLKEN0; U32 CMU_TRACEPRESC_SHIFT; U32 CMU_TRACEPRESC_MASK; U32 CMU_CLKEN0GPIO_SHIFT; U32 CMU_CLKEN0GPIO_MASK; U32 GPIO_BASE; U32 GPIO_DBGROUTEPEN; U32 GPIO_TRACEROUTEPEN; U32 GPIO_TRACEROUTEPEN_TRACE_MASK; U32 GPIO_TRACEROUTEPEN_ETMTDATA3PEN; U32 GPIO_TRACEROUTEPEN_ETMTDATA2PEN; U32 GPIO_TRACEROUTEPEN_ETMTDATA1PEN; U32 GPIO_TRACEROUTEPEN_ETMTDATA0PEN; U32 GPIO_TRACEROUTEPEN_ETMTCLKPEN; U32 GPIO_TRACEROUTEPEN_SWVPEN; U32 GPIO_PORT_A; U32 GPIO_MODE_PUSH_PULL; U32 GPIO_Px_BASE; U32 GPIO_Px_CTRL; U32 GPIO_Px_MODEL; U32 GPIO_Px_MODEH; U32 GPIO_Px_DOUT; U32 routepen; U32 tracePortSize; U32 etmPort; U32 etmTCLKPin; U32 etmTD0Pin; U32 etmTD1Pin; U32 etmTD2Pin; U32 etmTD3Pin; U32 _TRACE_presc; JLINK_SYS_Report("Start: Initializing trace pins"); PortWidth = JLINK_TRACE_PortWidth; // Ozone Tools->Trace Settings to choose the number of data pins - 4 pins rarely stalls the CPU JLINK_SYS_Report1("PortWidth: ", PortWidth); /* CMU */ CMU_BASE = 0x50008000; CMU_TRACECLKCTRL = CMU_BASE + 0x080; CMU_CLKEN0 = CMU_BASE + 0x064; CMU_TRACEPRESC_SHIFT = 4; CMU_TRACEPRESC_MASK = 0x3< 1) { routepen |= GPIO_TRACEROUTEPEN_ETMTDATA1PEN; } if (PortWidth > 2) { routepen |= (GPIO_TRACEROUTEPEN_ETMTDATA2PEN | GPIO_TRACEROUTEPEN_ETMTDATA3PEN); } etmPort = GPIO_PORT_A; etmTCLKPin = 4; etmTD0Pin = 3; etmTD1Pin = 5; etmTD2Pin = 6; etmTD3Pin = 7; // Calculating position of port registers GPIO_Px_BASE = GPIO_BASE + ( etmPort * 48 ); GPIO_Px_CTRL = GPIO_Px_BASE + 0x00; GPIO_Px_MODEL = GPIO_Px_BASE + 0x04; GPIO_Px_MODEH = GPIO_Px_BASE + 0x0C; GPIO_Px_DOUT = GPIO_Px_BASE + 0x10; v = JLINK_MEM_ReadU32(GPIO_Px_CTRL); v &= ~(0x70); // AND off the slew rate bits v |= 0x40; // bits 6:4 are the slew rate JLINK_MEM_WriteU32(GPIO_Px_CTRL, v); // set SLEW rate for the port - default is 0x40 - higher number is faster slew rate - 0x70 is fastest but may need several GNDs JLINK_SYS_Report1("GPIO_Px_CTRL: ", JLINK_MEM_ReadU32(GPIO_Px_CTRL)); // // TCLK init // v = JLINK_MEM_ReadU32(GPIO_Px_MODEL); JLINK_SYS_Report1("R_GPIO_Px_MODEL: ", v); v &= ~(0xF << (4 * etmTCLKPin)); // Mask Mode register v |= (GPIO_MODE_PUSH_PULL << (4 * etmTCLKPin)); // Set push pull function mode JLINK_SYS_Report1("W_GPIO_Px_MODEL: ", v); JLINK_MEM_WriteU32(GPIO_Px_MODEL, v); JLINK_SYS_Report1("GPIO_Px_MODEL: ", JLINK_MEM_ReadU32(GPIO_Px_MODEL)); // // TD0 init // v = JLINK_MEM_ReadU32(GPIO_Px_MODEL); v &= ~(0xF << (4 * etmTD0Pin)); // Mask Mode register v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD0Pin)); // Set push pull function mode JLINK_MEM_WriteU32(GPIO_Px_MODEL, v); if (PortWidth > 1) { // // TD1 init // v = JLINK_MEM_ReadU32(GPIO_Px_MODEL); v &= ~(0xF << (4 * etmTD1Pin)); // Mask Mode register v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD1Pin)); // Set push pull function mode JLINK_MEM_WriteU32(GPIO_Px_MODEL, v); } if (PortWidth > 2) { // // TD2 init // v = JLINK_MEM_ReadU32(GPIO_Px_MODEL); v &= ~(0xF << (4 * etmTD2Pin)); // Mask Mode register v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD2Pin)); // Set push pull function mode JLINK_MEM_WriteU32(GPIO_Px_MODEL, v); // // TD3 init // v = JLINK_MEM_ReadU32(GPIO_Px_MODEL); v &= ~(0xF << (4 * etmTD3Pin)); // Mask Mode register v |= (GPIO_MODE_PUSH_PULL << (4 * etmTD3Pin)); // Set push pull function mode JLINK_MEM_WriteU32(GPIO_Px_MODEL, v); } // // TRACEROUTE pin enable // v = JLINK_MEM_ReadU32(GPIO_TRACEROUTEPEN); JLINK_SYS_Report1("R_GPIO_TRACEROUTEPEN: ", v); v &= ~(GPIO_TRACEROUTEPEN_TRACE_MASK << 1); // Mask TRACEROUTEPEN register v |= routepen; // Set TRACEROUTEPEN JLINK_SYS_Report1("W_GPIO_TRACEROUTEPEN: ", v); JLINK_MEM_WriteU32(GPIO_TRACEROUTEPEN, v); JLINK_SYS_Report1("GPIO_TRACEROUTEPEN: ", JLINK_MEM_ReadU32(GPIO_TRACEROUTEPEN)); JLINK_SYS_Report("End: Initializing trace pins"); JLINK_ExecCommand("TRACE_SetEnableStalling = 1"); // enable stalling v=JLINK_MEM_ReadU32(0xE0000E80); // Debugging STALLENA in the ITM JLINK_SYS_Report1("ITM_TCR:",v); v |= 0x20; JLINK_MEM_WriteU32(0xE0000E80, v); v=JLINK_MEM_ReadU32(0xE0000E80); JLINK_SYS_Report1("ITM_TCR:",v); return 0; } /********************************************************************* * * ConfigTargetSettings() * * Function description * Called before InitTarget(). Mainly used to set some global DLL variables to customize the normal connect procedure. * For ARM CoreSight devices this may be specifying the base address of some CoreSight components (ETM, ...) * that cannot be automatically detected by J-Link due to erroneous ROM tables etc. * May also be used to specify the device name in case debugger does not pass it to the DLL. * * Notes * (1) May not, under absolutely NO circumstances, call any API functions that perform target communication. * (2) Should only set some global DLL variables */ int ConfigTargetSettings(void) { JLINK_ExecCommand("CORESIGHT_SetTPIUBaseAddr = 0xE0040000 ForceUnlock = 1"); // TPIU address is missing in ROM table JLINK_SYS_Report("Set TPIU Base Address"); return 0; }