Skip to main content
Associate II
May 27, 2025
Solved

Generate a particular waveform using Timer-triggered DMA to drive a GPIO output

  • May 27, 2025
  • 1 reply
  • 512 views

I'm trying to use the DMA engine to drive a GPIO output port, with each update triggered by a timer to achieve a particular waveform. It's trying to run, but I'm getting a TEIF (transfer error flag) and not seeing anything on the GPIO pins. I can't figure out where the problem is.

My targets are:

1. Target Dest GPIO Port F (all 16 bits)

2. TIM4_CH2 (DMA1 -> Channel 2 -> Stream 3). Note that I also have TIM4_CH2 routed to an alternate pin function so I can view the timing, and it is working correctly.

3. Data source is Memory/Internal RAM buffer (uint16_t array)

Here are my register setups:

1) S3NDTR = 0x100 (number of transfers == internal RAM buffer size)

2) S3M0AR = 0x200000c0 (address of internal RAM buffer)

3) S3PAR = 0x40021414 (GPIO F's ODR register)

 

4) S3FCR = 0x21 (default reset val, leaving in direct mode)

5) S3CR = 0x4032c41

Other notes: I'm following the rules and setting up everything before enabling the "EN" bit. I've tried various combinations of fifo/direct mode, and also trying to change the array/dest size to 32-bits, but still no luck. The DMA1 reset bit is 0 and the DMA1 periph clock enable bit is 1 in the RCC. It wasn't super clear in the timer register section what the TIMx_DIER register needs to be set to, I assume just CC2DE needs to be enabled, but I've also tried UDE, TDE, and various combinations of them.

Any clues as to what I'm missing?

Best answer by TDK

DMA1 can't access GPIO. Use DMA2.

1 reply

TDK
TDKBest answer
Super User
May 27, 2025

DMA1 can't access GPIO. Use DMA2.

"If you feel a post has answered your question, please click ""Accept as Solution""."
stmcoderAuthor
Associate II
May 27, 2025

Thank you, I must have missed that detail in the reference manual.