2024-10-08 05:38 AM
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!
2024-10-08 06:57 AM
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.
2024-10-08 07:20 AM
Data size is 4 bytes maximum.
2024-10-08 08:12 AM
> 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.
2024-10-08 08:37 AM
> 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
2024-10-08 08:48 AM
@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.
2024-10-08 09:31 AM
> 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
2024-10-08 12:02 PM
I'll second that! A revision level for peripherals so enhancements can be followed without deep diving into each data sheet during preliminary selection of the MCU. TI does something like this with its Piccolo series...
Dave