Skip to main content
Graduate
September 10, 2025
Solved

Blue and Black Pill SWO debugging

  • September 10, 2025
  • 7 replies
  • 953 views

Split from STM32H5 SWO debugging.


I want use SWO pin like standalone debug. Send data by "ITM_SendChar('A');" and want to read data from SWO pin by USB-UART dongle, SWO pin => Rx pin UART-USB on PC.

I try blue and black pill (STM32F103 and STM32F411), in stm32 cube ide I configured SysremCore->SYS->Debug: Trace Asynchronus Sw. In "Debug configuration" is Enable for SWV and clock core 8Mhz (SYSCLK and HCLK = 8MHz).

In main sycle:

 while (1)
 {
 /* USER CODE END WHILE */
	 HAL_GPIO_TogglePin(Led_GPIO_Port, Led_Pin);
	 HAL_Delay(1000);
	for (int i = 0; i < 10000; ++i) ITM_SendChar('A');
	 HAL_GPIO_TogglePin(Led_GPIO_Port, Led_Pin);
	 HAL_Delay(1000);
 /* USER CODE BEGIN 3 */
 }

LED is blinking, but SWO pin out is NO SIGNAL (Checking by oscillograph).
Where is it possible problem?

    This topic has been closed for replies.
    Best answer by Andrew Neil

    @TDK wrote:

    The SWO signal is not a UART signal. 


    In principle, it could be:

    https://developer.arm.com/documentation/ddi0314/h/Serial-Wire-Output/SWO-trace-port/Physical-pin-protocol#:~:text=Manchester%20encoding%20example-,UART%20encoding,bit%20%5B11%5D%20of%20the%20Device%20ID%20Register%2C%200xFC8%2C%20is%20set,-.%20It%20is%20enabled

    Do (any) STM32 support that ?

    @mkigor Generally, it's connected to the debug probe; eg, ST-Link.

    7 replies

    Super User
    September 10, 2025

    Note that Blue & Black Pills are not ST products, and likely do not have genuine STM32 chips.

    In the other thread@AScha.3 said that it's important to end your output with \r\n - did you try that?

    Graduate II
    September 10, 2025

    you wrote:

    > SWO pin => Rx pin UART-USB on PC

    Are you sure this is correct?

    I would expect to send from STM32-SWO via a pin labeled Tx or TxD to the PC. Maybe you want to double check the doc of your USB converter.

    Super User
    September 10, 2025

    @mfgkw wrote:

    I would expect to send from STM32-SWO via a pin labeled Tx or TxD to the PC


    Really?

    SWO = Serial Wire Output - so I'd expect it to go to RX (an input) on the PC (a DTE) ?

    Graduate II
    September 10, 2025

    It will depend on how the developer of the converter looks on its baby.

    The doc should tell...

    Super User
    September 10, 2025

    > want to read data from SWO pin by USB-UART dongle, SWO pin => Rx pin UART-USB on PC.

    The SWO signal is not a UART signal. This has no hope of working.

    Super User
    September 10, 2025
    Super User
    September 10, 2025

    >Do (any) STM32 support that ?

    Yes.  On the "clone" ST-link V2 just need to connect to PB7 , UART1 Rx , to get the SWO data.

    (The pic i showed, with CubeProgrammer connected to a H743 cpu showing SWV data, is made with an modified 

    ST-link V2 , working 100% reliably at 2 Mbit. With a ST-link V3 higher speed is no problem.)

    here with cmsis-DAP , also STM32F103 cpu :

    AScha3_0-1757526247105.png

     

    Super User
    September 10, 2025

    >and want to read data from SWO pin by USB-UART dongle, SWO pin => Rx pin UART-USB on PC.

    This wont work.

    Its more complex, than you are thinking : 

    AScha3_3-1757523226349.png

     

    +

    AScha3_2-1757523084230.png

     

    AScha3_0-1757522635139.png

    You can connect with the CubeProgrammer -> ST-link -> to the ITM :  then see SWV  -> SWO output:

    AScha3_1-1757522764415.png

    +

    >want to read data .. by USB-UART dongle, .. pin => Rx pin UART-USB on PC.

    If you just want serial "debug" messages, use an UART at "some speed" .(I use 3 Mbit for this.)

    Or the USB , as CDC device , so you can connect to a PC /USB directly. 

     

     

    mkigorAuthor
    Graduate
    September 10, 2025

    Ok, thank you all indeed, that is help for me that I am on the right way...
    1. I have chinese clone "blue pill" that have "normal" stm32f103c8t6, CubeIDE program it normal and simple example - led is blinking. Yes I have another one, fake, not working.

    2. SWO output can work in 2 protocol: It transmits data as either UART (NRZ) or Manchester code,. By default, it works at 2Mb/s speed.

    3. SWD with SWO output has more benefits than UART debug message, less load to MCU, only 1 wire use. If my result will not be success, noway - only UART message :(

    4. stm32 cortex M3,M4 support SWD SWO. But I dont undestand all of:
    UART encoding

    This protocol is supported if bit [11] of the Device ID Register, 0xFC8, is set. It is enabled when bits [1:0] of the Selected Pin Protocol Register, 0x00C, are set to 2'b10. Data is sent out in packets of ten bits, with start and stop bits, as shown in Figure 11.11 and Table 11.12. Capture devices are expected to operate at the same clocking speed as the TRACESWO pin and synchronize by waiting for a start bit.

    Somewhere I read, SWO not activated by default. A some register need to be init ???

    5. Yes, on the "clone" ST-link V2 it is possible solder + 1 wire to PB3 and send ITM_sendchar() message to window "SWV ITM Data Console" in CubeIDE. In my case, capture SWO data should be read by another device (something like "display terminal" read-only).

    Maybe I need to read the official datasheet of the debug SWD (SWO), configuration registers, etc. Can anyone help me find something? Thanks in advance.
     

    Super User
    September 11, 2025
    mkigorAuthor
    Graduate
    September 11, 2025

    Thanks. O, mama mia... So many, huge amount stm docs (milion pages) + arm docs in specific "black format" :) It is signalize - even not try to understand me.

    mkigorAuthor
    Graduate
    September 12, 2025

    Yea, but idea is good, but maybe "mission impossible". I see info, that it is working, but is no info how to do it. But, it is one more but ... :)
    This display terminal working on 3Mbit via UART, it's quite enough for SWO clock:
    https://github.com/mkprogigor/mkigor_terminal_p 
    https://www.youtube.com/watch?v=TVSalgKr5aE