cancel
Showing results for 
Search instead for 
Did you mean: 

Dma not working when triggered from timer trigger from external source start a DMA transfer on UART or SPI peripheral on STM32F411?

Ahmed Nabih
Associate II

I am using STM32F411 and SDK v1.27.1

I am trying to trigger an DMA xfer with an external signal source using the TIMER1 External Trigger, without the need to execute any interrupts in the CPU to utilize the CPU time, as I have two signals one every 2ms and one every 150us that come from to different on board ICs, and when each signal is executed an SPI/UART xfer must be done to retrieve data in real-time.

I have used the code generator from the CubeIDE to generate Initialization code, an started the transfer in the main function

Here is the pinout view of the project

0693W00000QLM9zQAH.pngTimer1 Conig.

0693W00000QLMA4QAP.png0693W00000QLMAdQAP.png0693W00000QLMA9QAP.png 

USART1 Config.

0693W00000QLMAxQAP.png 

Code Snippets

#define BUFF_SIZE         8
uint32_t dma_TxBuffer[BUFF_SIZE] = {0};
uint32_t dma_RxBuffer[BUFF_SIZE] = {0};
 
HAL_TIM_Base_Start(&htim1);
 
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_TC);
 
/* Enable the DMA transfer for transmit request by setting the DMAT bit
   in the UART CR3 register */
ATOMIC_SET_BIT(huart2.Instance->CR3, USART_CR3_DMAT);
 
HAL_DMA_Start(&hdma_tim1_trig, (uint32_t)dma_TxBuffer, (uint32_t)&huart2.Instance->DR, BUFF_SIZE);

After debugging the code I found that the DMA register does not move the data at all

any help?

thanks

1 ACCEPTED SOLUTION

Accepted Solutions

I don't use Cube/CubeMX, but it appears that you have set the slave-mode controller to clock the timer from the ETR pin. This will not generate Trigger events in the timer.

But ou don't need the Trigger events at all. Connect the external signal to some timer channel pin, set that channel to Input Capture, and set DMA to be triggered from the Capture event (TIMx_DIER.CCxDE).

JW

View solution in original post

6 REPLIES 6

I don't use Cube/CubeMX, but it appears that you have set the slave-mode controller to clock the timer from the ETR pin. This will not generate Trigger events in the timer.

But ou don't need the Trigger events at all. Connect the external signal to some timer channel pin, set that channel to Input Capture, and set DMA to be triggered from the Capture event (TIMx_DIER.CCxDE).

JW

I looked up the Timer1 section in the reference manual and a dma trigger event can be generated from external trigger

0693W00000QLMnGQAX.jpg

Yes it can, but then you have to set up the Slave-mode controller to be in Trigger mode.

Read out and check TIMx_SMCR to see.

JW

Sara BEN HADJ YAHYA
ST Employee

Hello @Ahmed Nabih​ ,

Thanks for your feedback,

Please check the DMA inti order in Project Manager-> Advanced Settings, it has to be called before TIM1 init call (please refer to the attached screenshot )

0693W00000QLRC5QAP.pngIf you are using CubeMX v6.5.0 or lower and in case the DMA init is called after the TIM inti, you need to apply the Workaround mentioned in this thread MX_DMA_Init order in the main.c file generated by STM32CubeMX, How to fix?

I hope this helps !

If your issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly 🙂

Sara.

I checked, but the init is done in it's right stages

thanks

A.Nabih

Thank you

You solved my problem