2020-07-22 01:09 AM
I am trying to change the system clock on my STM32F412 discovery board to 100 MHz using the HSI, however it just seems to crash. I am using direct writes to registers, but I looked at pregenerated CubeMX code and my registers look the same for the clock settings.
It crashes when I try to run the application on the board. Ignore the for loops in my code, they were just there for debugging stuff.
I do the following (HSI is selected by default):
Enable the Power control in the APB1
Set to scale 3 since I want it at 100 MHz
Turn the PLL off
Set PLLM to 8, PLLN to 0x64, PLLQ to 3, PLLR to 2, PLLP to 0
Set PPRE to 4 and SW to 2
Turn the PLL on and the adjustment
Wait for PLL to be ready
Wait for Power to be ready
int i;
RCC_APB1EN_R |= APB1EN_PWREN;
PWR_C_R = PWR_C_VOS_SCALE3;
for(i = 0; i < 500; i++);
RCC_C_R &= ~C_PLLON;
for(i = 0; i < 500; i++);
RCC_PLLCFG_R = PLLCFG_PLLM_8 | PLLCFG_PLLN_64 | PLLCFG_PLLQ_3 | PLLCFG_PLLR_2 | PLLCFG_PLLP_0;
for(i = 0; i < 500; i++);
RCC_CFG_R = CFG_PPRE1_4 | CFG_SW_2;
for(i = 0; i < 500; i++);
RCC_C_R = C_PLLON | C_HSITRIM_10;
while(!(RCC_C_R & C_PLLRDY));
while(!(PWR_CS_R & PWR_CSR_VOSRDY));
I confirm this doesn't work, I get a crash. I checked all my registers and they seem to be the same as the CubeMX generated project but I need to use registers writes for this because it is for a project and we are forbidden from an external API.
2020-07-22 01:23 AM
You need to set the needed flash wait cycles before switching up speed!
2020-07-22 01:50 AM
Wow! I am silly! I completely overlooked that. That fixed it. Thank you so much!