Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
How To Use STM32's UART with DMA
Rating: 4.1 out of 5(35 ratings)
1,096 students

How To Use STM32's UART with DMA

Module 1: Creating convenient library for transmitting and receiving data using STM32’s UART
Created byGeorgy Moshkin
Last updated 9/2023
English
English [Auto],

What you'll learn

  • Sending and receiving single bytes
  • Making reliable DMA-based serial library
  • Working with multiple UART ports
  • Adding RS-485 support

Course content

1 section12 lectures30m total length
  • Introduction1:02
  • The right way1:51

    Master STM32 UART with DMA by debunking myths and enabling nonblocking background data transfer. Validate reliability with loopback and hotplug tests and aim for portable code that avoids idle-interrupt dependencies.

  • Configuring UART ports1:16

    Configure stm32 uart ports by enabling all serial ports with transmit and receive dma, set rates to match receiver, and apply circular receive mode while keeping transmit non circular.

  • Simple receive and transmit experiment3:07

    Master STM32 UART with DMA through a simple receive and transmit experiment using a four-element circular buffer to illustrate circular DMA behavior.

  • Receiving single byte3:59
  • Calculating available unprocessed bytes count2:07

    Calculate available unprocessed bytes by subtracting processing position from teammate position index. Handle packets crossing the boundary by counting bytes to end, then wrap and add bytes from the start.

  • Receiving multiple bytes0:53
  • Transmitting single or multiple bytes1:52

    Transmit single or multiple bytes with stm32 uart and dma by sending pointers to data; ensure data remains unchanged; monitor uart status bit and support blocking or non-blocking operation.

  • Creating UART library and it’s functions3:34

    Transform previous uart proof-of-concept into a multi-port stm32 uart dma library with a header file, port structures and selection, circular receive buffers, and blocking and non-blocking transmit functions.

  • Additional features6:10
  • UART library usage examples4:01

    ZIP archive contains library itself (uart.c,uart.h) and two examples tested on stm32f103. Note that only example.ioc and main.c files are provided for each example. You can generate project using provided IOC file and then copy and paste example code to newly generated main.c file.

  • Introduction to next modules0:29

Requirements

  • Experience needed: STM32 developer with at least 6 months of experience.
  • You should already know how to use GPIOs and interrupt-driven HAL UART library.

Description

Through this module, you’ll learn how to use STM32’s UART the right way. Everything you’ve seen before is garbage! Just trash it… We will create a serial library which is fast, reliable and can be easily reused in different projects. Multi-port, powered by HAL and compatible with any STM32 microcontroller series.

There are many STM32 UART myths created by incompetent people. E.g., that DMA can’t be used with variable-size data packets and other nonsense. Avoiding DMA peripheral is one of the worst things you can do. It is much simpler to make really good UART code when DMA is used.

Many will say that their UART code is reliable, good, etc. Do you believe it? We will perform two simple tests to ensure that our serial library is reliable: 

  • Loopback test to ensure that each byte is sent and received correctly.

  • Hot-plug test to ensure that communication can be resumed after cable is re-connected.

Our serial library must be portable across multiple STM32 series. Generally, we should consider portability across microcontrollers from different manufactures.  E.g., porting code to Microchip’s PIC32 would be complicated if our library heavily relies on STM32’s “idle” interrupt. Thus, we know what functions to avoid if we want our library to be more portable.

Who this course is for:

  • For professional electronic engineers and firmware developers
  • For anyone who tired of searching how to solve UART problems in their projects