How To Use SWV Function in STM32CubeIDE

Follow+Star Public Account, don’t miss the exciting content

How To Use SWV Function in STM32CubeIDE

Source | STM32 Microcontroller

Many tools come with the SWV (Serial Wire Viewer) function. The previous article titled Print Output Tutorial described how to implement the “SWV” function in tools like Keil, IAR, ST-LINK Utility, STM32CubeProg, J-Link, etc. Today, I will share with you the SWV function of STM32CubeIDE.How To Use SWV Function in STM32CubeIDE

Step 1: Enable the SWO function in the Pinout & Configuration options. This step is mandatory.

How To Use SWV Function in STM32CubeIDEEnabling SWO function in STM32CubeIDEHow To Use SWV Function in STM32CubeIDE

Step 2: Relocate the printf interface function.

Here is a simple method: directly modify the content of the _write() function in the syscalls.c file, as shown in the code below. Also, include the header file core_cmX.h that implements ITM_SendChar in this file. This file is usually already included in the header file of the device model you choose.Here we choose stm32g431xx.h, and it can be placed at the beginning of this file.How To Use SWV Function in STM32CubeIDEHow To Use SWV Function in STM32CubeIDE

Step 3: Include the stdio.h header file in the main.c file and try to print using printf. Note that printing cannot be too frequent, so a delay is needed.

How To Use SWV Function in STM32CubeIDECompile globally and check for errors. If there are errors, please modify according to the prompt information. After compiling without errors, we can proceed to the next step.How To Use SWV Function in STM32CubeIDEHow To Use SWV Function in STM32CubeIDE

Step 4: Configure the simulation debugging parameters. Open the SWV debugging function. Note that the Core Clock must match the clock you configured. I configured it to 170MHz, which is consistent with my system clock.

How To Use SWV Function in STM32CubeIDEHow To Use SWV Function in STM32CubeIDE

Step 5: Start entering the debugging interface, and in the debugging interface, open Windows–>Show; View–>SWV ITM Data Console window. Note that the entire SWV actually shares a configuration file, so you can configure SWV by opening any window within SWV. Here we only want to view the content of Printf, so we chose the SWV ITM Data Console window. For detailed explanations of other parts here, refer to section 4.3 of UM2609.

How To Use SWV Function in STM32CubeIDE

Open SWV ITM Data Window

After opening this window, you need to add a Port. The default port used in TIM is port 0, so we can select 0 directly.How To Use SWV Function in STM32CubeIDE

Add Output Port

Select the configuration button to configure the parameters. The configuration is as follows:How To Use SWV Function in STM32CubeIDE

SWV Window Configuration Interface

It is recommended to reset the project first (optional), then “Start Trace/start trace”. Note: here, you should start tracing first, and then let the program run; it cannot be in reverse order.How To Use SWV Function in STM32CubeIDE

Start Trace and Begin Running

At this point, you will be able to see the printed content.How To Use SWV Function in STM32CubeIDE

Final Print Output Status

———— END ————

How To Use SWV Function in STM32CubeIDE

● Column “Embedded Tools”

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from Embedded Column

Follow the public account and reply “Add Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

How To Use SWV Function in STM32CubeIDE

How To Use SWV Function in STM32CubeIDE

Click “Read the Original Text” to see more shares.

Leave a Comment