How stmicroelectronics/stm32-mw-openbl works
Project type and purpose
• This is a middleware MCU component providing an In-Application Bootloader for STM32 microcontrollers (“Open Bootloader”).
• It implements the same protocol and command set as the STM32 system bootloader, exposing interfaces (USART, I2C, SPI, USB-DFU, FDCAN…) to a host tool (e.g., STM32CubeProgrammer).
• It is not a full-stack app but firmware middleware, intended to be compiled into Flash on a Cortex-M device’s non-secure domain.
File structure
• Top-level:
• Core/ – bootloader core logic (dispatch, protocol engine)
• Interfaces/Patterns/ – reference implementations for each hardware interface
• Interfaces/Templates/ – stub templates for user customization
• Modules/ – command handlers for each protocol, mapping commands to memory operations
• _htmresc, docs, CI, licensing, and project metadata
• Config files in Interfaces/Patterns (interfaces_conf.h, openbootloader_conf.h) define which interfaces and commands are enabled.
• The Core calls into Modules to execute high-level commands and uses HAL/LL drivers for low-level peripheral initialization.
Key README insights
• The bootloader lives in non-secure Flash/SRAM, is driven by the Core, and relies on STM32Cube HAL/LL.
• It services a Host over multiple comms, performing memory operations (read, write, erase, jump…).
• Customization points: location in Flash, enabled interfaces, supported commands, Templates for board-specific code.
a. Components
1. Host Tool (STM32CubeProgrammer or custom PC utility)
2. Physical Interfaces (USART, I2C, SPI, USB-DFU, FDCAN)
3. Interface Layer
– Patterns (concrete drivers)
– Templates (user-supplied overrides)
– Configuration (interfaces_conf.h, platform.h)
4. Bootloader Core
– Protocol parser
– Command dispatcher
5. Modules
– openbl_xxx_cmd.c / .h for each interface
– Implements each bootloader command (GetVersion, ReadMemory, FlashErase, etc.)
6. HAL/LL Drivers
– Clock init, GPIO, DMA, SysTick, IWDG
7. Memory Resources
– Internal Flash, SRAM, OTP, Option Bytes, External memory if configured
b. Relationships & interactions
• Host Tool → (over chosen interface) → Interface Layer
• Interface Layer → Bootloader Core (incoming frames)
• Bootloader Core → Module (execute command logic)
• Module → HAL/LL → Memory (perform read/write/erase)
• Bootloader Core → Interface Layer → Host (send responses)
c. Architectural patterns & principles
• Layered design: Interface abstraction, Core logic, Modules, HAL drivers
• Plugin-style Interfaces/Templates: user can swap in board-specific code
• Command dispatch pattern: central dispatcher calls per-command handlers
d. Key technologies & libraries
• STM32Cube HAL/LL (injected at compile time)
• C language, Makefile/CMake integration in STM32Cube Packages
• Communication protocols: AN3155 (USART), AN4221 (I2C), AN3156 (USB-DFU), AN5405 (FDCAN), AN4286 (SPI)