AnsweredAssumed Answered

SWO Trace setup for LPC15xx

Question asked by LPCware Support on Mar 31, 2016

To carry out SWO Trace on LPC15xx, it is necessary to:


  1. Ensure that your board has SWO pinned out to the debug connector
  2. Turn on the trace clock within the MCU, as this is not enabled by default
  3. Configure the switch matrix, so that the SWO signal is accesible on an appropriate pin of the MCU


This should typically be done within each of your application projects (or library projects that your projects link against).


SWO pin and debug connector


The first revisions of the LPCXpresso1549 board did not provide for connecting the SWO pin on the debug connector.  You will need a revision C (or later) of this board to carry out SWO trace.

To identify which revision of board you have, look in the top right of the back of the board which should be marked:

OM13056   v2 Rev C

If you are using a different board, you will need to check the schematics to identify if SWO is connected to the debug connector.


Enabling the trace clock


The startup code generated by the new project wizards for LPC15xx 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.08c package for the LPCXpresso1549 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 *) 0x400740D8; 


Note : later versions of the LPCOpen package for LPC15xx should contain appropriate trace clock setup code within the startup file.


SWO switch matrix configuration


The SWO signal from the Cortex CPU is not assigned to a fixed pin on the LPC15xx MCU. Thus it is necessary to correctly configure the switch matrix.


For example, if you are using LPCOpen v2.08c package for the LPCXpresso1549 board (and have a revision C or later board),  then you will need to modify board_sysinit.c in the lpc_board_nxp_lpcxpresso_1549 project to add SWO to the switch matrix setup thus:

STATIC const SWM_GRP_T swmSetup[] = { 
/* USB related */
{(uint16_t) SWM_USB_VBUS_I, 1, 11}, /* PIO1_11-ISP_1-AIN_CTRL */
/* UART */
{(uint16_t) SWM_UART0_RXD_I, 0, 13}, /* PIO0_13-ISP_RX */
{(uint16_t) SWM_UART0_TXD_O, 0, 18}, /* PIO0_18-ISP_TX */
/* SWO signal */ 
{(uint16_t) SWM_SWO_O, 1, 2}, /* PIO01_2-SWO */ 


Note : later versions of the LPCOpen package for LPC15xx should contain appropriate SWO switch matrix setup code for the LPCXpresso1549 board in the board library.



For more information: