board
Solar MPPT Power System
Public Unreviewedby TylerK
A 30 W solar battery charger with regulated 5 V and 3.3 V rails: an STM32G031 running perturb & observe MPPT and a CC/CV charge state machine, steering a TI LM5175 4-switch buck-boost through a single analog control input. Four-layer KiCad board, schematic and PCB generated from Python, with an electrothermal simulation run against the published board file.
main
# Two things can be checked without any STM32 hardware or a CubeMX install,
# and both are checked here:
#
# make test -- compile the control layer for the HOST and run it against a
# simulated panel, converter and battery, asserting the
# properties a charger must have (current limits respected,
# voltage ceiling respected, MPPT finds the peak, faults are
# detected and recovered from).
# make arm -- compile every application source for the real target
# (Cortex-M0+) under strict warnings, against a stub main.h
# standing in for the one CubeMX generates. Catches type and
# signature errors, accidental double-precision maths (this
# part has no FPU), and reports the flash/RAM cost.
#
# `make` runs both. Neither produces a flashable image -- that still needs
# CubeMX's startup code, linker script and HAL, per README.md.
CC ?= gcc
ARMCC ?= arm-none-eabi-gcc
SRC := $(wildcard Core/Src/*.c)
APP_SRC := $(filter-out Core/Src/app_main.c,$(SRC))
WARN := -Wall -Wextra -Wconversion -Wshadow -Wdouble-promotion
ARMFLAGS := -std=c11 -Os -mcpu=cortex-m0plus -mthumb -ffreestanding $(WARN) \
-ICore/Inc -Itest/arm-stub
HOSTFLAGS := -std=c11 -O1 -g -Wall -Wextra -ICore/Inc -Itest
BUILD := build
.PHONY: all test arm clean
all: test arm
test: $(BUILD)/harness
@echo "== host control-loop tests =="
@./$(BUILD)/harness
$(BUILD)/harness: test/harness.c test/plant.c Core/Src/charge_control.c | $(BUILD)
$(CC) $(HOSTFLAGS) $^ -o $@ -lm
arm: | $(BUILD)
@echo "== cross-compile for STM32G031 (Cortex-M0+) =="
@for f in $(SRC); do \
o=$(BUILD)/arm_$$(basename $$f .c).o; \
$(ARMCC) -c $(ARMFLAGS) $$f -o $$o || exit 1; \
done
@arm-none-eabi-size -t $(BUILD)/arm_*.o
@if arm-none-eabi-nm $(BUILD)/arm_*.o | grep -qE "__aeabi_(dadd|dsub|dmul|ddiv|f2d)"; then \
echo "ERROR: double-precision soft-float pulled in on a part with no FPU"; exit 1; \
else echo "OK: single-precision only"; fi
$(BUILD):
@mkdir -p $(BUILD)
clean:
@rm -rf $(BUILD)