Using SWD and SWV with STM32 uControllers – Printf and Logic Analyzer into Debbug Mode

In this post I will talk about SWV. How to set up SWV function and how to use printf and logic analyzer.

This week a friend send me a video[1] where a guy uses printf directly inside uVision debugger without VPC or UART. This is called SWV(serial wire viwer),  a real-time trace technology that uses SWD(serial wire debug) port and the SWO(serial wire output) pin. Serial Wire Viewer provides advanced system analysis and real-time tracing without the need to halt the processor to extract certain types of debug information. You can read more in [2][3]. Besides the printf, what caught my attention was the logic analyzer built in the SWV debugger[4].

Figure 1. Logic Analyzer View

If you use printf to debug your code you can choose between SWV, UART and VPC. SWV just needs the SWO pin(PB3), UART needs 3 pins(TX,RX,GND), and VPC needs 2 pins(USB_DP, USB_DM). Using SWV will save some pins to your application.  

I am currently working with the Blue Pill Dev. Board (figure 2), it has a STM32F103 (Cortex-M3 core) uController[9]. I tested SWV on this board and nothing happened. After click on Run in the debugger session the  only message was  “Trace: No Synchronization”. I found a lot of things about SWV but nothing helped in this time.

Figure 2. Blue Pill – STM32F103C8T6 Dev. Board

After some time I gave up and tried on the MCBSTM32 Dev. Kit (picture 2). This board has a STM32F103RBT6 microcontroller a use a ULINK-ME debugger. SWV worked great with this board with no problem.

Figure 3. MCBSTM32 Keil Dev. Kit

I decided to use the STM32F429I-DISC1 to test SWV, and nothing happend too. This time was easy to find the problem. The STM32F429I-DISC1 has a STM32F429ZIT6U microcontroller and has a ST-LINK V2 debugger built-in the board. The ST-LINK comes by default without the connection between pin PB3 of the microcontroller and SWO of the debugger. To fix this the Solder Bridge SB9 must be shorted in order for SWV to operate. You can see the solder bridge in the figures below and know more about this in the datasheets[5][6].

Figure 4. STM32F429I-DISC1 Eval. Kit
Figure 5. STM32F429I-DISC1 Eletrical Schematic of SWD


Figure 6. Back of STM32F429I-DISC1. Pay attetion that SB9 is soldered.

I did not understand why the Blue Pill still not working. After some time, I do not know how, I found a video from a Russian channel,  ElectroHobby, that solve my problem[7], Thanks friend.

The ST-LINK V2 that I have is the cheap ones. I bought it on Aliexpress with my blue pill for U$10,00 I think[8]. Figure 7 shows two ST-LINK V2 that you can buy on Aliexpress, they are almost the same if you use Blue Pill. The  ST-LINK on the left of Figure 7 has only SWD connection, and the ST-LINK on the right has SWD, SWIM, and JTAG connection.

The video of ElectroHobby shows who to hack the ST-LINK on the left side of the Figure 7. Here I will show how to hack the ST-LINK on the right side.

 I was connecting the SWO(PB3) pin from the Blue Pin on the JTWO pin (I thought that was the same because of the labels on Figure 7) (-.-).

Figure 7. ST-LINK’s


If you have the left ST-LINK V2 of  Figure 7 you can follow the video.

My hack was a little cleaner that presented on the video. After you open the case of the programmer you will see some thing like Figure 8. There is a SWIM pin on ST-LINK V2 that is used to STM8 microcontrollers, you can see this pin labeled on Figure 7, I probably will not use this microcontrollers then I soldered a wire from PA10 in the 220 ohm resistor that is connect between PB3 to the pin 5 referent to SWIM.

Figures 8 and 9 show the positions where you need to solder the wire. Figures 10, 11, and 12 show how my ST-LINK looks now. Figure 13 shows the connectors labeled of my ST-LINK now.

I don’t know if there is a problem to connect PB3 and PA10 directly, but this worked (This is gambiarra). You can cut/scratch the path from the resistor to the PB3 pin from the microcontroller of the ST-LINK V2 if you want.

Figure 8. Front of ST-LINK V2
Figure 9. Back of ST-LINK V2
Figure 10. Front of ST-LINK V2 with SWO soldered
Figure 11. Front of ST-LINK V2. Where to solder the SWO wire.
Figure 12. Back of ST-LINK V2 with SWO soldered.
Figure 13. ST-LINK V2 Connector Modified.

Now the Blue Pill has the SWV functions too. The next steps explain how to set up this board to work with SWV.

First you need to create a new project on STM32CUBEMX, select the STM32F103C8Tx microcontroller, select Crystal to HSC in RCC, and Serial Wire to debug in SYS (Figure 14). After this you need to set the clock in the Clock Configuration tab. Just type 8 in the Input Frequency text field, and 72 in the HCLK to AHB bus, core text field (Figure 15). Now you can generate the source code to Keil uVision.

I just wrote a simple code to demonstrate this features, figure 16 shows the code. To use a variable on watchdog or logic analyzer you need to declare it globally.

Now you need to enable STDIN/STDOUT with ITM in Manage Run-Time Environment window like figure 17. In Options for target window, go to Debug tab, and click in Settings beside the name of your programmer device. Here you need to configure the debugger. You need to copy figure 19. Change the core frequency to the value that you use in the HCLK to AHB bus, core text field of STM32CubeMx.

Compile and download the program, and click in Start Debug Session.  Click in View-> Serial Window->Debug (printf) Viewer to add a terminal. Click in View->Analysis Windows->Logic Analyzer to add a logic analyzer window. Figures 20 and 21 show how to add and set a variable to the logic analyzer.

Now you just click in Run or press F5.

Figure 14. STM32CubeMx Pinout Tab


Figure 15. STM32CubeMx Clock Configuration Tab


Figure 16. Keil uVision5 Main File


Figure 17. Keil uVision5 Manage Run-Time Enviroment Window

Figure 18. Keil uVision5 Options For Target Window
Figure 19. Keil uVision5 Options For Target Window
Figure 20. Keil uVision5 Debug Window
Figure 21. Keil uVision5 Debug Window
Figure 22. Keil uVision5 Debug Window

OFF-TOPIC: I want to thank the Russian Blue Pill community, this guys is working hard with this board.  


[1] STM32F7: Debug(printf) Viwer y Logic Analyzer en Keil 5 –


[3] Serial Wire Viewer (SWV) for ARM Cortex-M3 Processors ARM Real-Time Trace aids debugging –

[4] Logic Analyzer –


[6] STM32F429I-DISC1 datasheet –

[7] STM32 Serial Wire Output SWO –

[8] STLINK-V2 aliexpress –

[9] STMF103xx Datasheet –



Autor: Daniel Nesvera

Apaixonado por engenharia e gambiarras!

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do

Você está comentando utilizando sua conta Sair /  Alterar )

Foto do Google

Você está comentando utilizando sua conta Google. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s