STM32C011 Clock Config
Hi @ST Community ,
I struggle to configure the clock speed to the frequency I desire.
The chip I am using is STM32C011F6U and the code I use as first function in main() is the following:
uint16_t cr = RCC->CR;
uint16_t cal = RCC->ICSCR;
uint16_t cfgr = RCC->CFGR;
//Reset Clock divider to 1 (full 48MHz)
cr &= ~(RCC_CR_HSIDIV_0 | RCC_CR_HSIDIV_1 | RCC_CR_HSIDIV_2);
cr |= (1U << 11);
cr |= (1U << 12);
cr |= (1U << 13);
RCC->CR = cr;
//Enable HSI48 Clock
RCC->CR |= RCC_CR_HSION;
//Wait for HSI to be ready
while((RCC->CR &= RCC_CR_HSIRDY) == 0u);
//Default HSI calibration trimming value
cal &= ~RCC_ICSCR_HSITRIM;
cal |= RCC_ICSCR_HSITRIM_6;
RCC->ICSCR = cal;
//Set APB divider to 8
cfgr &= ~RCC_CFGR_PPRE;
cfgr |= (RCC_CFGR_PPRE_2 | RCC_CFGR_PPRE_1);
RCC->CFGR = cfgr;
//Set AHB divider to 1
cfgr &= ~RCC_CFGR_HPRE;
RCC->CFGR = cfgr;
However the above doesn't seem to have any effect and the clock frequency never change. I have also tried to output the SYSCLK using the MCO pins.
What am I doing wrong or missing?
Thanks!
