Skip to main content
hazall
Associate II
May 12, 2023 10:51 AM UTC
Question

Change system clock stm32f0 manual

I want to change system clock as a PLL(using HSE) 20 Minute after systemInit. thats why I must change it in main function not system_stm32f0.c file.

Here is my code, Not working properly. I dint do anything interrupt function.

void ClockInit(void)

{

if ((RCC->CFGR & RCC_CFGR_SWS) == RCC_CFGR_SWS_PLL)

{ 

RCC->CFGR &= (uint32_t) (~RCC_CFGR_SW);

while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) {}

}

RCC->CR &= (uint32_t)(~RCC_CR_PLLON); 

while((RCC->CR & RCC_CR_PLLRDY) != 0) {}

RCC->CFGR &= ~(RCC_CFGR_PLLMULL | RCC_CFGR_PLLSRC);

  RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI_Div2 | RCC_CFGR_PLLMUL5);

 //RCC_PLLConfig(RCC_CFGR_PLLSRC_HSI_Div2,RCC_CFGR_PLLMUL5);

RCC->CR |= RCC_CR_PLLON; /* (7) */

while((RCC->CR & RCC_CR_PLLRDY) == 0) {}

RCC->CFGR |= (uint32_t) (RCC_CFGR_SW_PLL);

while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) {}

 SystemCoreClockUpdate();

}

Thanks for everything

This topic has been closed for replies.

5 replies

waclawek.jan
Super User
May 12, 2023 11:51 AM UTC

What are exactly the symptoms?

Code looks good. Can't you single-step and observe the registers?

Which STM32? The 'F0 family has two different RCC setup (PLL prescaler).

JW

hazall
hazallAuthor
Associate II
May 15, 2023 10:26 AM UTC

STM32F030C8T6TR

I changed code like that, it seems good

void RCC_HSE_Configuration(void){

RCC_DeInit();

RCC_HSEConfig(RCC_HSE_ON);

if(RCC_WaitForHSEStartUp() == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_4);  

RCC_PLLCmd(ENABLE);

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

while(RCC_GetSYSCLKSource() != 0x08); 

}

SystemCoreClockUpdate();

}

Piranha
Principal III
May 13, 2023 7:01 AM UTC

Did you adjusted the FLASH latency and APB prescalers properly before increasing the SYSCLK?

hazall
hazallAuthor
Associate II
May 15, 2023 10:28 AM UTC

No, I don't quite understand, can you show an example code?

Piranha
Principal III
May 23, 2023 11:30 PM UTC

Reference manual has an explanation and even exact sequences of actions listed.