cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX LL_ADC_SetCommonPathInternalCh generation bug - only one internal ch is enabled

kurta999
Senior

I can't measure tempsensor with vbat and vref because cubemx generates low layer code in the following order:

LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_TEMPSENSOR);
  LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_TEMPSENSOR, LL_ADC_SAMPLINGTIME_640CYCLES_5);
  LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_TEMPSENSOR, LL_ADC_SINGLE_ENDED);
  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR);
  /** Configure Regular Channel 
  */
  LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_7, LL_ADC_CHANNEL_VREFINT);
  LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_VREFINT, LL_ADC_SAMPLINGTIME_640CYCLES_5);
  LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_VREFINT, LL_ADC_SINGLE_ENDED);
  LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_VREFINT);  // Previously enabled tempsensor bit get overwritten here and only internal vrefint channel is enabled.. I took a few hours until I figured out why ny MCU temp measuring module isn't works since I ported my ADC to HAL from LL

Finaly result is only vrefint is enabled and tempsensor is disabled. CubeMX should use logical OR in this case. In HAL it is implemented correctly, but this implementation missing from LL.

Solution is:

LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_PATH_INTERNAL_VREFINT);

14 REPLIES 14
kurta999
Senior

Any news on this? I'm working with F4 now and it's also present here not only for L4.

Just wasted a few hours on this, so it STILL isn't fixed.

This (generated by CubeMX) does not work:

LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR);
 
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_VREFINT);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_VREFINT);

But this does:

LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR);
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_VREFINT);
 
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR | LL_ADC_PATH_INTERNAL_VREFINT);

t.decker
Senior II

Any news on this? I'm working with the up-to-date framework / tools and still not fixed for F7.

(Same bug reported here: https://community.st.com/s/question/0D50X0000C20aDzSQI/bug-cubemx-550-stm32g0-wrong-setcommonpathinternalch-initialization )

Edit: On the F767xx this a bit more complicated. While chapters 15.10 and 15.11 of the reference manual (RM0410) state that only VBAT and internal temperature sensor can't be used at the same time.

Reality shows and register description of ADC_CCR state that VBAT can't be used with temperature sensor OR VREFINT at the same time.

I suggest a fix of the reference manual (update the chapter 15.11 note) and maybe a warning when generating invalid combinations with CubeMX.

When this account seems to be inactive, try @tdecker2 - ST can't change mail addresses, so I had to create a new account.
Motla1
Associate II

@Khouloud ZEMMELI​ Any news on this ?? It's crazy that it has to take ST more than 4 years to correct such a simple bug like this... Very annoying for anybody during all this time who spend hours to understand what is wrong with your libraries, because someone doesn't want to correct it.

@Motla​ , First I want to apologize for the delay made to fix this issue, @Khouloud OTHMAN​ Could you please take in charge the follow up of that issue (or one of the support team) as I don't work on support anymore?