Developing the UART driver
In this section, we will apply everything we’ve learned about the UART peripheral to develop a driver for transmitting data using the USART2
peripheral.
Let’s begin by identifying the GPIO pins connected to the UART2 peripheral. To do this, refer to the table on page 39 of the STM32F411RE datasheet. This table lists all the GPIO pins of the microcontroller, along with their descriptions and additional functionalities. As shown in Figure 10.3, part of this table reveals that PA1 has an alternate function labeled as USART2_TX
:
Figure 10.3: The USART2_TX pin
To use PA2 as the USART2_TX
line, we need to configure PA2
as an alternate function pin in the GPIOA_MODER
register and then specify the alternate function number for USART2_TX
in the GPIOA_AFRL
register. The STM32F4 microcontroller allows us to choose from 16 different alternate functions, numbered from AF00
to AF15
. The alternate function mapping table, which...