cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX 6.11.0 and STM32CubeIDE 1.15.1: bug in generated MX_ADC1_Init() function

SOfne.1
Associate III

Used STM32CubeIDE version: 1.15.1
Used driver library: STM32Cube_FW_G0_V1.6.2, LowLevel-Drivers
Microcontroller STM32G070xx

 

I found a bug in the generated MX_ADC1_Init() function. The delay loop index variable misses the volatile keyword. Consequently with optimization turned on the loop is optimized away and the delay is shorter than expected. This may lead to unexpected ADC errors, for example if the calibration is performed directly after MX_ADC1_Init().

void MX_ADC1_Init(void)
{
...
/* Enable ADC internal voltage regulator */
LL_ADC_EnableInternalRegulator(ADC1);
/* Delay for ADC internal voltage regulator stabilization. */
/* Compute number of CPU cycles to wait for, from delay in us. */
/* Note: Variable divided by 2 to compensate partially */
/* CPU processing cycles (depends on compilation optimization). */
/* Note: If system core clock frequency is below 200kHz, wait time */
/* is only a few CPU processing cycles. */
volatile uint32_t wait_loop_index;    // <-- volatile at the beginning of this line is missing in the generated code
wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10);
while(wait_loop_index != 0)
{
wait_loop_index--;
}
...
}

As far as I can see in the release notes of the new STM32CubeIDE v1.16.0 this problem has not been fixed yet.

1 REPLY 1
SofLit
ST Employee

Hello @SOfne.1 ,

I'm escalating your feedback internally. I will get back to you as soon as I have an internal feedback.

Internal Ticket: 186041

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.