How to use the SWO on STM32H7 devices?

Document created by Amel N Employee on Jun 21, 2018Last modified by Amel N Employee on Jun 22, 2018
Version 8Show Document
  • View in full screen mode

The configuration of the SWV needs to be done for each project you use whenever ITM output is required. It will be saved when you close a project or μVision.

There are two main parts to be considered in this setup:

  • Select the Serial Wire Debug Port instead of the JTAG port (step 6 below)
  • Configure the Serial Wire Output (steps 4 and 7)



μVision must not be in debugging mode for these steps. If it is, click on the debugger icon

The menus below will be grayed out if μVision is in debugger mode.

1- Select your project and make sure the correct processor is selected. (Project/Open Project).


2- Open the Debug setup menu. This can be accessed three ways:

  • Click on Flash/Configure Flash Tools and select the Debug tab.
  • Click on Project/Options for target “STM32H743ZI”. Select the Debug tab.
  • Click on Options For Target icon on main μVision toolbar . Select the Debug tab.


The third option is probably the easiest to use, but whichever one you use, Figure 1 opens up:

 Figure 1 : Option for Target

Figure 1 : Option for Target


3- Select ST-Link Debugger


4- The attached file STM32H743xx_swo.ini can be located in the the project directory. It configures the SWV ports.

In the box Initialization File: select the file STM32H743xx_swo.ini as shown in Figure 1. 

You can rename and/or relocate this file if you prefer. It will not hurt if this is enabled for every exercise.


5- Click on Settings to configure the ST-Link. Figure 2 opens up.


 Figure 2 : Target Driver Setup


6- Select the SWJ box and set Port: to SW as shown in Figure 2. This must not be set to JTAG.

SWV operates only through the Serial Wire debug port (SW). Max clock @ 4 MHz is correct.


7- Select the Trace tab and Figure 3 opens up to configure the SWV trace:


 Figure 3 : Trace Setup


8- Important Step: Set the Core Clock to 400 MHz and check the Trace Enable box. Ensure in the ITM Stimulus Ports that at least Port 0 and Port 7..0 are selected. The rest are Don’t Care for this exercise.

9- Click on OK twice. The Serial Wire Viewer Trace is now configured and ready to use !

10- Click on File/Save to save these settings.



  1. When in the debugger mode, if the SWV windows do not update when the program is running and only do when you stop the program execution, make sure View/Periodic Window Update is activated.
  2. If Core Clock is different of 400 MHz, pay attention to set correct divisor value in initialization file (In following example of .ini file, refer to line 16 to calculate the new value and line 17 to set it)


Example of Initialization file:

/* STM32H743_SWO.ini: STM32H743 Debugger Initialization File                  */

FUNC void DebugSetup (void) {



  //SWO current output divisor register
  //This divisor value (0x000000C6) corresponds to 400Mhz
  //To change it, you can use the following rule
  // value = (CPU Freq/2000)-1
  _WWORD(0x5C003010,((_RWORD(0x5C003010) & 0xfffff000) | 0x000000C7));

  //SWO selected pin protocol register
  _WWORD(0x5C0030F0, 0x00000002);

  //Enable ITM input of SWO trace funnel
  _WWORD(0x5C004000, (_RWORD(0x5C004000) | 0x00000001));

  //RCC_AHB4ENR enable GPIOB clock
  _WWORD(0x580244E0, (_RWORD(0x580244E0) | 0x00000002));

  // Configure GPIOB pin 3 as AF
  _WWORD(0x58020400,((_RWORD(0x58020400) & 0xffffff3f) | 0x00000080));

  // Configure GPIOB pin 3 Speed
  _WWORD(0x58020408, (_RWORD(0x58020408) | 0x00000080));

  // Force AF0 for GPIOB pin 3
  _WWORD(0x58020420, (_RWORD(0x58020420) & 0xFFFF0FFF));

DebugSetup();                       // Debugger Setup

FUNC void OnResetExec (void)  {        // executes upon software RESET; Use the function name as is
  DebugSetup();                       // call the initialization function
4 people found this helpful