Skip to content

This example shows how to establish a serial communication between the stm32h743 microcontroller and a laptop using the UART peripherals.

License

Notifications You must be signed in to change notification settings

martindoff/bare-metal-stm32h7-uart

Repository files navigation


Logo

Bare metal stm32h7

A bare metal implementation of a UART example for the stm32h743 with a simple makefile and without using HAL libraries.

Table of Contents

  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact

About The Project

This example shows how to establish a serial communication between the stm32h743 microcontroller and a laptop using the UART peripherals. To demonstrate the connection, the user can use the serial communication program minicom to interact with the board and command the blinking pattern of the LED.

This project does not rely on HAL libraries and the code can be built and flashed using GNU make (so that you do not need any IDE such as STM32CubeIDE) and the GNU ARM Embedded Toolchain. The code was tested with the stm32h743vit6 development board from DevEBox but could be easily adapted for any configuration. The board can be purchased on Banggood.

Detailed description

The program configures the PA1 pin as a LED (ouput push-pull) and the PB12, PB13 pins for UART5.

The UART protocole is kept in the default configuration (8N1) and the baud rate is set to 38400.

The system clock frequency is set to 480MHz, assuming the presence of a 25MHz high speed external (HSE) crystal. If you do not use a HSE or if you have an older version of the chip* you might have to modify the clock configuration function or rely on the default internal oscillator (64MHz). In that case you will have to change the baud rate register (e.g. with the internal oscillator at 64MHz, baud rate of 38400, the BRR should be modified with: uint16_t uartdiv = 64000000 / 38400;)

The program allows a user to interact with the microcontroller to flash the PA1 LED (D2) a given number of times (between 0 and 9). The program then returns an echo message.

*Note that stmicroelectronics recently introduced a new version of their chip (version V) able to operate at up to 480MHz.

Built With

Getting Started

Prerequisites

You need to install the following:

  • GNU make
  • git
  • st-link
  • GNU ARM toolchain
  • minicom or PuTTY

Installation

  1. Clone the repo
    git clone https://github.com/martindoff/bare-metal-stm32h7-uart.git
  2. Go to directory
    cd bare-metal-stm32h7-uart
  3. Build
    make
  4. Flash the board (connect via st-link V2 debugger)
    make flash
  5. Disconnect the st-link V2 debugger and connect the board to a development computer with a USB TTL serial adapter according to the following schematics:

Logo

  1. Find the name of the COM port. In macOS, this can be found in the /dev directory and starts by the prefix /dev/cu.
  2. Configure the COM port. For example, using minicom:
  minicom -s

The configuration can be done as follows:

  • Select the "Serial Port Setup" entry and press Enter.
  • Modify the path name to match the name of the COM port found previously (press 'A').
  • Disable flow control ('F' and 'G').
  • Change the port settings by typing 'E': set the baud rate to 38400 ('D') and configure the port to 8N1 ('Q').
  • Type Enter twice to go back to the main menu and choose the option "Save setup as..." to give a name to the configuration, e.g. config.

If you exit minicom, you can retrieve your configuration as explained in step 7. Otherwise go to step 8 directly.

  1. To open minicom and retrieve the saved setting in config:
  minicom config
  1. In the active minicom terminal, interact with the stm32h743 by typing a digit between 0 and 9 (any entry out of this range will be converted to 0 by the program running on the microcontroller). Observe the LED blink as much time as prompted (laptop -> stm32h743) and notice the message returned by the microcontroller (stm32h743 -> laptop).

Roadmap

Starting from this simple bidirectional UART communication example, more complex projects will be built. For example, hardware-in-the-loop simulations can be enabled by exchanging data via the UART protocol between the microcontroller and a development computer.

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Martin Doff-Sotta - [email protected]

Linkedin: https://www.linkedin.com/in/mdoffsotta/

About

This example shows how to establish a serial communication between the stm32h743 microcontroller and a laptop using the UART peripherals.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages