This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSPM0G3519-Q1: UART RX DMA configuration, no interrupts

Part Number: MSPM0G3519-Q1

I'd like to use the DMA to extend the RX FIFO in the UART for receiving long messages without an interrupt.  The messages might be 2 bytes or as much as 256 bytes, and I'd like to check for message data from time to time from my main loop, with no interrupts.

Looking at the configuration of the example uart_rx_multibyte_fifo_dma_interrupts, the DMA is set up for a single transfer of 4 bytes to a buffer: volatile uint8_t gRxPacket[4].  When the DMA completes, the example catches an interrupt to handle the receipt.

Supposing I change it to volatile uint8_t gRxPacket[256] (changing the #define UART_PACKET_SIZE to 256), I'd expect the DMA to grab a few characters (e.g. 4 characters) but not fire the interrupt.

From my main loop, how can I query the DMA state to know 4 characters have arrived?

With that knowledge, I can process that portion of the message and re-enable the DMA, maybe back at &gRxPacket[0].

Is it safe to disable the DMA channel, check for and process the messages, reset the destination address, and re-enable the DMA?  Do I need to do any other steps for characters that might arrive at the rx fifo while the DMA was disabled?  Is there a better way to do this (without interrupts)?

Thanks!

  • The DMA channel's DMASZ decrements as the bytes are transferred. Watch for the threshold where it reads (UART_PACKET_SIZE-4).

    At that point, as you describe, you can disable the channel, deal with the data, put back DMADA and DMASZ, and re-enable the channel.

  • Hi Michael,

    Bruce has a good suggestion here. You could also use a read pointer instead if you don't want to disable DMA mid-stream:

     #define UART_PACKET_SIZE 256
    
      volatile uint8_t gRxPacket[UART_PACKET_SIZE];
      uint16_t gReadPos = 0;  // tracks how far we have consumed
    
      // In main loop:
      void checkUartRx(void)
      {
          uint16_t written  = UART_PACKET_SIZE - DL_DMA_getTransferSize(DMA, DMA_CH0_CHAN_ID);
          uint16_t avail    = written - gReadPos;
    
          if (avail >= 4) {
              // safe to read gRxPacket[gReadPos .. gReadPos+3]
              processBytes(&gRxPacket[gReadPos], 4);
              gReadPos += 4;
          }
    
          // Reset only when the DMA buffer is exhausted or you want to wrap
          if (gReadPos >= UART_PACKET_SIZE || written == UART_PACKET_SIZE) {
              DL_DMA_disableChannel(DMA, DMA_CH0_CHAN_ID);
              DL_DMA_setDestAddr(DMA, DMA_CH0_CHAN_ID, (uint32_t)&gRxPacket[0]);
              DL_DMA_setTransferSize(DMA, DMA_CH0_CHAN_ID, UART_PACKET_SIZE);
              DL_DMA_enableChannel(DMA, DMA_CH0_CHAN_ID);
              gReadPos = 0;
          }
      }

    Then you can disable DMA once you near a boundary, such as buffer full.

    You can still disable mid-stream, but keep in mind that the UART RX FIFO can still receive bytes. Overflow an be a concern here, but can be handled with care.

  • Thanks for pointing me in the right direction with this!