cancel
Showing results for 
Search instead for 
Did you mean: 

stm32cubemx generates incorrect code for internal voltage reference peripheral

AByc.1
Associate

code generated in cube mx contains several bugs in [stm32h7xx_hal_msp.c] source file:

  • in function HAL_MspInit, vref clock enabling is missing - __HAL_RCC_VREF_CLK_ENABLE
  • function HAL_SYSCFG_VREFBUF_HighImpedanceConfig shall be called before HAL_SYSCFG_EnableVREFBUF
  • in [stm32h7xx_hal.h] file, wrongly defined symbols for voltage scale, e.g. SYSCFG_VREFBUF_VOLTAGE_SCALE0 shall have value VREFBUF_CSR_VRS_OUT1 instead of wrong VREFBUF_CSR_VRS_OUT2 macro (description is ok)

this is my first post here, so hope, that written in good place

3 REPLIES 3
Khouloud ZEMMELI
ST Employee

Hello @AByc.1​ 

could you please share your ioc file?

Thanks

Khouloud

JimSChen.4
Associate II

Hi @Khouloud ZEMMELI​ ,

I am using stm32h745zi-q Nucleo-144 board and facing similar problem. When selecting internal voltage reference scale as SCALE 1: around 2.048V in cube mx (6.0.1), it does set the clock but still seem to generate the wrong code:

  •  HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1); looks like wrong. Shouldn't this SYSCFG_VREFBUF_VOLTAGE_SCALE1 be SYSCFG_VREFBUF_VOLTAGE_SCALE0 as per the macro define?
  • The order doesn't seem to be correct either: HAL_SYSCFG_EnableVREFBUF(); is called before the HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
  • Most problematic one is that waiting for VREFBUF_CSR_VRR never gets set. It times out to error return.

So my DAC's Vref is still 3.3V.

stm32cubeide is v1.4.2.

Any idea please? Thanks

JimSChen.4
Associate II

OK, on the Nucleo-144 board, the Vref is hardwired via the R39 resister to the VDD_MCU. With this, the Vref for both ADC/DAC is fixed. Removing (un-soldering) the R39 from the board got it working as expected.

It would be nice if the cubeMX can provide an info telling the designer when setting VREFBUF based on the board selection!

Yet the SYSCFG_VREFBUF_VOLTAGE_SCALE0/SYSCFG_VREFBUF_VOLTAGE_SCALE1 macro definitions are in wrong way round. SYSCFG_VREFBUF_VOLTAGE_SCALE0 is 2.048V whilst SYSCFG_VREFBUF_VOLTAGE_SCALE1 is 2.5V. So we will define our own in case stm changes this in the future.