cancel
Showing results for 
Search instead for 
Did you mean: 

SystemCoreClock Reading incorrect value?

jksystem247
Associate II
Posted on October 25, 2013 at 10:54

Hi, I am working with STM32F401 discovery board.

I set up the system_stm32f4xx.c file so that the system clock becomes 84MHz(I used Excel based stm32 clock generator tool to get PLL values).

void Delay(uint32_t dlyTicks){

 msTicks = 0;

 while(msTicks<dlyTicks);

}

SystemInit();

 SystemCoreClockUpdate();//Update variable SystemCoreClock

//SysTick_Config(SystemCoreClock/1000);

 SysTick_Config(84000);

If i do switch to the code that is commented out above, I get in accuracte timing for delay.

The problem is that SystemCoreClock is read as 262500000. I don't understand why. Shouldn't it read 84000000 or 10500000?

The un-commented code works fine and the SysTick seems to be operating at 84MHz clock.

When I generated system_stm32f4xx.c file, I set up the Excel Wizard so that Systick runs at 10.5MHz. Why is it running at 84MHz? and how can I change it correctly??

Thank you.

3 REPLIES 3
Posted on October 25, 2013 at 12:58

I'd just edit the file manually and understand the relationship between the clock settings.

Perhaps you have HSE_VALUE wrong? The DISCOVERY boards have an 8 MHz crystal, whereas the EVAL boards typically have an 25 MHz one. The relationship between the clocks is hardly complex.

#if defined (PLL_SOURCE_HSI)
uint32_t SystemCoreClock = ((HSI_VALUE / PLL_M) * PLL_N) / PLL_P;
#else
uint32_t SystemCoreClock = ((HSE_VALUE / PLL_M) * PLL_N) / PLL_P;
#endif

If this gives the wrong answer, then some of the input variables are wrong.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jksystem247
Associate II
Posted on October 28, 2013 at 02:15

the ''system_stm32f4xx.c'' file generated by stm32f4xx clock configuration tool seems to make the Systick run at 48MHz( SysTick_Config(48000) makes interrupt occur every 1ms)). However, on the tool, it shows Cortex Timer(Systick) = 6. 

In the ''system_stm32f4xx.c'' file, I inserted a little code defining #define HSE_VALUE 8000000. Otherwise it is unchanged.

I don't know what's wrong. I am not even sure that the core is running at 48MHz.

below are my Dropbox link to relevent files.

Thank you.

https://www.dropbox.com/s/frna2zgdblnjbns/Clock%20Configuration%20Tool%20for%20STM32F40x%2c41x.xls

https://www.dropbox.com/s/7h698fbpy490xut/system_stm32f4xx.c

https://www.dropbox.com/s/ephfshqiwwm6se8/myBlinky.zip

Posted on October 28, 2013 at 12:50

Consider using

STM32F401-Discovery_FW_V1.0.0\Projects\Template\system_stm32f4xx.c Make sure you define STM32F401xx for the project Alternatively consider #define PLL_N 336 #define PLL_P 4 #define PLL_M 8 #define PLL_Q 7

uint32_t SystemCoreClock = ((HSE_VALUE / PLL_M) * PLL_N) / PLL_P;

This would run the part at 84 MHz, and also allow 48 MHz for the USB clock
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..