MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Serial wire output is a mechanism for ARM targets to output signal from core through a single pin. Some IDEs also support SWO, such IAR and KEIL, both input and output are supported, see below for details.

Guide SWO for SDK

NOTE: After the setting both "printf" and "PRINTF" are available for debugging, JlinkSWOViewer can be used to capture the output log.

Step 1: Setting up the environment

  1. Define SERIAL_PORT_TYPE_SWO in your project settings.
  2. Prepare code, the port and baudrate can be decided by application, clkSrcFreq should be mcu core clock frequency:
    DbgConsole_Init(instance, baudRate, SERIAL_PORT_TYPE_SWO, clkSrcFreq);
  3. Use PRINTF or printf to print some thing in application.

    Step 2: Building the project

Step 3: Download and run project

Guide SWO for IAR

NOTE: After the setting both "printf" and "scanf" are available for debugging.

Step 1: Setting up the environment

  1. Choose project -> "Options" -> "Debugger" -> "J-Link/J-Trace".
  2. Choose tab "J-Link/J-Trace" -> "Connection" tab -> "SWD".
  3. Choose tab "General Options" -> "Library Configurations", select Semihosted, select Via SWO.
  4. To configure the hardware’s generation of trace data, click the SWO Configuration button available in the SWO Configuration dialog box. ●The value of the CPU clock option must reflect the frequency of the CPU clock speed at which the application executes. Note also that the settings you make are preserved between debug sessions. ●To decrease the amount of transmissions on the communication channel, you can disable the Timestamp option. Alternatively, set a lower rate for PC Sampling or use a higher SWO clock frequency.
  5. Open the SWO Trace window from J-LINK,and click the Activate button to enable trace data collection.
  6. There are three cases for this SDK_DEBUGCONSOLE_UART whether or not defined. a: if use uppercase PRINTF to output log,The SDK_DEBUGCONSOLE_UART defined or not defined will not effect debug function. b: if use lowercase printf to output log and defined SDK_DEBUGCONSOLE_UART to zero,then debug function ok. c: if use lowercase printf to output log and defined SDK_DEBUGCONSOLE_UART to one,then debug function ok.

NOTE: Case a or c only apply at example which enable swo function,the SDK_DEBUGCONSOLE_UART definition in fsl_debug_console.h. For case a and c, Do and not do the above third step will be not affect function.

  1. Start the project by choosing Project>Download and Debug.

    Step 2: Building the project

Step 3: Starting swo

  1. Download and debug application.
  2. Choose View -> Terminal I/O to display the output from the I/O operations.
  3. Run application.

Guide SWO for Keil µVision

NOTE: After the setting both "printf" and "scanf" are available for debugging.

Step 1: Setting up the environment

  1. There are three cases for this SDK_DEBUGCONSOLE_UART whether or not defined. a: if use uppercase PRINTF to output log,the SDK_DEBUGCONSOLE_UART definition does not affect the functionality and skip the second step directly. b: if use lowercase printf to output log and defined SDK_DEBUGCONSOLE_UART to zero,then start the second step. c: if use lowercase printf to output log and defined SDK_DEBUGCONSOLE_UART to one,then skip the second step directly.

NOTE: Case a or c only apply at example which enable swo function,the SDK_DEBUGCONSOLE_UART definition in fsl_debug_console.h.

  1. In menu bar, click Management Run-Time Environment icon, select Compiler, unfold I/O, enable STDERR/STDIN/STDOUT and set the variant to ITM.
  2. Open Project>Options for target or using Alt+F7 or click.
  3. Select “Debug” tab, select “J-Link/J-Trace Cortex” and click “Setting button”.
  4. Select “Debug” tab and choose Port:SW, then select "Trace" tab, choose "Enable" and click OK, please make sure the Core clock is set correctly, enable autodetect max SWO clk, enable ITM Stimulus Ports 0.

Step 3: Building the project

  1. Compile and link the project by choosing Project>Build Target or using F7.

Step 4: Run the project

  1. Choose “Debug” on menu bar or Ctrl F5.
  2. In menu bar, choose "Serial Window" and click to "Debug (printf) Viewer".
  3. Run line by line to see result in Console Window.

Guide SWO for MCUXpresso IDE

NOTE: MCUX support SWO for LPC-Link2 debug probe only.

Guide SWO for ARMGCC

NOTE: ARMGCC has no library support SWO.