2018-03-13 11:14 AM
Hi all,
I'm using STM8l052R8 MCU.
I'm trying to switch the clock from HSI to LSI but I can't.
this is my code:
{
CLK_DeInit(); //deinitiate clock
CLK_SYSCLKSourceSwitchCmd(ENABLE); //enable switchingCLK_LSICmd(ENABLE); //enable LSI oscillator
CLK->SWR = 0x02; // choose LSI as a clock source
}
the debugger doesn't work correctly. I'm using ST-Link Debugger.
Is this code Is correct or How to confirm that I switched to LSI correctly ??2018-03-14 05:19 AM
HelloMohammed,
Here is the snippet, which can be used to switch the system clock from HSI to LSI:
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSI);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_LSI)
{}�?�?�?�?�?�?�?�?
Looking at your code you do a similar thing. The difference is that you use direct register access to change the clock source for system clock and you don't wait for end of this operation. Anywayfrom my point of view it should work as well.
You mentioned thatdebugger doesn't work correctly.SWIM communication requirescertain clock frequency to work normally. When LSI is used, this frequency is too slow. So if on your side you see that after executing
CLK->SWR = 0x02; debug session is broken, then it is expected behaviour.
You canimplement a simple procedure to check if switching to LSI was succesful. For example you check in your codethe current system clock souce (CLK->SCSR or CLK_GetSYSCLKSource() ) and if the result is LSI, then you simply switch on the LED.
Regards
Szymon