cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L clock change

marcogrossi89
Associate II
Posted on October 05, 2015 at 18:13

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

1 REPLY 1
Posted on October 05, 2015 at 18:37

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..