Clock settings in STM32l152 (startup/stability issues)
Hello.
I'm playing with my stm32l152 discovery board. I've got lcd, buttons, leds working. I wanted to change my clock speed to 16Mhz HSI (default 2Mhz MSI) and problem started.
To write my code I use RM - and I'm missing something. How this configuration should be done?
There is my clocks setting code: (If nedded I can upload whole project)
RCC->CR |= (RCC_CR_HSION); //enable high-speed internal oscillator
while(!(RCC->CR & RCC_CR_HSIRDY)); //wait until oscillator starts
RCC->CFGR |= RCC_CFGR_SW_HSI; //set hsi as systemclk
while((RCC->CR & RCC_CFGR_SWS_HSI)!= RCC_CFGR_SWS_HSI);
RCC->CFGR |= (RCC_CFGR_MCOSEL_SYSCLK); //set mco output to sysclk
RCC->AHBENR |= (RCC_AHBENR_GPIOAEN); //enable clock for PORTA peripheral
RCC->AHBENR |= (RCC_AHBENR_GPIOBEN); //enable clock for PORTB peripheral
RCC->AHBENR |= (RCC_AHBENR_GPIOCEN); //enable clock for PORTC peripheralThis is just after main(). Is this correct way to do it?
What actually happens:
After reset processor doesn't always start up (led doesn't blink). When it sometimes starts - the signal on MCO output is not present every time(2/10 times?) And moreover - the led sometimes flashes as on 2Mhz and sometimes as on 16Mhz clocks (somehow returning to default?) .
Any help really appreciated!
