Skip to main content
Graduate
May 13, 2024
Solved

ITM SWO works but i dont know why.

  • May 13, 2024
  • 3 replies
  • 3541 views

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? 

 

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    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

    3 replies

    BasanoAuthor
    Graduate
    May 13, 2024

    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).

    Graduate II
    May 13, 2024

    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

    Graduate II
    May 13, 2024

    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

    Super User
    May 13, 2024

    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.

    BasanoAuthor
    Graduate
    May 13, 2024

    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.

    Graduate II
    May 13, 2024

    So assuming you're DIY'ing this and not using libraries

    MCU will start and run from MSI at 4 MHz unless you change things

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

     

    Super User
    May 13, 2024

    This variable comes from the ARM CMSIS conventions. Any vendors' chip startup code must define SystemCoreClock and keep it in sync with every update of  the core clock. ST libraries for CubeIDE use this convention and so do Keil and IAR. If your project lacks this... you live in a cave?

    SystemCoreClockUpdate() is another CMSIS defined function that reads the core clock from hardware and updates SystemCoreClock.  My bad, in previous reply I've meant SystemClock_Config(), not SystemClockConfig. That function is specific to the ST library.

    Graduate II
    May 13, 2024

    >>... you live in a cave?

    Avoid the ones with bat guano, that s**t will make you crazy..

     

    If one goes full-bare-metal it's probably not going to be there or needed. Not fully aware of the context here, but a quick grep of the source code, or github should illuminate.