I need my system clock to run on 150 MHz. But I also need to read&write to Flash.
To achieve this I wanted to change the clock from 150 MHz to 75 MHz and after the Flash operation bump the speed back up to 150 MHz.
But I am not sure how to do this.
I wanted to do is in the following way:
void System::decreaseMainClockSpeed()
{
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 2U, false);
POWER_SetVoltageForFreq(75000000);
SystemCoreClock = 75000000;
}
void System::resetMainClockToOriginalSpeed()
{
POWER_SetVoltageForFreq(150000000);
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);
CLOCK_GetFreq(kCLOCK_BusClk);
SystemCoreClock = 150000000;
}
The decreaseMainClockSpeed function works like it should. But when I call the resetMainClockToOriginalSpeed everything breaks after the CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); function.
Can someone help me?
Hello,
I recommend the use of the MCU config tool, try to change the frequency and evaluate what changes were made in the code then implement them in your application.