cancel
Showing results for 
Search instead for 
Did you mean: 

Bug report Stm32cubeMX ADC initialization code( Cube v4.6.0/stm32f1xx_hal_adc.c(v1.0.0)

christer
Associate
Posted on March 17, 2015 at 13:51

Hi,

I'm quite new to Stm32 development and tried cube for the first time last weekend,

I'm using the STM32VLDISCOVERY board, (which by the way was not in the available list of predefined boards in Cube)  (but selecting the MCU STM32F100RBTx it works)

But, the bug that I found was when I tried to enable ScanConvMode to receive values from several ADC channels. But only the first (rank1) channel got converted.. 

And the reason to this was the mismatch between Cube generated ADC initialization value for enabling ScanConvMode, and the expected value in the driver..

in the Cube generated adc.h

  hadc1.Init.ScanConvMode =

ENABLE

;

But in the driver it' expects the value 

ADC_SCAN_ENABLE

in HAL_ADC_Init:

    if (hadc->Init.ScanConvMode ==

ADC_SCAN_ENABLE

)

    {

      tmp_sqr1 = ADC_SQR1_L_SHIFT(hadc->Init.NbrOfConversion);

    }

And since 

ADC_SCAN_ENABLE  

!= 

ENABLE 

The number of conversions is never read, and thus only the first channel in converted..

Since it was the first time trying stm32 it took me half a weekend to realize that the fault was not in my code but in the generated.. =(

/Christer

Edit:  

https://my.st.com//public/STe2ecommunities/mcu/Lists/STM32Java/STMCubeMX%20Incorrect%20ADC%20generation%20for%20STM32103CBT6

#adc-scanmode-stm32-stm32f1xx
3 REPLIES 3
raptorhal2
Lead
Posted on March 17, 2015 at 16:05

Same situation for CubeMXL1

In stm32l1xx_hal.adc.c:

if (hadc->Init.ScanConvMode == ADC_SCAN_ENABLE)

And in main.c    void MX_ADC_Init (void)

hadc.Init.ScanConvMode = ENABLE;

It's probably worthwhile for ST to check all Cube versions.

Regards, Hal

raptorhal2
Lead
Posted on March 18, 2015 at 02:29

Upon further investigation:

DISABLE is always defined to be = 0.

ENABLE is defined to be !0.

ADC_SCAN_ENABLE is defined to be 1.

So if ENABLE is set to 1, it  can be = ADC_SCAN_ENABLE, and that is the case for MX_ADC_Init.

Is your IDE using some other value for ENABLE ?

But it is confusing and open to error if two different definitions are used.

Cheers, Hal

 

stm32cube-t
Senior III
Posted on March 18, 2015 at 10:43

Please note this issue will be corrected with MX 4.7.