cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX STM32L476 Injected ADC Configuration Incorrect

Rich Hanna
Associate
Posted on January 29, 2018 at 22:00

STM32CubeMX Version: 4.23.0

STM32L4 Firmware Package Version: 1.10.0

When creating an EWARM project with injected ADC channels targeting the STM32L476, the JSQR register is not properly configured by HAL_ADCEx_InjectedConfigChannel(). In particular, the ADC_JSQR_RK macro is incorrect.

The macro in its current form is:

&sharpdefine ADC_JSQR_RK(__CHANNELNB__, __RANKNB__) ((((__CHANNELNB__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << ((__RANKNB__) & ADC_INJ_RANK_ID_JSQR_MASK))

The final shift of:

((__RANKNB__) & ADC_INJ_RANK_ID_JSQR_MASK)

is incorrect given that HAL_ADCEx_InjectedConfigChannel() expects the rank to be a normal integer, and instead should be something like:

(((((__RANKNB__) & ADC_INJ_RANK_ID_JSQR_MASK)-1) * (ADC_INJ_RANK_2_JSQR_BITOFFSET_POS - ADC_INJ_RANK_1_JSQR_BITOFFSET_POS)) + ADC_INJ_RANK_1_JSQR_BITOFFSET_POS)

I do not know if other targets are affected by this issue.

Is any more information needed on this? Hope this helps.

#stm32l476-adc #injected-conversion
0 REPLIES 0