Skip to main content
Shen
Associate II
April 2, 2022
Solved

CubeMX 6.5.0 code generation error when ADC enables temperature sensor�?Vref and Vbat channel(LL library)

  • April 2, 2022
  • 3 replies
  • 1068 views

Hello Everyone,

I am using STM32G474RE and the STM32CubeMX version is 6.5.0.

When ADC5 enables temperature sensor�?Vref and Vbat channel, STM32CubeMX will generate code in MX_ADC5_Init function(LL library):

/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_VREFINT);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SINGLE_ENDED);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VREFINT);
 
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_TEMPSENSOR_ADC5);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SINGLE_ENDED);
 
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_VBAT);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SINGLE_ENDED);
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VBAT);

I think there is a line of code missing after line 12:

LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_TEMPSENSOR);

Besides, calling LL_ADC_SetCommonPathInternalCh() function will clear the previous state, so I think it should be modified to this code:

/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_VREFINT);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SINGLE_ENDED);
 
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_TEMPSENSOR_ADC5);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SINGLE_ENDED);
 
/** Configure Regular Channel
*/
LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_VBAT);
LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SINGLE_ENDED);
 
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VBAT|LL_ADC_PATH_INTERNAL_VREFINT|LL_ADC_PATH_ INTERNAL_TEMPSENSOR);

​Best regards,

Shen

This topic has been closed for replies.
Best answer by Walid ZRELLI

Hello @Shen​ 

Thank you for your contribution.

This issue has been reported internally.

Internal ticket number: 126032 (PS: This is an internal tracking number and is not accessible or usable by customers)

BeST Regards,

Walid

3 replies

Walid ZRELLI
Visitor II
April 4, 2022

Hello Shen,

In order to allow a better analysis of your problem, could you please give us the .ioc file that you are used to reproduce this issue.

BeST Regards,

Walid

Shen
ShenAuthor
Associate II
April 5, 2022

Hello Walid,

Thank you for your reply, here is my .ioc file.

Walid ZRELLI
Walid ZRELLIBest answer
Visitor II
April 7, 2022

Hello @Shen​ 

Thank you for your contribution.

This issue has been reported internally.

Internal ticket number: 126032 (PS: This is an internal tracking number and is not accessible or usable by customers)

BeST Regards,

Walid