cancel
Showing results for 
Search instead for 
Did you mean: 

ITM SWO works but i dont know why.

Basano
Associate II

Hello Gentlemen!
I have edited this question, former question below just for clarity.

New question: the ITM SWO printF-ing works with frequency of 4 MHz. I have searched every little PDF regarding my board (NUCLEO-U575ZI-Q) and i have no clue where you can find this number. Can anyone help me? The frequency in question is this one:

Basano_0-1715631555690.png

 

 

 

 

 

 

 

Former question (ignore)

 

Spoiler


I am just trying to make printF work over SWO. on my board, over STM32 IDE 

 

Board number: NUCLEO-U575ZI-Q

Things i tried on the internet:
1. dont forget \n sign.

2. Make sure you have Solder bridge or whatever, to SWO: Internet provides lots of images of some table, where you have this SWO pin explicitely mentioned and said if its soldered or not. I never found this, but i did look at scheme, and everything related to SWO was present, no DNF

3. You have to have your CoreClock config synchronized: The only thing i found is in this image. I used both 16Mhz and 48 mhz, with no luck

Basano_1-1715630032959.png

Now, my config looks like this:

Basano_2-1715630218932.png

With ITM config like this:

Basano_3-1715630284195.png

 

and implementation of ITM function:

#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000)
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00)

void ITMSendChar(uint8_t ch){
DEMCR |= (1<<24);
ITM_TRACE_EN |= (1<<0);
while (!(ITM_STIMULUS_PORT0 & 1));
ITM_STIMULUS_PORT0 = ch;

}

 

#include <stdio.h>

#if !defined(__SOFT_FP__) && defined(__ARM_FP)
  #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
int main(void)
{
printf("Hello \n");
    /* Loop forever */
for(;;);
}

 

Am I missing something? 

 

1 ACCEPTED SOLUTION

Accepted Solutions

https://www.st.com/resource/en/datasheet/stm32u575zi.pdf

"The system clock after wake-up is MSI up to 4 MHz"

So if your code does nothing, and doesn't bring up the HSI, HSE or PLL's, it will be running at 4 MHz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

14 REPLIES 14
Basano
Associate II

Gentlemen, i have now figured out that the frequency was 4 MHz. It works with that.

Now let me reiterate the question. Can anyone find where the 4 MHz comes from (i got this number by bruteforcing it and trying it randomly).

Is it the HSI / MSI clock the part is starting from?

Typically the number here is SystemCoreClock, so whatever the processor is running at via the PLL, etc.

The ST-LINK should know it's SWCLK rate, and that can be relative low on the V2's and relatively high on the V3, but not overly fast on the CM0(+) cores because of relative slowness.

The rate of the MCU and the SWV then dictates the SWO baud rate divider.

 

printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);

TPI->ACPR is the divider on the CM7's = (SystemCoreClock / (SWCLK * 2)) - 1 if I recall

 

https://www.keil.com/appnotes/files/apnt_297_v102.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

Usually this number must match the value of global variable SystemCoreClock.  For 4.0 MHz SystemCoreClock must be 4000000.

SystemCoreClock will change after your code calls SystemClockConfig() so you want to call SystemClockConfig early, before any printf, and put in the SWV settings box the value after this call.

https://community.st.com/t5/stm32cubeide-mcus/trace-swo-output-in-non-debug-mode/td-p/281533

SWOPrescaler = (SystemCoreClock / SWCLK) - 1 

*((volatile unsigned *)(ITM_BASE + 0x40010)) = SWOPrescaler; /* "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output */

Connection rates for ST-LINK/V2 are typically 4 MHz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Unfortunately, i cannot make the code run. The variable is just not there. 
Thanks for the answer anyway, ill try to have a look around the internet to make it work.

Well, two replies with the same "global variable SystemCoreClock" but where do i get this global variable from? If i just put it into code, it throws error saying this variable doesnt exist.

I am very grateful for your reply tho. Ill try to surf on the internet a little bit, if you dont reply to this.

Thanks for the last sentence.

However, where do you all get this global variable systemCoreClock? All three replies had this. I am not getting this at all and internet is like "well jsut call SystemCoreClockUpdate" but that doesn't exist either.

 

It literally just says that variable doesnt exist.

 

I am still eternally gratful for your response, thanks.

What are you building with?

HAL should have it in system_stm32xyz.c

https://github.com/STMicroelectronics/STM32CubeU5/blob/main/Projects/NUCLEO-U575ZI-Q/Templates/TrustZoneDisabled/Src/system_stm32u5xx.c#L164

System should be able to back compute by picking through PLL settings, clock source, and things like HSE_VALUE for board level specifics.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

https://www.st.com/resource/en/datasheet/stm32u575zi.pdf

"The system clock after wake-up is MSI up to 4 MHz"

So if your code does nothing, and doesn't bring up the HSI, HSE or PLL's, it will be running at 4 MHz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..