cpq /bare-metal-programming-guide

A bare metal programming guide (ARM microcontrollers)

★ 4,995⑂ 460👁 88▤ 0
CCreated 2022-09-15
+0
Daily
+0
Weekly
+45
Monthly
4,995
stars
460
forks
88
watchers
–
prs
–
issues
0
releases

README

A bare metal programming guide




English | 中文 | Türkçe

This guide is written for developers who wish to start programming
microcontrollers using a GCC compiler and a datasheet, without using any
framework. This guide explains the fundamentals, and helps to understand how
embedded frameworks like Cube, Keil, Arduino, and others, work.

Every chapter in this guide comes with a complete source code which gradually
progress in functionality and completeness. In the end, I provide bare metal
template projects for different architectures:

- blinky - classic, blink an LED and print a debug message periodically
- cli - UART command line interface. Implements commands to set LED status and hexdump RAM
- lfs - implement file functions mkdir(),readdir(),fopen(),... using
  littlefs in the upper
  region of buit-in flash memory. Store device boot
  count in a file, increment on each boot, and print periodically
- webui - embedded web server with a professional device dashboard UI
  using mongoose library

| Board | Arch | MCU datasheet | Board datasheet | Template project |
| ----- | ---- | ------------- | --------------- | ---------------- |
| STM32 Nucleo-F429ZI | Cortex-M4  | mcu datasheet | board datasheet | blinky, cli, webui |
| STM32 Nucleo-F303K8 | Cortex-M4  | mcu datasheet | board datasheet | lfs |
| STM32 Nucleo-L432KC | Cortex-M4  | mcu datasheet | board datasheet | blinky, cli, lfs |
| STM32 Nucleo-H563ZI | Cortex-M33 | mcu datasheet | board datasheet | lfs |
| SAME54 Xplained     | Cortex-M4  | mcu datasheet | board datasheet | blinky |
| TI EK-TM4C1294XL    | Cortex-M4F | mcu datasheet | board datasheet | webui | 
| RP2040 Pico-W5500   | Cortex-M0+ | mcu datasheet | board datasheet | webui |
| ESP32-C3            | RISCV      | mcu datasheet | | blinky |

In this tutorial we'll use the Nucleo-F429ZI development board, so
go ahead and download the mcu datasheet and the board datasheet for it.

 Tools setup

To proceed, the following tools are required:

- ARM GCC, https://launchpad.net/gcc-arm-embedded - for compiling and linking
- GNU make, http://www.gnu.org/software/make/ - for build automation
- ST link, https://github.com/stlink-org/stlink - for flashing
- Git, https://git-scm.com/ - for downloading source code and version control

 Setup instructions for Mac

Start a terminal, and execute:

sh
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install gcc-arm-embedded make stlink git


 Setup instructions for Linux (Ubuntu)

Start a terminal, and execute:

sh
$ sudo apt -y update
$ sudo apt -y install gcc-arm-none-eabi make stlink-tools git


 Setup instructions for Windows

- Download and install gcc-arm-none-eabi-10.3-2021.10-win32.exe. Enable "Add path to environment variable" during the installation
- Create c:\tools folder
- Download stlink-1.7.0-x86_64-w64-mingw32.zip and unpack bin/st-flash.exe into c:\tools
- Download make-4.4-without-guile-w32-bin.zip and unpack bin/make.e

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON