How 1141170704/buck-boost works
Project Type and Purpose
• This is an embedded firmware project for a Buck-Boost digital power supply based on an STM32G4 series MCU. The device reads voltages/currents, runs a PID control loop, drives the power stage (buck-boost converter), provides a user interface (keys + OLED), and persists settings to external flash.
File Structure Analysis
• Top-level:
• .cmsis/… – ARM CMSIS core headers for startup and core access
• Core/Hardware – Driver implementations for external hardware modules (Key, OLED, W25Q64 flash)
• Core/Inc – HAL peripheral wrappers (ADC, DMA, GPIO, I2C, SPI, TIM, USART, watchdog, HRTIM, PID)
• Core/Src – Source files that implement peripheral initialization and ISR handlers, plus main.c and system startup
• EIDE configs & workspace files – Project metadata for the IDE/build environment
• Patterns:
• Layered architecture:
– Hardware Abstraction (CMSIS + STM32 HAL)
– Board-level Drivers (Core/Hardware)
– Peripheral Wrappers & Middleware (Core/Inc & Core/Src)
– Application Logic (main.c + PID controller + UI logic)
Key Components
a. STM32G4 MCU Block
– Cortex-M4 core, flash, SRAM
– On-chip peripherals: ADC, DMA, TIM/HRTIM, SPI, I2C, USART, IWDG
b. External Hardware
– Buck-Boost power stage (power MOSFETs + inductors + capacitors)
– OLED display (SPI or I2C interface)
– User keys (GPIO inputs)
– W25Q64 external flash (SPI)
c. Firmware Layers
– CMSIS (core startup, vector table)
– STM32 HAL (low-level register drivers)
– Board Drivers (Core/Hardware/*.c/.h)
– Middleware: PID control, system functions (Core/Inc + Core/Src)
– Application (main.c loop, UI state machine)
Interactions & Data Flows
• ADC → DMA → PID algorithm → Timer/HRTIM PWM outputs → Power stage
• Key presses (GPIO interrupts) → UI state machine → update OLED via SPI/I2C
• Settings save/load → W25Q64 flash via SPI
• Watchdog timer resets on main loop “heartbeat”
• USART for debugging/parameter tuning (optional)
Architectural Patterns & Principles
• Layered separation: hardware abstraction, drivers, middleware, application
• Interrupt-driven peripherals with DMA for real-time sampling
• Modular drivers per hardware block (single responsibility)
• Persistent storage abstraction for settings
Essential Elements to Capture
• Clear component names (e.g., “STM32G4 ADC1 + DMA1” vs. generic “ADC”)
• Data flows with arrowheads and labels
• Notes on critical timing (e.g., sampling rate, PWM frequency) if desired