Skip to main content
DNYAR.1
Associate II
March 24, 2026
Solved

VREFBUF configuring based on GPIO state with CubeMx

  • March 24, 2026
  • 2 replies
  • 270 views

I am using a G474RE nucleo board and i have 2 separate interface boards which i ca connect to it.

One board requires a VREFBUS of 2.5V and the other  2.90 .

Currently i modify the .IOC file and select the appropriate VREFBUS, compile the code. So currently i have 2 separate .elf files, one for each scenario.

I will want a single code version so that on start up based on the status of a switch connected to a GPIO,

it will configure the correct VREFBUF value.

The attachment shows my setup for the 2.90V internal voltage reference.

Thanks

Davidg474re_vrefbuf_2900mv.jpg

 

Best answer by mƎALLEm

@DNYAR.1 wrote:

I do not see where the appropriate cubeMX code is created. It is not in my main.c file (like the other peripheral initializations).

Is there another file i need to look into for that?

Thanks


A thread related to the same subject you've already created in 2023 Example code to configure internal Vrefbuf on STM32G474RE (Nucleo -G474RE) ;)

screenshot.png

2 replies

mƎALLEm
Technical Moderator
March 24, 2026

Hello,

That's not possible to set two configurations for two different voltage reference in CubeMx.

You need to do that in the user code i.e. configure the VREFBUF in the user code section based on the GPIO state.

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
DNYAR.1
DNYAR.1Author
Associate II
March 24, 2026

Sorry i did not come across clearly. What i want is user code to set that up using a GPIO pin to select between the

2 possible internal buffer voltages.

 

mƎALLEm
Technical Moderator
March 24, 2026

In the user code:

if (GPIO_pin_status == SET)
{
configure VREF_Buff to 2.5
}
else
{
configure VREF_Buff to 2.9
}
 

Generate the code with cubeMx for both configurations and paste the VREFBUF config related code in the respective condition.

And here is a thread related to the same subject you've already created in 2023 Example code to configure internal Vrefbuf on STM32G474RE (Nucleo -G474RE)

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
DNYAR.1
DNYAR.1Author
Associate II
March 24, 2026

I do not see where the appropriate cubeMX code is created. It is not in my main.c file (like the other peripheral initializations).

Is there another file i need to look into for that?

Thanks