cancel
Showing results for 
Search instead for 
Did you mean: 

ADC clock misconfiguration on F091 ?

christoph riehl
Associate II

Hello,

it seems cube 5.3.0 generates broken code for the ADC config.

the ADC_InitStruct.Clock is never written to CFGR2, and CFGR2 is never written.

Any suggestion why ? is this a problem from Cube code generation ?

in adc.c : 

in adc.c :   ADC_InitStruct.Clock = LL_ADC_CLOCK_SYNC_PCLK_DIV4;
..
  LL_ADC_Init(ADC1, &ADC_InitStruct);

then stm32f0xx_ll_adc.c :

ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
{
  ErrorStatus status = SUCCESS;
  
  /* Check the parameters */
  assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  
  assert_param(IS_LL_ADC_CLOCK(ADC_InitStruct->Clock));
  assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
  assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
  assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode));
  
  /* Note: Hardware constraint (refer to description of this function):       */
  /*       ADC instance must be disabled.                                     */
  if(LL_ADC_IsEnabled(ADCx) == 0U)
  {
    /* Configuration of ADC hierarchical scope:                               */
    /*  - ADC instance                                                        */
    /*    - Set ADC data resolution                                           */
    /*    - Set ADC conversion data alignment                                 */
    /*    - Set ADC low power mode                                            */
    MODIFY_REG(ADCx->CFGR1,
                 ADC_CFGR1_RES
               | ADC_CFGR1_ALIGN
               | ADC_CFGR1_WAIT
               | ADC_CFGR1_AUTOFF
              ,
                 ADC_InitStruct->Resolution
               | ADC_InitStruct->DataAlignment
               | ADC_InitStruct->LowPowerMode
              );
    
  }
  else
  {
    /* Initialization error: ADC instance is not disabled. */
    status = ERROR;
  }
  return status;
}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

It appears to be correct in the latest repository version:

https://github.com/STMicroelectronics/STM32CubeF0/blob/568c7255f77258c12ac876745f53ce76a682259f/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c#L372

    MODIFY_REG(ADCx->CFGR2,
               ADC_CFGR2_CKMODE
              ,
               ADC_InitStruct->Clock
              );

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

It appears to be correct in the latest repository version:

https://github.com/STMicroelectronics/STM32CubeF0/blob/568c7255f77258c12ac876745f53ce76a682259f/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c#L372

    MODIFY_REG(ADCx->CFGR2,
               ADC_CFGR2_CKMODE
              ,
               ADC_InitStruct->Clock
              );

If you feel a post has answered your question, please click "Accept as Solution".
christoph riehl
Associate II

Thank you !

Yes, it seems ST has already solved it.