0% found this document useful (0 votes)
4 views1 page

Configuring USART2 on STM32 Nucleo

Uploaded by

dokterhis1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Configuring USART2 on STM32 Nucleo

Uploaded by

dokterhis1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EVE Appearance

As said before, the first time we configure the USART2 for our Nucleo it is best to use CubeMX. The
first step is enabling the USART2 peripheral inside the Pinout view: click on USART2 entry inside the
Connectivity section and then select the Asynchronous entry from the Mode combo box inside the
USART2 Mode andConfiguration pane, as shown in Figure 8.5. Both PA2 and PA3 pins will be
automatically highlighted in green. Then, go inside the Configuration section and click on the USART2
button. By using the Configuration pane, you can set additional options such as the BaudRate, word
length and so on⁹. Once we have configured the USART interface, we can generate the C code. You
will notice that CubeMX places all the USART2 initialization code inside the MX_USART2_UART_Init()
(which is contained in the main.c file). Instead, all the code related to GPIO configuration is placed
into the HAL_UART_MspInit() function, which is contained inside the stm32XXxx_hal_msp.c file.
⁹Some of you, especially those having a Nucleo-F3, will notice that the configuration pane may
contain a more settings compared to those shown in Figure 8.5. Please, refer to the reference
manual for your target MCU for more information. Universal Asynchronous Serial Communications
188 Figure 8.5: CubeMX can be used to configure the UART2 interface easily 8.3 UART
Communication in Polling Mode STM32microcontrollers, and hence the CubeHAL, offer three ways
to exchange data between peers over a UART communication: polling, interrupt and DMA mode. It is
important to stress right from now that these modes are not only three different flavors to handle
UART communications. They are three different programming approach to the same task, which
introduce several benefits both from the design and performance point of view. Let us introduce
them briefly. • In polling mode, also called blocking mode, the main application, or one of its
threads, synchronously waits for the data transmission and reception. This is the simplest form of
data communication using this peripheral, and it can be used when the transmit rate is not too much
low and when the UART is not used as critical peripheral in our application (the classical example is
the usage of the UART as output console for debug activities). • In interrupt mode, also called non-
blocking mode, the main application is freed from waiting for the completion of data transmission
and reception. The data transfer routines terminate as soon as they complete to configure the
peripheral. When the data transmission ends, a subsequent interrupt will signal the main code about
this. This mode is more suitable when communication speed is low (below 38400 Bps) or when it
happens “rarely”, compared to other activities performed by the MCU, and we do not want to stick
it waiting for data transmission. • DMA mode offers the best data transmission throughput, thanks
to the direct access of the UARTperipheral to [Link]-
speedcommunicationsan

You might also like