Skip to main content
Visitor II
October 8, 2024
Question

STM32G4 : Timer triggered UART transmit with DMA

  • October 8, 2024
  • 4 replies
  • 1567 views

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!

    This topic has been closed for replies.

    4 replies

    Super User
    October 8, 2024

    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.

    guptaniksAuthor
    Visitor II
    October 8, 2024

    Data size is 4 bytes maximum.

     

    Super User
    October 8, 2024

    > 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.

    Super User
    October 8, 2024

    > 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

     

    Super User
    October 8, 2024

    @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.

    Super User
    October 8, 2024

    > 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

    Graduate II
    October 8, 2024

    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