Is CubeMX config generating an overrun error when using ADC peripheral with DMA ?
I'm using an STM32F446RE nucleo-64 board with STM32CubeIDE.
I was testing a potentiometer and noticed that the default code generated by cubeMX leads to an overrun error in the ADC peripheral. The issue can be manually solved by calling MX_DMA_Init() before MX_ADC1_Init() in main.c.
To reproduce the issue, my configuration on the CubeMX interface is as follows:
- ADC1_channel0 enabled.
- DMA2 stream 0 in peripheral to memory, circular mode.
- DMA and continous mode enabled.
- Only 1 regular conversion.
- sampling time of 480 cycles per conversion.
In main(), the regular conversion is triggered by HAL_DMA_START() just before the while loop.
This works as expected :
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_DMA_Init(); // Has been moved manually before MX_ADC1_Init();
MX_ADC1_Init();
if (HAL_ADC_Start_DMA(&hadc1, g_raw_adc_reading, BUFLENGTH) != HAL_OK)
Error_Handler();
while (1)
{
}
}But if line 9 & 10 are inverted, as generated by cubeMX, the overrun flag will be set in the ADC1 status register. Unless I am missing something on the HAL library.
