cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 ADC1 DMA Works while ADC3 DMA does nothing

Duddie
Associate II

So I have two channels configured basically with same settings. ADC1 works fine and DMA gets triggered and handled well. ADC3 DMA refuses to trigger any interrupt (not even an Error). The only difference is that ADC1 handles 14 channels while ADC3 handles 2 channels, But reducing ADC1 to 2 channels didn't make any difference (ADC1 was still OK while ADC3 DMA wasn't working). ADC3 works well in polling mode without any problems. Any suggestions?

Below code for ADC3 (all settings for ADC1 are identical).

Thanks in advance!!!

hadc3.Instance = ADC3;
  hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8;
  hadc3.Init.Resolution = ADC_RESOLUTION_12B;
  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc3.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  hadc3.Init.LowPowerAutoWait = DISABLE;
  hadc3.Init.ContinuousConvMode = DISABLE;
  hadc3.Init.NbrOfConversion = 2;
  hadc3.Init.DiscontinuousConvMode = DISABLE;
  hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
  hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_4;
  hadc3.Init.OversamplingMode = DISABLE;
  if (HAL_ADC_Init(&hadc3) != HAL_OK)

And DMA:

__HAL_RCC_ADC3_CLK_ENABLE();
 
    __HAL_RCC_GPIOC_CLK_ENABLE();
 
   // disabling below two lines has no effect
    HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PC2, SYSCFG_SWITCH_PC2_OPEN);
    HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PC3, SYSCFG_SWITCH_PC3_OPEN);
 
    /* ADC3 DMA Init */
    /* ADC3 Init */
    hdma_adc3.Instance = DMA2_Stream7;
    hdma_adc3.Init.Request = DMA_REQUEST_ADC3;
    hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_adc3.Init.MemInc = DMA_MINC_ENABLE;
    hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
    hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
    hdma_adc3.Init.Mode = DMA_CIRCULAR;
    hdma_adc3.Init.Priority = DMA_PRIORITY_LOW;
    hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_adc3) != HAL_OK)

3 REPLIES 3
TDK
Guru

I don't think there are any errors in the code you posted.

I would open up the peripheral viewer and see if the appropriate registers are set correctly. Compare settings between working ADC1 and not working ADC3.

If you feel a post has answered your question, please click "Accept as Solution".
Duddie
Associate II

After googling I found a suggestion to enable FIFOMODE and set FIFO THRESHOLD to 3/4 for BOTH DMA channels. When setting on single channel it changed nothing while setting on BOTH channels it did the MAGIC and both channels now seem to work as expected. The trouble is that it has not been explained WHY. Need to do more digging into the Reference Manual.

Excessive sample rate and large RAM access latency, resulting in DMA overload?

> ADC3 DMA refuses to trigger any interrupt (not even an Error)

Then something is rotten as ADC3 should've overrun; but given you've apparently just clicked, it's not much of a surprise.

JW