AnsweredAssumed Answered

CubeMX STM32L476 Injected ADC Configuration Incorrect

Question asked by Rich Hanna on Jan 29, 2018

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:

 

#define 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.

Outcomes