
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.
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.
Master STM32 UART with DMA through a simple receive and transmit experiment using a four-element circular buffer to illustrate circular DMA behavior.
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.
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.
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.
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.
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.