The SWD debug interface is a debug interface proposed by ARM. Compared with the traditional JTAG interface, it uses fewer signal pins. The SWD debug interface signal definition is shown in the red line in the figure below:
Some Cortex-M3/M4/M7 chips support SWO Trace function, which have built-in DWT, ITM (Instrument Trace Macrocell) and other units. One of the main uses of ITM is to support information output. In addition, DWT also tracks the entry and exit of interrupts and samples the PC counter.
IAR supports SWO Trace debugging, a powerful debugging function that uses the SWO serial line in the SWD interface to output the trace information generated during debugging. Using SWO debugging requires connecting the SWO pin of the debugger to the SWO of the chip.
This article will briefly introduce several practical functions of SWO Trace debugging.
Hardware requirements for using SWO Trace:
1. The emulator used supports SWD debug interface and SWO serial communication.
2. The chip supports the SWD debug interface. Most mainstream core chips such as M3/M4/M7 support it, and the SWO pin on the chip should be connected to the SWO pin of the hardware debug interface.
Software settings using SWO Trace:
Select the SWD interface to connect in the debugger configuration.
SWO debugging function example:
(1). Use Terminal I/O to print debugging information
The Terminal I/O function provided by IAR can display the information output by the printf statement in the function in the Terminal I/O window. There are two ways to output printf information, semi-host mode and SWO mode. The information output rate is slow in semi-host mode, and when using SWO mode for information output, the speed is very fast, which is suitable when there is a large amount of information to be output. You can check the use of SWO mode in General Options->Library Configuration. The Terminal I/O window is opened from the View menu after entering the debugging environment.
(2). Real-time display of variable value changes
With SWO debugging, you can monitor the value changes of global variables in real time and display them in a graphical way. TestPoint in the figure below is a global variable. Right-click on the variable and select "Data Log" to set a data logging breakpoint.
Open the breakpoint window through the view->breakpoint option, right-click the breakpoint and click the Edit option to edit it, and select to trigger the data recording breakpoint when the variable is overwritten by Write.
Open the Data Log and Timeline windows from the debug menu of the simulator used, such as I-jet, right-click the window and select "Enable", then click "Go" to run the program at full speed. The data log window will display the tracking record of the global variable TestPoint in real time. The displayed data includes information such as timestamp, variable value and variable address.
In the Data Log column of the Timeline window, right-click again and select "Enable" to enable graphical display. You can get the real-time change view of the TestPoint variable value as shown below.
(3). Measure code execution time
Because the information displayed in the Data Log window contains the timestamp when the variable value changes, this can be used to measure the execution time of the function. As shown in the figure below, a global variable TimeStamp is added before and after the sorting function NumberSorting() is executed as a monitoring variable for measuring the running time.
The NumberSorting function modifies the value of the TimeStamp variable before and after execution. The execution time of the function can be calculated based on the change time of the TimeStamp value in the Data Log window. The time taken for TimeStamp to change from 0x05 to 0x0A is:
t = 21576.23 - 20992.01 = 584.22us
From this we can know that the time taken to execute the sorting function NumberSorting() is 584.22us.