cancel
Showing results for 
Search instead for 
Did you mean: 

BUG: Incorrect HSE clock (STM32G474)

OGhis
Associate III

When using an external crystal in the MXcube for the STM32G474 mcu.

conditions:

Change High Speed Clock (HSE) to Crystal/Ceramic Resonator in the pinout & Configuration tab page

Change the input frequency to 16Mhz in the Clock configuration tab page

After generation the code, op the file 'system_stm32G4xx.c file.

The HSE_VALUE   isn't changed to 16000000U

#define HSE_VALUE     8000000U

2 REPLIES 2
WTom
Associate III

I found there was no clock initialization at all. You have to patch registers directly or use low level interface.

Piranha
Chief II

Guys, learn basic programming first...

https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Drivers/CMSIS/Device/ST/STM32G4xx/Source/Templates/system_stm32g4xx.c

#if !defined  (HSE_VALUE)
  #define HSE_VALUE     8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_conf_template.h

/* ########################## Oscillator Values adaptation ####################*/
/**
  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
  *        This value is used by the RCC HAL module to compute the system frequency
  *        (when HSE is used as system clock source, directly or through the PLL).
  */
#if !defined  (HSE_VALUE)
#define HSE_VALUE    (8000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

You (or CubeMX) have to adjust HSE_VALUE in file stm32g4xx_hal_conf.h or set it in a global project settings and that value will override predefined 8000000UL.