2023-10-18 7:49 PM
SWV 16MHz, SYSCLK 16Mhz = logging works
SWV 16MHz, SYSCLK 25Mhz = logs gibberish (expected)
SWV 25MHz, SYSCLK 25Mhz = logs nothing at all
SWV 48MHz, SYSCLK 48Mhz = logs nothing at all
Why would this be?
It works with HSI 16MHz, so my wiring and configuration must be correct. I'd expect gibberish from a mismatch, seems odd to see nothing at all.
Maybe the V3PWR is at fault? I've ordered a V3SET and V3MINIE to compare.
HSI isn't accurate enough for my needs. My HSE is 25MHz and PLLP output must be >= 24MHz, so I can't try HSE 16MHz.
Solved! Go to Solution.
2023-10-19 7:52 AM
CubeIDE version: 1.13.2 (18220_20230914_1601, latest as of yesterday)
V3PWR firmware: V4.J3.B1.P4 (latest as of yesterday)
Target: STM32F411CEU6
SWD is working, so I can pause execution and check eg SystemCoreClock. It's 16000000 before SystemClock_Config() and 25000000 after. My code continues to run at 25MHz so I think my HSE is working correctly. I will drag out the scope to be sure... oh wow my HSE is actually 10MHz. Just wow. Aaaaand SWO works correctly now that I specified the right speed. What an idiot moment! Thank you for taking a look and prodding me to find the error.
I think it'd be an improvement if the UI would report invalid data on SWO. The differentiation between "there is nothing" and "there is something but it's invalid, are your speeds correct?" would surely help many people.
2023-10-19 2:32 AM
I think such issue maybe caused by time sequence issue of the SWV.
2023-10-19 3:48 AM
Hello,
According to the STLINK-V3PWR user manual (https://www.st.com/resource/en/user_manual/um3097-source-measurement-unit-smu-and-debuggerprogrammer-for-stm32-microcontrollers-stmicroelectronics.pdf) the maximum frequency for SWV is 12MHz at 3.3V and 10MHz at 1.8V. Higher frequencies may generate too many data loss in a continuous flow to consider it functional. Gibberish data are not always present, they require the STLINK-V3PWR UART to at least detect a start bit and to face no other error afterwards. At 25MHz and 48MHz the signal is probably too much degraded at STLINK-V3PWR UART input, this has even not been measured (clearly out of specifications)
2023-10-19 6:39 AM
Thanks, but the speeds I mentioned for SWV is the core clock speed as entered into the debug configuration in STM32CubeIDE:
I have tried limiting (down to 200kHz) and not limiting the SWO clock, but it doesn't change the result. Here are my numbers showing the SWO clock:
SWV 16MHz / 8 = 2000kHz, SYSCLK 16Mhz = logging works
SWV 16MHz / 8 = 2000kHz, SYSCLK 25Mhz = logs gibberish (expected)
SWV 25MHz / 13 = 1920kHz, SYSCLK 25Mhz = logs nothing at all
SWV 48MHz / 16 = 2000kHz, SYSCLK 48Mhz = logs nothing at all
With SYSCLK 48Mhz, the SWO clock is the same 2000kHz as it is with SYSCLK 16Mhz, yet it does not work.
It makes sense about the start bit, though I still don't understand why the only configuration that works is SWV 16MHz / 8 = 2000kHz. It seems if I set any other frequency, I get nothing.
2023-10-19 7:07 AM
OK so the issue seems rather at CubeIDE or application level, not at probe level (in your cases, the parameter given to the probe by CubeIDE should be 2000kHz or 1920kHz, the probe has no knowledge of the real core clock). You have to ensure that the core clock value specified in CubeIDE for trace configuration is really matching the runtime value of your application (get rid of any possible build configuration issue, ...). What is your CubeIDE version ? On which target do you see the issue ? Do you have the possibility to either monitor signals (to check UART frequency) or to add a blinking LED in your application to double check the runtime frequency between configurations ?
2023-10-19 7:52 AM
CubeIDE version: 1.13.2 (18220_20230914_1601, latest as of yesterday)
V3PWR firmware: V4.J3.B1.P4 (latest as of yesterday)
Target: STM32F411CEU6
SWD is working, so I can pause execution and check eg SystemCoreClock. It's 16000000 before SystemClock_Config() and 25000000 after. My code continues to run at 25MHz so I think my HSE is working correctly. I will drag out the scope to be sure... oh wow my HSE is actually 10MHz. Just wow. Aaaaand SWO works correctly now that I specified the right speed. What an idiot moment! Thank you for taking a look and prodding me to find the error.
I think it'd be an improvement if the UI would report invalid data on SWO. The differentiation between "there is nothing" and "there is something but it's invalid, are your speeds correct?" would surely help many people.
2025-08-23 3:58 AM - edited 2025-08-23 4:23 AM
Had the same issue until tonight, experience C++ dev but newbie (4days) to STM32.
Anyhow, I managed to get the trace to run properly at 32MHZ thus far, after a cpl dozen failed attempts.
The Clock setting function: set the Clock speed to 32MHZ in the main example:
TESTED on STM32F411CE
VERY IMPORTANT: Be sure to test your clock speed settings: I figured I had the PLL_P value wrong !
And the ST documentation is not very clear on this value : I was after enforcing value 2 to have prescaler 2:
e.g. HSE to 25MHZ on STM32F411 then PLL_M prescaler set to 25 and then PLL_P to 2
Result 25/25 * (clock speed set value e.g. 192 MHZ) / 2 (PLL_P) == 96 MHZ clock speed.
However I figured I set, PLL_P = 2 , which caused the clock speed to be divided by factor 4 e.g. 192/4 instead of 2.
Instead again, it is counter intuitive but the PLL_P value needs set to binary b00 in order to obtain the desired prescaler to value == decimal 2.
So I was suprised that my attempts kept failing, after debugging, adding the SystemCoreClock to a WATCH while debbuging, I figured it out, then simply setting the CPU speed, as below in Keil IDE Trace config settings, did the trick, so far tested 32 and 48 MHZ successfully.
Note: I am not even using an official STM32 Vlink but the Chinese cheap clone modified to expose the SWO pin. And well it works pretty well. See my post :
https://community.st.com/t5/stm32cubeide-mcus/debugging-with-itm-not-working-with-swv-in-stm32cubeide/td-p/172503
The correct clock speed code with correct PLL_P b00 value.
void SystemClock_Config(void) {
// Enable HSE (if using external crystal) 25MHZ on F411
RCC->CR |= RCC_CR_HSEON;
while (!(RCC->CR & RCC_CR_HSERDY));
RCC -> APB1ENR |= RCC_APB1ENR_PWREN;
PWR ->CR |= PWR_CR_VOS;
// Configure Flash Latency (example for high speed)
FLASH -> ACR |= FLASH_ACR_ICEN | FLASH_ACR_PRFTEN | FLASH_ACR_DCEN |FLASH_ACR_LATENCY_3WS;
// Configure PLL (example values, replace with your calculations)
//Put PLL_M = 25, PLL_P = 0, PLL_N = 192, PLL_M = 25 and PLL_Q = 4 (Main PLL prescaler)
//Select PLL source as HSE oscillator by setting the RCC_PLLCFGR_PLLSRC bit.
//formula https://kunalsalvi63.medium.com/bare-metal-rcc-setup-for-stm32f411cex-23d2ef2d706d
// Input HSE freq => 25MHZ for F411 / PLL_M x PLL_N / PLL_P ==
// 25/25 *192 / 2 == 96 MHZ clock
// Then ensure to set AHB, APB1 and APB2. APB1 MAx 50 MHZ ! , APB2 MAX =96MHZ
//Put PLL_M = 25, PLL_P = 0 (to get / 2), PLL_N = 192, PLL_M = 25 and PLL_Q = 4.
RCC->PLLCFGR = (25U << RCC_PLLCFGR_PLLM_Pos) | // PLLM = 25 MHZ for HSE oscillo
(64U << RCC_PLLCFGR_PLLN_Pos) | // PLLN = 192 MHZ
(0U << RCC_PLLCFGR_PLLP_Pos) | // PLLP = 2 (0b00)
(4U << RCC_PLLCFGR_PLLQ_Pos) | // PLLQ = 4 so 192/4 e.g.
RCC_PLLCFGR_PLLSRC_HSE; // PLL Source is HSE
// Enable PLL
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR & RCC_CR_PLLRDY));
// Configure AHB, APB1, APB2 prescalers
RCC->CFGR |= RCC_CFGR_HPRE_DIV1 | // AHB prescaler = 1 => ,max AHB == 96
RCC_CFGR_PPRE1_DIV2 | // APB1 prescaler = 2 max APB1 50MHZ
RCC_CFGR_PPRE2_DIV1; // APB2 prescaler = 1 max APB2 96MHZ
// 25mhz fixed PLL max 100 AHB96 APB1 50 APB2 96/
// HSE >>> PLL >>> SYSCLCK >>> AHB/APB1/APB2
// Select PLL as system clock source
RCC->CFGR |= RCC_CFGR_SW_PLL;
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);
// Update SystemCoreClock variable (part of CMSIS)
SystemCoreClockUpdate();
}
int main()
{
printf("Hello, STM32!\n");
printf("Hello, STM32!\n");
printf("clock speed %d, STM32!\n", SystemCoreClock);
SystemClock_Config();
printf("clock speed %d, STM32!\n", SystemCoreClock);
USART2_Init();
while(1){
printf("clock speed %d, STM32!\n", SystemCoreClock);
USART_write('!');//print !
USART_write('\r');USART_write('\n'); //new line and return cursor to start of the line
delay(1000);
}
}
Keil IDE Debug trace config. I found that getting the clock option e.g. using the system clock, or SWO clock and then selecting a manual set/forced prescaler value or leaving it to "set to max" is what made the difference between scrambled characters and then clear output.
As below test done with 32MHZ
Keil IDE Trace debug config
Note: The prescaler for SWO is calculated by Keil IDE and is e.g. 3x for 32MHZ, was only 2x for 16MHZ, and for 64MHZ, just tested to work is set to 4x.
So to answer to S.C ST Employee: This is very important to enter the correct CPU clock speed and making sure one way or another than your IDE or whatever debug setup takes it into account and sets the right prescaler value for the SWO channel!
Update: TESTED to work at 48MHZ too, will keep testing see what happens, as below success
TESTED at 64MHZ again works 1st hand if right debug trace setting in Keil IDE.
TESTED at 96MHZ again works 1st hand if right debug trace setting in Keil IDE. Which is 4MHZ away from the max 100MHZ for the STM32F411.
Again I cannot insist enough on the fact that you need to check that your debug IDE/setup is enforcing the correct SWO channel prescaler in order to limit the SWO freq to under 16MHZ. In this case thanks to letting KEil IDE setting it automatically to 8x, when at 96MHZ then it works perfectly !
Note you can set it manually, if your IDE does not set it automatically and just make sure to use under 16MHZ, I tested 10MHZ, 12MHZ and 8MHZ thus far to work perfectly.
2025-08-23 4:30 AM
As per my detailed reply below, I tested things to work well even at 96MHZ with my STM32F411CE. The key element is to set the SWO prescaler appropriately in Trace config in the IDE in order to obtain an SWO channel clock under 12MHZ. Tested 16 then 24, 32, 48, 64 then 96MHZ and it kept working.
I am not even using an official ST vlink but the cheap chinese clone, that I solder a wired onto pin PA10 to expose the SWO pin. The clone is an STM31F103 btw. So basically we have an F103 and an F411 in this case at different clock speed, however the IDE tells the ST Link / clone to set their CLK (I guess the SWCLK) at e.g. 12MHZ and as long as both ST link and the target device are both set to the same SWCLK under 12MHZ then there's no issue.
So you were right the actual CPU clock is not what really matters, what does it ensuring that the 2 ends have the SWCLK right.
2025-08-23 4:41 AM - edited 2025-08-23 4:45 AM
As per my detailed answer below the SWO clock SWCLK pin btw, is used on ST Link and it will be connected to your Target MCU on its SWCLK pin. And as you may know the difference between a UART and USART is the CLK pin addition that enables both ends to communicate synchronously thanks to the CLK pin.
IF you look at documentations on the matter it explains how USART can run at significantly higher baud rate and clock speed therefore. Where a simple basic UART only having 2 pins RX and TX is very limited.
So anyhow, this is what motivated me to dig a bit and not buying that the MCU clock speed was a determining factor due to the fact that SWO has its own clock.
In a nutshell, as my reply below, I found that my clock speed function was wrong. 1st issue, then fixed.
Then I found that my Keil IDE trace settings were wrong namely that the Prescaler value for SWO needs to be set to a correct value.
1. in Keil IDE the automatic "set to max" setting seems to work well, e.g. tried 16,32,48,64 then 96 MHZ clock speed to see that keil IDE was calculating the right Prescaler for SWO, as screenshots in my reply below: the prescaler went up from 1,2,4,6 then 8 for 16,24,32,64 and 96 MHZ clock speed. Ended with 12MHZ SWO clock when on 96MHZ cpu speed.
Note: I tried setting this by hand it did not work ! The value needs to be i guess a specific fraction of your clock speed. e.g. 12MHZ worked well for 96, 10.666 MHZ did for 32 MHZ etc. screenshots below.
So clearly the .666 decimal value shows you need to enforce a specific SWO clock speed somehow. I could be wrong, it could just be some value under 12 MHZ that are compatible with the ST link. e.g. some values are not supported, some are. Anyhow Keil IDE gets it right or so it seems.
So I really believe that what happened in your case is nothing to do direclty with the clock speed being higher but your manual static limiting value being incorrect, with Eclipse / Cube IDE is I suspect "Limit SWO clock" does only enforce a manual value ( if im correct ?) vs Keil IDE having a nicer integrated auto algo to compute the correct value according to the cpu clock speed, If you get it wrong, it will not work.
So perhaps take a look at the values i got with Keil IDe below, and try. im pretty sure this is your problem. I will try in Cube IDE when i have time.