AnsweredAssumed Answered

STM32F1x ADC+DMA dual regular simultaneous mode. 3 bugs

Question asked by Jurijs Varnels on Oct 30, 2017
Latest reply on Feb 13, 2018 by Jeanne Joly

This discussion is more like a bug report than a help request. Therefore it would be nice, if these bugs could be confirmed and fixed;


These bugs appears, when I use  ADC "dual regular simultaneous mode", using DMA transfers (created using as reference AN3116). Used MCU = STM32F103VET6; Code generated using STM32CubeMX, v.4.18.0. Used libraries: STM32Cube FW F1 V1.6.0.

I scan 5 channels for ADC1 and 5 channels for ADC2.


As result, when I Build and run auto-generated code, adding just few lines:


HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t*)dmaAdcBuff, DMA_ADC1_BUFF_SIZE);


, the first bug appeared:
1) inside MX_ADC2_Init(); function there is expression:

if (HAL_ADCEx_MultiModeConfigChannel(&hadc2, &multimode) != HAL_OK)


which always leads to Error_Handler(); for ADC2


My Solution for bug #1 was just deleting this piece of code; 


2) Later, when I managed to make my code run continously, second bug appears (don't know, if it's dependent on my "fix" above, whether it's independent). This bug is that function 

HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t*)dmaAdcBuff, DMA_ADC1_BUFF_SIZE);
returns with no result (I mean, it does not do, what it should, because it returns with Error)


My solution for bug #2 was adding following lines of code:

 hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
if (HAL_ADC_Init(&hadc2) != HAL_OK) {


before HAL_ADCEx_MultiModeStart_DMA(...); function (IMHO its epic fail that CubeMX haven't generated hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START; line)


3) Later, when I managed to launch DMA transfers, and see that buffer updates, third bug appears: looks like ADC2 is not working: all channels of ADC1 ar filled correctly; ADC2 all channels have same value.


My solution for bug #3 was: add code piece :

hadc2.Instance->CR2 |= ADC_CR2_EXTTRIG;

before HAL_ADCEx_MultiModeStart_DMA(...); function



CubeMX and HAL libraries make life easier, but in specific modes it can bring lots of trouble and misunderstanding, if there is no appropriate code examples...
(I was porting my project from StdPeripheral Library to HAL, and there were no problems in old lib =). moreover, actually, old lib with its examples helped me a lot to find the third bug.  )