2018-08-31 05:22 AM
Hello,
i want to use 3 ADC :
-ADC1 et ADC2 in Dual regular simultaneous mode + trigger on timer +DMA
-ADC3 on its own in continuous mode + DMA.
According to reference manuel,for DMA :
-ADC1 can use channel0 + stream0
-ADC2 can use channel1 + stream2
-ADC3 can use channel2 + stream1
Is it mandatory to program explicitely the DMA ? (cubemx doesn't call HAL_DMA_Init function)
Do i need to do the following initialization :
g_DmaHandleADC1.Instance = DMA2_Stream0;
g_DmaHandleADC1.Init.Channel = DMA_CHANNEL_0;
g_DmaHandleADC1.Init.Direction = DMA_PERIPH_TO_MEMORY;
g_DmaHandleADC1.Init.PeriphInc = DMA_PINC_DISABLE;
g_DmaHandleADC1.Init.MemInc = DMA_MINC_ENABLE;
g_DmaHandleADC1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
g_DmaHandleADC1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
g_DmaHandleADC1.Init.Mode = DMA_NORMAL; //DMA_CIRCULAR;
g_DmaHandleADC1.Init.Priority = DMA_PRIORITY_HIGH;
g_DmaHandleADC1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
g_DmaHandleADC1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
g_DmaHandleADC1.Init.MemBurst = DMA_MBURST_SINGLE;
g_DmaHandleADC1.Init.PeriphBurst = DMA_PBURST_SINGLE;
HAL_DMA_Init(&g_DmaHandleADC1);
__HAL_LINKDMA(&hadc1, DMA_Handle, g_DmaHandleADC1);
g_DmaHandleADC2.Instance = DMA2_Stream0;
g_DmaHandleADC2.Init.Channel = DMA_CHANNEL_2;
g_DmaHandleADC2.Init.Direction = DMA_PERIPH_TO_MEMORY;
g_DmaHandleADC2.Init.PeriphInc = DMA_PINC_DISABLE;
g_DmaHandleADC2.Init.MemInc = DMA_MINC_ENABLE;
g_DmaHandleADC2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
g_DmaHandleADC2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
g_DmaHandleADC2.Init.Mode =DMA_NORMAL; //DMA_CIRCULAR;
g_DmaHandleADC2.Init.Priority = DMA_PRIORITY_HIGH;
g_DmaHandleADC2.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
g_DmaHandleADC2.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
g_DmaHandleADC2.Init.MemBurst = DMA_MBURST_SINGLE;
g_DmaHandleADC2.Init.PeriphBurst = DMA_PBURST_SINGLE;
HAL_DMA_Init(&g_DmaHandleADC2);
__HAL_LINKDMA(&hadc2, DMA_Handle, g_DmaHandleADC2);
g_DmaHandleADC3.Instance = DMA2_Stream0;
g_DmaHandleADC3.Init.Channel = DMA_CHANNEL_1;
g_DmaHandleADC3.Init.Direction = DMA_PERIPH_TO_MEMORY;
g_DmaHandleADC3.Init.PeriphInc = DMA_PINC_DISABLE;
g_DmaHandleADC3.Init.MemInc = DMA_MINC_ENABLE;
g_DmaHandleADC3.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
g_DmaHandleADC3.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
g_DmaHandleADC3.Init.Mode = DMA_NORMAL; //DMA_CIRCULAR;
g_DmaHandleADC3.Init.Priority = DMA_PRIORITY_HIGH;
g_DmaHandleADC3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
g_DmaHandleADC3.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
g_DmaHandleADC3.Init.MemBurst = DMA_MBURST_SINGLE;
g_DmaHandleADC3.Init.PeriphBurst = DMA_PBURST_SINGLE;
HAL_DMA_Init(&g_DmaHandleADC3);
__HAL_LINKDMA(&hadc3, DMA_Handle, g_DmaHandleADC3);
best regards
thanks
2018-09-18 01:56 AM
Hi @Professional ,
You need to configure DMA in STM32CubeMX, then the initialization code for DMA will be added.
You need to check both main.c file as well as the generated stm32xxxx_hal_msp.c file.
-Amel
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.
2018-09-21 06:29 AM
Hello
thank you very much for your reply : i was just looking at main.c
I have programmed ADC1 + ADC2 in Dual regular simultaneous mode and continuous mode, and i validated DMA2 stream0 and stream2 global interrupt in CubeMX
1) If i call the HAL_ADC_Start_DMA (&hadc1, (uint32_t *) &aADCxConvertedData[0], ADC_CONVERTED_DATA_BUFFER_SIZE );
will it start the ADC1 and ADC2 in continuous mode (has just handle for ADC1 is given) ?
2) in the function void DMA2_Stream0_IRQHandler() can i get the data from ADC1 conversion (in aADCxConvertedData array)
3) in the function void DMA2_Stream2_IRQHandler() can i get the data from ADC2 conversion : where are they placed in my aADCxConvertedData array ?
thanks
regards