STM32 - A Minimal Hello-World Program
This simplest blinking led project goes through documents of microcontroller, the target hardware, and a guide to learn how microcontroller bootups.
Objectives
Functional features:
- Turn on the board and boot the MCU up
- Repeatedly turn on and turn off an on-board LED attached to a GPIO
Non-functional features:
- Understand main steps to boot up an MCU
- Use Bare-metal programming, without any IDE, library
- The compiled firmware is as small as possible
Hardware
The target board is Nucleo-64 F411RE board:
- STM32F411RET6U:
- Arm® 32-bit Cortex®-M4 CPU with FPU, upto 100 MHz
- 512 Kbytes of flash memory
- 128 Kbytes of SRAM
- Debug mode:
- Serial wire debug (SWD) & JTAG interfaces
- Cortex®-M4 Embedded Trace Macrocell™
- 1 User LED
- 1 Reset Push-Button and 1 User Push-Button
- On-board ST-LINK/V2-1 debugger and programmer with SWD connector and USB re-enumeration capability (Virtual COM port, Mass storage, Debug port)
Documents
Nucleo-64 Board User Manual UM1724 STM32 Nucleo-64 boards (MB1136):
- Board features: MCU, Debugger, on-board Peripherals
- Hardware settings: Layout, Configuration, Connectors, Jumpers
- Power supply
Board Schematic MB1136-DEFAULT-C05 Board schematic:
- Components and Wiring
MCU Datasheet DS10314 - STM32F411RE MCU:
- Device overview with block diagrams
- Peripherals and features
- Memory map and Memory range
- Pin-out and pin description
- Electrical characteristics
Reference Manual RM0383 - STM32F411xC/E MCUs:
- System Architecture with bus, peripherals, and connections
- Memory map and boundary addresses
- Boot configuration, vector table relocation
- Peripheral with details features, descriptions, and structure
- Registers and bit-fields for all accessible registers
- Code examples using CMSIS header files
Programming Manual PM0214 - STM32 Cortex®-M4 MCUs and MPUs:
- Processor Mode and Stack Model
- Memory Model and Memory Management
- Exception model, the Interrupt Service Routines, Fault Handling
- Power Management, Sleep Mode, Wake Up
- The Instruction Set
- CMSIS intrinsic functions
- Core Peripherals:
- Memory Protection Unit (MPU)
- Nested vectored interrupt controller (NVIC)
- System control block (SCB)
- SysTick timer (STK)
Application Notes
There many Application Note documents provided by ST. Each document present the usage, design, and advice for a specific application or feature.
For example:
- AN2606 - STM32 microcontroller system memory boot mode
- AN4488 - Getting started with STM32F4xxxx MCU hardware development
- AN4646 - Peripheral interconnections on STM32F401 and STM32F411 lines
- AN4739 - STM32Cube firmware examples for STM32F4 Series
Development Tools
List of tools on the host PC for compiling, debugging the target MCU:
ARM Compiler
Install Cross-Compiler ARM GNU Toolchain:
For the latest version, download the toolchain from Arm GNU Toolchain.
This will install:
gcc-arm-none-eabi
: Bare metal C and C++ compiler for embedded ARM chipsbinutils-arm-none-eabi
: Programs are used to manipulate binary and object files that may have been created for ARM architecturelibnewlib-arm-none-eabi
: C library and math library intended for use on embedded ARM chipslibstdc++-arm-none-eabi-newlib
: C++ library for embedded ARM chips using newlib as standard C library
ST-Link Tools
Install ST-Link package:
For the latest version, download the package from stlink-org/stlink.
The STLink toolset includes:
st-info
- a chip information toolst-flash
- a flash manipulation toolst-trace
- a logging tool to record information on executionst-util
- a GDB serverstlink-lib
- a communication library
Connect the board and probe the on-board ST-Link debugger: