

If you’re using an STM32L432KC “Nucleo-32” board, pins A2 and A15 are connected to its built-in debugger which will forward the serial connection over the board’s USB connector. Like with other STM32 peripherals, you can check your chip’s datasheet to see which pins can be used with which peripherals.įor these examples, I’ll use the USART2 peripheral. You’ll probably have at least 3 of them, but some larger chips have 8 or more since it is such a common interface. Most STM32 chips contain several USART peripherals, including simpler UART peripherals which do not support the extra “synchronization” clock signal. And these examples are all available in a GitHub repository, if you just want a quick reference. If you use a “pill” board, you’ll also need an ST-LINK debugger and a USB / UART bridge such as a CP2102 board. The “Nucelo” boards are easier to use, because they include a debugger. If any of that sounds interesting, keep reading! The target hardware will be either an STM32L432KC “Nucleo-32” board or an STM32F103C8 “pill” board they cost around $11 or $2-5 respectively. Setting up a “ring buffer” to handle continuous data reception.Using interrupts to receive data as it arrives.Implementing the C standard library’s printf(.) function to send text strings over UART.Setting up the UART peripheral to send / receive data one byte at a time.I will cover a few basic ways to use the STM32 UART peripherals, though: There are also a set of extra “flow control” signals, but I’m not going to talk about those or USART functionality in this post. The standards are otherwise very similar, so you might see UART and USART used interchangeably in some places. That, combined with the availability of cheap off-the-shelf USB / UART bridges, makes it a popular way to add some interactivity and a working printf(.) function to bare-metal applications.Īnd while a simple 2-wire UART connection is reliable enough for most purposes, there is also an extended USART standard which adds an optional “clock” line to synchronize the two devices’ timing the extra “S” stands for “Synchronous”. One of the most common uses of UART is to transmit strings of text or binary data between devices.

(But technically, your actual transmission frequency will be slightly lower than the baud rate, because the standard includes extra “control” bits which are sent in addition to the actual data.) If you have a baud rate of 9600, then you expect a new bit every 1 / 9600 of a second.

Since it is asynchronous (no clock signal), both devices need to use the same “baud rate”, which is basically the transmission frequency measured in Hertz. In its most basic form, it only uses two data signals: “Receive” ( RX) and “Transmit” ( TX). UART stands for “Universal Asynchronous Receiver / Transmitter”, and it is a very simple serial communication interface. It is such a fundamental peripheral that I vaguely thought I’d already written about it until I got a couple of comments asking about it, so thank you for those reminders! Usually when people write microcontroller tutorials, UART is one of the first peripherals that they talk about, and I’ve gone far too long without mentioning it.

If you’ve been reading the posts about STM32s that I’ve been writing, I owe you an apology.
