Skip to main content
OGhis
Senior
Aug 21, 2019 7:53 PM UTC
Question

BUG: Incorrect HSE clock (STM32G474)

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

This topic has been closed for replies.

2 replies

WTom
Associate III
Aug 24, 2019 10:35 PM UTC

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

Piranha
Principal III
Aug 25, 2019 4:45 AM UTC

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.