Skip to main content
Visitor II
November 1, 2023
Solved

Example code to configure internal Vrefbuf on STM32G474RE (Nucleo -G474RE)

  • November 1, 2023
  • 1 reply
  • 1995 views

Is there an example code to configure the internal VREFBUF on the STMG474RE (Nuclo-G474RE board).

 to output for example 2.5V to be used by the ADCs. I do not want to use the external reference on the board.

Thanks

David

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    Example code is generated by STM32CubeMX, if you set the VREFBUF Mode in the peripheral module SYS to Internal voltage reference and then set the Internal Voltage reference scale in Parameter Settings to SCALE 1: around 2.5V. The STM32G474 will then be generated correctly in stm32g4xx_hal_msp.c, function HAL_MspInit():

    __HAL_RCC_SYSCFG_CLK_ENABLE(); // necessary so that SYSCFG can be configured and switched on
    [...]
    
    /* System interrupt init */
    /** Configure the internal voltage reference buffer voltage scale */
    // for SYSCFG_VREFBUF_VOLTAGE_SCALE1 see RM0440, section 23.4.1, bits VRS
    HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);
    
    /** Enable the Internal Voltage Reference buffer */
    HAL_SYSCFG_EnableVREFBUF();
    
    /** Configure the internal voltage reference buffer high impedance mode */
    HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
    

    Hope that helps?

    Regards
    /Peter

    1 reply

    Technical Moderator
    November 1, 2023

    Example code is generated by STM32CubeMX, if you set the VREFBUF Mode in the peripheral module SYS to Internal voltage reference and then set the Internal Voltage reference scale in Parameter Settings to SCALE 1: around 2.5V. The STM32G474 will then be generated correctly in stm32g4xx_hal_msp.c, function HAL_MspInit():

    __HAL_RCC_SYSCFG_CLK_ENABLE(); // necessary so that SYSCFG can be configured and switched on
    [...]
    
    /* System interrupt init */
    /** Configure the internal voltage reference buffer voltage scale */
    // for SYSCFG_VREFBUF_VOLTAGE_SCALE1 see RM0440, section 23.4.1, bits VRS
    HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);
    
    /** Enable the Internal Voltage Reference buffer */
    HAL_SYSCFG_EnableVREFBUF();
    
    /** Configure the internal voltage reference buffer high impedance mode */
    HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
    

    Hope that helps?

    Regards
    /Peter

    DNYAR.1Author
    Visitor II
    November 1, 2023

    Hi Peter,

    Thanks a lot. 

    David