To carry out SWO Trace on LPC5410x, it is necessary to:
This should typically be done within each of your application projects (or library projects that your projects link against).
Note : SWO Trace on LPC5410x MCUs can only be carried out for debug sessions connected to the Cortex-M4 CPU, not to the Cortex-M0+.
On LPCXpresso54102 boards, pin P0_15 is connected to SWO of the debug connector.
If you are using a different board, you will need to check the schematics to identify if SWO is connected to the debug connector (and on which pin from the MCU).
The LPCXpresso54102 board is typically shipped with CMSIS-DAP firmware installed into the built-in LPC-Link2 debug probe that does not provide the necessary channels for SWO trace data transfer back to the host debugger. You need to configure your board so that the LPCXpresso IDE can softload "redlink" firmware. This is done by fitting a jumper on JP5, then repowering the board. For more details, please see LPCXpresso Boards|NXP
The startup code generated by the new project wizards for LPC5410x in LPCXpresso IDE v7.7 (and later) contain code to optionally turn on the trace clock. By default this code will be enabled by the new project wizard, but if not required can be removed by defining the compiler symbol DONT_ENABLE_SWVTRACECLK.
If you are using different startup code (for instance, as provided in the projects in the LPCOpen v2.14.1 package for the LPCXpresso5410x board), then you can add the following code to your project to turn on the trace clock (for example right at the start of main() or in the startup file before the call to main() ) :
volatile unsigned int *TRACECLKDIV = (unsigned int *) 0x400000E4;
volatile unsigned int *SYSAHBCLKCTRLSET = (unsigned int *) 0x400000C8;
// Write 0x00000001 to TRACECLKDIV (0x400000E4) – Trace divider
*TRACECLKDIV = 1;
// Enable IOCON peripheral clock (for SWO on PIO0-15 or PIO1_1)
// by setting bit13 via SYSAHBCLKCTRLSET[0] (0x400000C8)
*SYSAHBCLKCTRLSET = 1 << 13; // 0x2000
Note that later versions of the LPCOpen package for LPC5410x should contain appropriate trace clock setup code in the startup file.
On LPCXpresso54102 boards, pin P0_15 is connected to SWO of the debug connector. This needs configuring in the pinmux settings for your project.
If you are using the examples from the LPCOpen v2.14.1 package for the LPCXpresso5410x board, then you need to modify the pinmux settings in board_sysinit.c of the lpc_board_lpcxpresso_54102 library project, so that the SWO settings are not commented out by the #if 0 ... #endif clause (as they are by default). Thus after modifying the code, it should look like:
{0, 15, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* SWO */ #if 0 /* Debugger signals, do not touch */ {0, 16, (IOCON_FUNC5 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* SWCLK_TCK */ {0, 17, (IOCON_FUNC5 | IOCON_MODE_INACT | IOCON_DIGITAL_EN)}, /* SWDIO */ #endif
Note that later versions of the LPCOpen package for LPC5410x should contain appropriate SWO pinmux setup code for the LPCXpresso54102 board in the board library.