USART DMA Driver

The universal synchronous and asynchronous receiver and transmitter (USART) is normally used to transfer data from one device to the other.

When receiving data over USART DMA, the data buffer supplied by the user is used. The RX done callback will only be generated at the end of the buffer and not for each byte.

On the other hand, when sending data over USART DMA, the data is stored in a buffer defined by the user, the TX done callback will be generated only at the end of the buffer and not for each byte.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Register I/O descriptor

  • Enable or disable USART

  • Hookup callback handlers on transfer complete, or error events

  • Data transfer: transmission, reception

Summary of configuration options

Below is a list of the main USART parameters that can be configured in START. Many of these are used by the usart_dma_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden and changed runtime by calling the appropriate API functions.
  • Select USART DMA TX channel

  • Select USART DMA RX channel

  • Set USART baudrate

  • Select UART or USART communication mode

  • Select character size

  • Set Data order

  • Flow control

  • Which clock source is used

Driver Implementation Description

After USART hardware initialization, the usart_dma_get_io_descriptor function is needed to register an I/O descriptor. Then use usart_dma_register_callback to register the callback function for transfer, and enable USART hardware complete. After that, start the read/write operation.

Concurrency

  • The write buffer should not be changed while data is being sent

Limitations

  • The driver does not support 9-bit character size

Example of Usage

The following shows a simple example of using the USART DMA. The USART must have been initialized by usart_dma_init. This initialization will configure the operation of the USART.

The example registers an I/O descriptor and enables the hardware. Then it registers a callback, and finally starts a writing operation.

          /**
           * Example of using USART_0 to write "Hello World" using the I/O abstraction.
            
           * Once transfer has been completed the tx_cb function will be called.
           */
          static uint8_t example_USART_0[12] = "Hello World!";
          static void tx_cb_USART_0(struct _dma_resource *resource)
          {
              /* Transfer completed */
          }
          void USART_0_example(void)
          {
              struct io_descriptor *io;
              usart_dma_register_callback(&USART_0, USART_DMA_TX_DONE, tx_cb_USART_0);
              usart_dma_get_io_descriptor(&USART_0, &io);
              usart_dma_enable(&USART_0);
              io_write(io, example_USART_0, 12);
          }
        

Dependencies

  • The USART peripheral and its related I/O lines and clocks

  • The NVIC must be configured so that USART interrupt requests are periodically serviced

  • DMA