Nucleo L152RE out of the box system clock issue (24MHz to 32MHz)
Recently got charmed by world of ARM, which still is quite confusing for a guy coming from AVR background, but briefly said the performance difference is just overwhelming. But definitely these two (actually more since there is arm M0/3/4 etc.) architectures wrestle in entirely different categories, so direct comparison wouldn't be fair.
There is couple suggested fixes for this problem described in the title, but I couldn't manage to get them work for my board so I decided to write a little note about it.
Before you try this method yourself, I do claim this solved the problem for me, but I do have very little experience in ARM programming, so I announce that trying this method is use at your own risk! The author is not responsible for damage caused to your hardware.
Part of the "problem" is actually described on Nucleo board description UM1724 document provided by ST.
"MCO from ST-LINK: MCO output of ST-LINK MCU is used as input clock. This frequency cannot be changed, it is fixed at 8 MHz and connected to PF0/PD0/PH0- OSC_IN of STM32 microcontroller. "
Clock sources
Mbed library currently seems to prioritize HSE clock source usage over HSI (an internal 16MHz clock always used by ADC). This sounds little weird, considering that most of my applications use ADC, so using two clock sources sounds like future problems waiting to happen, but for prototyping it is okay. Typically, though, external clocks are more accurate than internal ones. HSE clock currently has been configured in system_stm32l1xx.c file to be 24MHz when 8MHz source is used. In order to change this setting, download mbed-src repository and use it instead of mbed standard one.
I used STM32CubeMX to find correct dividers for the 32 MHz clock configuration.
In order to provide 32MHz system clock, PLLMul and PLLDiv has to be changed accordingly to 12x and /3. This should provide appropriate clock speeds for peripherals and USB, if needed. Clock setting is found in system_stm32l1xx.c
Same as a code insert
// SYSCLK = 24 MHz ((8 MHz * 6) / 2) // USBCLK = 48 MHz (8 MHz * 6) --> USB OK RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; /* Parameters below changed to support 32MHz MUL12/DIV3 from original MUL6/DIV2 */ RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
These can be little hard to find, but it is located in mbed-src/targets/cmsis/target_stm/target_stm32l1/system_stm32l1xx.c . You can use the search tool to find those bits. After changing these and compiling, you should be able to enjoy your new system speed! You can also use pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); command with proper serial initialization to see your clock speed printed to pc terminal window.
References and links
Please log in to post comments.