Embedded Software Programming on the STM32 Plattform
You can use the STM32CubeMX software to create the necessary configuration files to enable the UART port(s) with the required parameters.
In this tutorial I’m going to explain how you can use the UART interface to print values using printf()
and react to user input via UART interrupts.
You need any of the STM32-Nucleo 64 boards. I am going to use the STM32f103rb
board in this tutorial. You should also have an the STM32CubeMX Configurator and a compatible IDE installed. Check Tutorial 000 for installation instructions. I will build upon the Tutorial 001 - GPIO Operations. It is also handy if you happen to have the User Manual of the Nucleo-64 board and the datasheet for the STM32 microcontroller nearby.
- STM32 NUCLEO-F103RB
- STM32F103c8 Datasheet
- STM32 Nucleo-64 boards User Manual UM1724 (pdf)
- Description of STM32F1 HAL and low-layer drivers UM1850 (pdf)
- STM32CubeMX installed
- arm Keil µVision 5 IDE installed
- (read through Tutorial 001 - GPIO Operations)
This tutorial comes with the following source code files
- STM32F103-Tutorial-001-GPIO.ioc (STM32CubeMX project file)
main.c
stm32f1xx_it.c
For this tutorial I am using the same file as in the previous tutorial.
If you check the default settings of the USART2
communication interface, you will see the following settings:
MIT License
Copyright (c) 2020 Simon Burkhardt / simonmartin.ch / github.com/mnemocron
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.