STMicroelectronics/STM32CubeL1

SystemCoreClockUpdate() does not work correctly when SYSCLK source is HSI.

Closed this issue · 3 comments

yn386 commented

Describe the set-up

  • The board: NUCLEO-L152RE

Describe the bug
SystemCoreClockUpdate() does not work correctly when SYSCLK source is HSI.

If SYSCLK source is HSI and HSI_VALUE is not defined, SystemCoreClockUpdate() cannot update SystemCoreClock correctly.

According to the STM32L1 microcontorollers specification, the HSI value is 16MHz.
Also, the comment of SystemCoreClockUpdate() describes that the default HSI_VALUE is 16MHz.

* (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.

However, default HSI_VALUE is defined as 8MHz at
#if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)8000000U) /*!< Default value of the Internal oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSI_VALUE */

HSI_VALUE can be adapted by the user appliication, but I think default HSI_VALUE should be 16MHz.

How To Reproduce
HSI_VALUE is not defined.
To get 32MHz HCLK, I set

  • Use HSI
  • PLLMul x6
  • PLLDiv /3

After setting these parameters, call SystemCoreClockUpdate().
Global variable 'SystemCoreClock' expected 32MHz, but I got 16MHz.

Additional context
I changed default HSI_VALUE as follows.

--- a/CMSIS/STM32L1xx/Source/Templates/system_stm32l1xx.c
+++ b/CMSIS/STM32L1xx/Source/Templates/system_stm32l1xx.c
@@ -67,7 +67,7 @@
 #endif /* HSE_VALUE */
 
 #if !defined  (HSI_VALUE)
-  #define HSI_VALUE    ((uint32_t)8000000U) /*!< Default value of the Internal oscillator in Hz.
+  #define HSI_VALUE    ((uint32_t)16000000U) /*!< Default value of the Internal oscillator in Hz.
                                                 This value can be provided and adapted by the user application. */
 #endif /* HSI_VALUE */

Hi @yn386,

Thank you for you contribution. The issue you pointed out is confirmed. Indeed, the HSI value should be 16MHz rather than 8MHz. The proposed fix is thus approved it will be implemented and made available in the frame of a future release.

With regards,

ST Internal Reference: 134336

Hello @yn386 ,

The fix has been implemented and is now available in the frame of the latest STM32CubeL1 package V1.10.4 release. This issue can be closed now. Thank you again for your contribution.

With Regards,