/stm32_bare_metal

Bare metal C programming examples for the STM32

Primary LanguageCApache License 2.0Apache-2.0

Bare-metal Code Examples for STM32 microcontrollers

This repository contains bare-metal C code written from scratch based on the reference manuals. It's aimed to be heavily commented to allow a smooth start for C-developers diving into embedded coding with STM32 based boards like the Blue Pill.

For the register address defines, CMSIS headers from ARM and STMicroelectronics are used. CMSIS also contains startup code, linker scripts and even higher abstractions which you might want to use for production grade applications. These are not used in this repository in order to demonstrate programming at a low level.

The code is split into two parts:

  • common contains general-purpose/framework code, Makefile, linker script etc. shared amongst the different examples.
  • src has subdirectories with different examples.

To start experimenting yourself, simply create a new subfolder in src and create a symlink Makefile -> ../../common/Makefile.

Prerequisites

  • GNU make
  • GCC arm-none-eabi
  • CMake (for stlink)
  • libusb 1.0 (for stlink)

On Debian/Ubuntu, the following should install the necessary requirements:

apt-get install build-essential gcc-arm-none-eabi cmake libusb-1.0-0-dev

If you did not use --recursive when cloning, don't forget to init submodules (for stlink):

git submodule init
git submodule update

You should now be able to run make build in any of the examples in src. Use make load to also load the resulting hex file with st-flash.

Reading Material