cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4 : Timer triggered UART transmit with DMA

guptaniks
Associate II

Hi,

I need to synchronize my UART transmission with a timer using DMA. I don't want CPU intervention in fixed data transmission. 

My data and size is fixed. I need to continuously transmit the packet every 5ms.

kindly suggest!

6 REPLIES 6
TDK
Guru

How large is the data? If it's a single write, should be easy to set up with DMA. If it takes several writes, it will be a bit more complicated.

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

Data size is 4 bytes maximum.

 

TDK
Guru

> Data size is 4 bytes maximum.

So it can be packaged and sent as a uint32_t, since the STM32G4 has a TXFIFO on the UART. The peripheral will then send out the individual bytes.

 

Set up a timer to trigger DMA every update and set the destination address to be the UARTx->TXDR register. Not sure if CubeMX will let you set up everything in the gui, but it can be done in software.

UART should be set up, initialized and be ready to transmit before you start the DMA.

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

> So it can be packaged and sent as a uint32_t, since the STM32G4 has a TXFIFO on the UART. The peripheral will then send out the individual bytes.

I don't think this is possible, the UART does not have the data-packing feature SPI in 'G4 does (and even there you couldn't write it as words, only halfwords).

However, it should be possible to use a DMA of 4 byte transfers, requested from the DMAMUX's Request generator set to 4 requests, triggered from LPTIM1_OUT.

Another possibility would be using two timers in master-slave arrangement, master generating a gate signal each 5ms, the slave in gated mode running approximately at the byte-transmit rate generating the DMA requests, and the gate signal would be set up to last exactly 4 cycles of the slave timer. With careful timing, this could be pulled out even on older STM32 without FIFO in UART.

JW

 

@waclawek.jan You're right. It has a TXFIFO but no data packing. So many different versions of the UART peripheral. Thanks for the correction.

The master/slave timer interface was also what I was thinking.

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

> So many different versions of the UART peripheral.

Indeed. I wish there would be a concise matrix of the peripherals' versions used across the STM32 families.

JW