Turn off pll before entering sleep - STM32F410RB
Hello,
i am using stm32f410rb device, where i want to do some things at 100mhz using HSI only, and pll.
After this i am puting the device in sleep mode, and provide wakeup using the rtc interupt.
The HSE is not used.
My problem is that before sending the sleep functions, the pll and the system clock source remains still on the PLL.
If i remember corectly i cannot change pll setings while this is running..
Here is my code
int main(void)
{
clockConfig();
RCC_ClocksTypeDef clocks;
RCC_GetClocksFreq(&clocks);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
/* Check that the system was resumed from StandBy mode */
if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
/* Clear SB Flag */
PWR_ClearFlag(PWR_FLAG_SB);
}
sprintf(sout,"%d",clocks.HCLK_Frequency);
USART_puts(USART1,sout);
configure_rtc(); // configure rtc to generate interupt every 20 sec
while(1)
{
if(stbyFlag==0)
{
stbyFlag=1;
clockConfig(); // configure back the clock to HSI + PLL
RCC_GetClocksFreq(&clocks);
sprintf(sout,"HCLK after wakeup %d\r\n SysClk source %d
\r\n",clocks.HCLK_Frequency,RCC_GetSYSCLKSource());
USART_puts(USART1,sout);
}
//#################### Do things here before sleep #####################
//######################################################################
//########## Config clocks and turn off PLL before entering sleep
RCC_HSEConfig(RCC_HSE_OFF);
RCC_HSICmd(DISABLE);
//Disable the PLL
RCC_PLLCmd(DISABLE);
RCC_HSICmd(ENABLE);
//check and wait for HSI to be stable
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
SystemCoreClockUpdate();
//####### end of config clks before sleep #######
for(uint32_t g=0;g<0xFFFF;g++); // add some delay
RCC_GetClocksFreq(&clocks);
sprintf(sout,"HCLK after sleep %d\r\n",clocks.HCLK_Frequency);
//########### Enter in stop mode
PWR_FlashPowerDownCmd(ENABLE); //set FPDS bit
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
return 0;
}
void RTC_WKUP_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_WUT) != RESET)
{
GPIO_ToggleBits(GPIOA,GPIO_Pin_5);
GPIO_ToggleBits(GPIOC,GPIO_Pin_3);
RTC_ClearITPendingBit(RTC_IT_WUT);
stbyFlag=0;
EXTI_ClearITPendingBit(EXTI_Line22);
}
}
After coming from sleep interupt i set the stbyflag to reconfigure back to HSI & PLL for SystemClock,
Then i do the tasks... and try to turn off the PLL before entering sleep again.
My problem is that i cannot turn off the PLL and the SysClock source is remaining set on the PLL output.
Before sleep i want the sysclock to be sourced only from the HSI output.
What do you think?
