2015-10-05 09:13 AM
I am trying to change the clock source in a NUCLEO (STM32L152RE) board to reduce the power consumption.I use EmBitz as IDE. The Default configured clock in system_stm32l1xx.c is HSI clock (16MHz) with PLLMul 6 and PLLDiv 3 thus giving a System clock of 32MHz. The IDD drawn in this case is 6.95mA.
However if a try to decrease the system clock frequency to 16MHz with
RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_3, RCC_PLLDiv_3);
the power consumprion remains the same.
If a use RCC_DeInit(); the current drawn drops to 1.65mA (that is consistent with the fact that the default MSI 2MHz is selected as system clock).
Howeverif I try to change the clock source to MSI 2MHz without RCC_deInit(); but using
RCC_MSIRangeConfig(RCC_MSIRange_6); //2MHz
RCC_MSICmd(ENABLE);
RCC_HSICmd(DISABLE);
the current drawn increases to 10mA
I need some help about code needed to change clock source and frequency once the microcontroller has started
Thanks
2015-10-05 09:37 AM
The general rule is you can't change the PLL settings, when the PLL is running, and the processor is running from it. On most STM32 implementations I think register access is blocked.
So, you need to select a different clock for the source, disable the PLL, reconfig the PLL, start it, wait for it to lock, select it as the source again, wait for that to occur. One should probably quantify how long that all takes to switch back and forth. The other alternative is to change the AHB and APB dividers to get the clocking gearing you want. You can do this directly as the transition is glitch free. And will also allow you to quickly gauge if the speeds you're shooting for have the desired impact. When changing clocks you will also have to reconfigure any/all peripherals with input/output based on those clocks, ie USART baud rates, TIMs, etc