cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 ADC3 is set to 10 bit mode when 12 bit is selected (LL code generator) CubeIDE 1.6.1

Remon Dijkstra
Associate II

LL Code generated by the CubeMX:

ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B;
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
LL_ADC_Init(ADC3, &ADC_InitStruct);

The define "LL_ADC_RESOLUTION_12B" should be value "0" (as per ADC3 datasheet).

However it seems to use the ADC12 define which results in value "2":

/** @defgroup ADC_LL_EC_RESOLUTION  ADC instance - Resolution
  * @{
  */
#define LL_ADC_RESOLUTION_16B              (0x00000000UL)                                      /*!< ADC resolution 16 bits */
#define LL_ADC_RESOLUTION_14B              (                                  ADC_CFGR_RES_0)  /*!< ADC resolution 12 bits */
#define LL_ADC_RESOLUTION_12B              (                 ADC_CFGR_RES_1                 )  /*!< ADC resolution 12 bits */
#define LL_ADC_RESOLUTION_10B              (                 ADC_CFGR_RES_1 | ADC_CFGR_RES_0)  /*!< ADC resolution 10 bits */

1 ACCEPTED SOLUTION

Accepted Solutions
Philippe Cherbonnel
ST Employee

Hi @Remon Dijkstra​ ,

STM32H7 serie has 2 lines differing for ADC:

- STM32H73x with ADC1/2 16 bits and ADC3 12 bits

- other STM32H7xx devices with all ADC instances 16 bits

I assume you are using device STM32H73x.

For code genericity, literals LL_ADC_RESOLUTION_xx are corresponding to configuration of ADC 16 bits and are not directly applicable to ADC 12 bits.

Then, for ADC3 12 bits, the adaptation is done by function:

__STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)

{

#if defined(ADC_VER_V5_3)

<Case of STM32H7xx devices with all ADC instances 16 bits>

<apply setting for ADC 16 bits>

#elif defined(ADC_VER_V5_V90)

<Case of STM32H73x with ADC1/2 16 bits and ADC3 12 bits>

 if (ADCx == ADC3)

 {

  <apply setting for ADC 12 bits (adapt LL literals for this ADC version)>

  MODIFY_REG(ADCx->CFGR, ADC3_CFGR_RES, (((Resolution & 0x10UL) | 0x08UL | (Resolution & 0x04UL)) & 0x00000018UL));

 }

 else

 {

  <apply setting for ADC 16 bits>

 }

#endif

}

Best regards

Philippe

View solution in original post

6 REPLIES 6
Remon Dijkstra
Associate II

Can anyone confirm this?

Philippe Cherbonnel
ST Employee

Hi @Remon Dijkstra​ ,

STM32H7 serie has 2 lines differing for ADC:

- STM32H73x with ADC1/2 16 bits and ADC3 12 bits

- other STM32H7xx devices with all ADC instances 16 bits

I assume you are using device STM32H73x.

For code genericity, literals LL_ADC_RESOLUTION_xx are corresponding to configuration of ADC 16 bits and are not directly applicable to ADC 12 bits.

Then, for ADC3 12 bits, the adaptation is done by function:

__STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)

{

#if defined(ADC_VER_V5_3)

<Case of STM32H7xx devices with all ADC instances 16 bits>

<apply setting for ADC 16 bits>

#elif defined(ADC_VER_V5_V90)

<Case of STM32H73x with ADC1/2 16 bits and ADC3 12 bits>

 if (ADCx == ADC3)

 {

  <apply setting for ADC 12 bits (adapt LL literals for this ADC version)>

  MODIFY_REG(ADCx->CFGR, ADC3_CFGR_RES, (((Resolution & 0x10UL) | 0x08UL | (Resolution & 0x04UL)) & 0x00000018UL));

 }

 else

 {

  <apply setting for ADC 16 bits>

 }

#endif

}

Best regards

Philippe

Hi Philiippe,

I understand whats wrong.

I merely was indicating that CubeMX was generating faulty code.

The (LL) code generated by cubeMX is using that 16 bit define for a 12 bit convertor.

Kind regards,

Remon.

Houda GHABRI
ST Employee

Hi @Remon,

I understand that's can be a bit confusing but as mentioned by Philippe Cherbonnel CubeMX is generating a generic code that will work on all H7 Family, for the specific case of H73x which is containing a 12 Bit ADC a specific handling is done by LL to manage it.

If we take the full picture, init code + LL The generated code is correct.

Hope this helps you.

Houda

CA..1
Associate II

LL_ADC_SetResolution is not working either, since LL_ADC_RESOLUTION_12B is 0x08 and with (((Resolution & 0x10UL) | 0x08UL | (Resolution & 0x04UL)) & 0x00000018UL) is not what ADC3 expects to see, 00, the resolution bits 4-5.

Only manual setup works:

MODIFY_REG( ADC3->CFGR, ADC3_CFGR_RES, 0x00 ); //12 bit

Even if using LL, and some setup is allowed to be incomplete, it is not expected to have LL functions that pretend they should work and they actually do not work, for ADC3 on H73x.

This problem appears to be fixed in CubeMX v6.4.0. Thanks!