Programming STM32 USART using GCC tools. Part 2

In the last part of the tutorial, we have covered simple USART routines that send data directly to USART peripheral. This is OK to use such an approach when a project isn’t time-critical and processing resources are far from limits. But most often, we stuck with these limiting factors, mainly when RTOS is used or when we perform necessary real-time data processing. And having USART routines with while the loop-based wait isn’t a good idea – it steals processing power only to send a data. As you may guess – next step is to employ interrupts. As you can see, there are many sources to trigger interrupts, and each of them is used for a different purpose. To use one or another interrupt, first, it has to be enabled in USART control register (USART_CR1, USART_CR2, or USART_CR3). Then NVIC USART_IRQn channel has to be enabled to map interrupt to its service routine. Because NVIC has only one vector for all USART interrupt triggers, service routine has to figure out which of interrupts has triggered an event. This is done by…

Continue reading

Programming STM32 USART using GCC tools. Part 1

When we need some feedback from the microcontroller, usually we use USART. It allows to output messages and debug information to the terminal screen. Also, data can be sent to MCU same way. For this purpose, STM32 microcontrollers have more than one USART interface allowing to have multiple streams of data output and input. USART interface is designed to be very versatile, allowing to have lots of modes including LIN, IrDA, Smart card emulation, DMA based transmissions. But for now, let’s focus on standard USART communications we could send and receive messages from the terminal window.

Continue reading