Module 1: Creating convenient library for transmitting and receiving data using STM32’s UART

What you will learn

Sending and receiving single bytes

Making reliable DMA-based serial library

Working with multiple UART ports

Adding RS-485 support

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.


Get Instant Notification of New Courses on our Telegram channel.


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.

English
language

Content

The right way

Introduction
The right way
Configuring UART ports
Simple receive and transmit experiment
Receiving single byte
Calculating available unprocessed bytes count
Receiving multiple bytes
Transmitting single or multiple bytes
Creating UART library and it’s functions
Additional features
UART library usage examples
Introduction to next modules