Skip to main content
BMcDo.3
Associate III
January 26, 2022
Solved

TIM-triggered periodic ADC capture w/ DMA

I'm trying to do a periodic ADC capture on 2 channels, triggered by TIM5. ADC should output to memory via DMA, with a DMA interrupt upon each completion to read the data from each scan.

So far, the DMA interrupts aren't hitting, and the ADC doesn't even appear to be reading anything. Any ideas what I'm missing?

TIM5_CC4 outputs on a GPIO. ADC captures should be synced with that, so I'm trying to use TIM5_CC3 to trigger the ADC.

Code was generated by STM32CubeMX 6.1.1, with STM32F4 package 1.25.2. (MX_DMA_Init() is called before MX_ADC1_Init().)

CubeMX Project Screenshots

0693W00000JNQtTQAX.png 

0693W00000JNQtiQAH.png 

0693W00000JNQtsQAH.png 

0693W00000JNQtxQAH.png 

0693W00000JNQu7QAH.png 

0693W00000JNQuCQAX.png 

0693W00000JNQuRQAX.png 

0693W00000JNQugQAH.png 

0693W00000JNQv0QAH.png 

0693W00000JNQtPQAX.png 

Code Excerpts

Order of some relevant function calls:

// in main():
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_DMA_Init();
 
 // elsewhere, after OS starts:
 MX_ADC1_Init();

 EDIT: Added relevant code excerpts as attachments.

This topic has been closed for replies.
BMcDo.3
BMcDo.3Best answer
Associate III
January 28, 2022

Thanks for your help.

On further investigation, I see no sanctioned way with the (non-LL) HAL to enable the channels before starting the PWM output.

I'm working around the issue by (ab)using the private function TIM_CCxChannelCmd(). I've replaced

 TIM_CCxChannelCmd(htim5.Instance, TIM_CHANNEL_4, TIM_CCx_ENABLE);

with

 TIM_CCxChannelCmd(htim5.Instance, TIM_CHANNEL_3, TIM_CCx_ENABLE);
 TIM_CCxChannelCmd(htim5.Instance, TIM_CHANNEL_4, TIM_CCx_ENABLE);
 
 HAL_TIM_Base_Start(&htim5);

EDIT: the DMA interrupts aren't correct yet. The interrupt gets hammered for a while, then isn't called anymore. I think the ADC config isn't correct. But I'm over the main roadblock now.

9 replies

KnarfB
Super User
January 26, 2022

use the timer update event for TRGO, not the reset event.

BMcDo.3
BMcDo.3Author
Associate III
January 26, 2022

Changed as specified. Problem persists, i.e. HAL_ADC_ConvCpltCallback() still isn't called.

0693W00000JNSDPQA5.png0693W00000JNSF1QAP.png 

KnarfB
Super User
January 27, 2022

Here is a working project for an F0.

Did you start

 HAL_TIM_Base_Start(&htim1);
 HAL_ADC_Start_DMA(&hadc, (uint32_t*)adc_buf, ADC_BUF_LEN);

hth

KnarfB

waclawek.jan
Super User
January 26, 2022

Which STM32?

Read out and check/post TIM, ADC and DMA registers content.

JW