Skip to main content
christoph riehl
Associate
September 9, 2020
Solved

ADC clock misconfiguration on F091 ?

  • September 9, 2020
  • 2 replies
  • 1312 views

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;
}

This topic has been closed for replies.
Best answer by TDK

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
 );

2 replies

TDK
TDKBest answer
Super User
September 9, 2020

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
September 10, 2020

Thank you !

Yes, it seems ST has already solved it.