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
- Define SERIAL_PORT_TYPE_SWO in your project settings.
- Prepare code, the port and baudrate can be decided by application, clkSrcFreq should be mcu core clock frequency:
- 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
- Choose project -> "Options" -> "Debugger" -> "J-Link/J-Trace".
- Choose tab "J-Link/J-Trace" -> "Connection" tab -> "SWD".
- Choose tab "General Options" -> "Library Configurations", select Semihosted, select Via SWO.
- 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.
- Open the SWO Trace window from J-LINK,and click the Activate button to enable trace data collection.
- 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.
- Start the project by choosing Project>Download and Debug.
Step 2: Building the project
Step 3: Starting swo
- Download and debug application.
- Choose View -> Terminal I/O to display the output from the I/O operations.
- 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
- 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.
- In menu bar, click Management Run-Time Environment icon, select Compiler, unfold I/O, enable STDERR/STDIN/STDOUT and set the variant to ITM.
- Open Project>Options for target or using Alt+F7 or click.
- Select “Debug” tab, select “J-Link/J-Trace Cortex” and click “Setting button”.
- 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
- Compile and link the project by choosing Project>Build Target or using F7.
Step 4: Run the project
- Choose “Debug” on menu bar or Ctrl F5.
- In menu bar, choose "Serial Window" and click to "Debug (printf) Viewer".
- 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.