2025-09-10 8:22 AM - last edited on 2025-09-10 8:46 AM by Andrew Neil
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?
Solved! Go to Solution.
2025-09-10 9:56 AM
@TDK wrote:The SWO signal is not a UART signal.
In principle, it could be:
Do (any) STM32 support that ?
@mkigor Generally, it's connected to the debug probe; eg, ST-Link.
2025-09-10 8:51 AM
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?
2025-09-10 9:23 AM
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.
2025-09-10 9:30 AM
@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) ?
2025-09-10 9:43 AM
It will depend on how the developer of the converter looks on its baby.
The doc should tell...
2025-09-10 9:50 AM
> 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.
2025-09-10 9:52 AM - edited 2025-09-10 9:55 AM
>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 :
+
You can connect with the CubeProgrammer -> ST-link -> to the ITM : then see SWV -> SWO output:
+
>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.
2025-09-10 9:56 AM
@TDK wrote:The SWO signal is not a UART signal.
In principle, it could be:
Do (any) STM32 support that ?
@mkigor Generally, it's connected to the debug probe; eg, ST-Link.
2025-09-10 10:42 AM - edited 2025-09-10 10:44 AM
>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 :
2025-09-10 2:41 PM - edited 2025-09-10 3:32 PM
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.