Skip to content

Commit 3bc8e16

Browse files
committed
tooling: Add firmware build and deploy targets.
1 parent 2c5f280 commit 3bc8e16

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ __pycache__
77
78e43b91-b6a2-4e0a-99c2-3f6f74828063_ExportBlock-935e0d48-7286-4b74-aa60-ccd18217ac01
88
node_modules/
99
CLAUDE.md
10+
.build/

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ make bump PART=minor # minor: v1.0.1 → v1.1.0
122122
make bump PART=major # major: v1.1.0 → v2.0.0
123123
```
124124

125+
## Firmware build and deploy
126+
127+
The drivers are "frozen" into the MicroPython firmware for the STeaMi board. The Makefile automates cloning, building, and flashing:
128+
129+
```bash
130+
make firmware # Clone micropython-steami (if needed), update submodule, build
131+
make deploy # Flash firmware via OpenOCD
132+
make run SCRIPT=lib/steami_config/examples/calibrate_magnetometer.py # Deploy a script as main.py
133+
make firmware-clean # Clean firmware build artifacts
134+
```
135+
136+
The firmware source is cloned into `.build/micropython-steami/` (gitignored). The submodule `lib/micropython-steami-lib` is pointed to the current HEAD of your local branch, so the firmware always includes your latest driver changes.
137+
138+
**Requirements**: `arm-none-eabi-gcc` toolchain and OpenOCD for flashing.
139+
125140
## Notes
126141

127142
* Keep implementations simple and readable

Makefile

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,42 @@ ci: lint test test-examples ## Run all CI checks (lint + tests + examples)
7979
.PHONY: build
8080
build: lint test ## Build (lint + test)
8181

82+
# --- Firmware ---
83+
84+
$(MPY_DIR):
85+
@echo "Cloning micropython-steami into $(MPY_DIR)..."
86+
git clone --branch $(MICROPYTHON_BRANCH) $(MICROPYTHON_REPO) $(MPY_DIR)
87+
cd $(MPY_DIR) && git submodule update --init --recursive
88+
89+
.PHONY: firmware
90+
firmware: $(MPY_DIR) ## Build MicroPython firmware with current drivers
91+
@echo "Updating submodule to current HEAD..."
92+
cd $(MPY_DIR)/lib/micropython-steami-lib && \
93+
git fetch origin && \
94+
git checkout $$(cd $(CURDIR) && git rev-parse HEAD)
95+
@echo "Building firmware for $(BOARD)..."
96+
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD)
97+
@echo "Firmware ready: $(MPY_DIR)/ports/stm32/build-$(BOARD)/firmware.hex"
98+
99+
.PHONY: deploy
100+
deploy: ## Flash firmware to the board via OpenOCD
101+
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) deploy-openocd
102+
103+
.PHONY: run
104+
run: ## Copy and run a script on the board (SCRIPT=path/to/file.py)
105+
@if [ -z "$(SCRIPT)" ]; then \
106+
echo "Error: SCRIPT is required. Usage: make run SCRIPT=lib/.../example.py"; exit 1; \
107+
fi
108+
mpremote connect $(PORT) cp $(SCRIPT) :main.py
109+
mpremote connect $(PORT) reset
110+
@echo "Script deployed as main.py and board reset."
111+
112+
.PHONY: firmware-clean
113+
firmware-clean: ## Clean firmware build artifacts
114+
@if [ -d "$(MPY_DIR)/ports/stm32" ]; then \
115+
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) clean; \
116+
fi
117+
82118
# --- Hardware ---
83119

84120
.PHONY: repl
@@ -141,8 +177,9 @@ clean: ## Remove build artifacts and caches
141177
find . -type d -name .mypy_cache -exec rm -rf {} + 2>/dev/null || true
142178

143179
.PHONY: deepclean
144-
deepclean: clean ## Remove everything including node_modules
180+
deepclean: clean ## Remove everything including node_modules and firmware
145181
rm -rf node_modules
182+
@if [ -d "$(BUILD_DIR)" ]; then rm -rf $(BUILD_DIR); fi
146183

147184
.PHONY: help
148185
help: ## Show this help

env.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
export PATH := $(CURDIR)/node_modules/.bin:$(PATH)
22
PORT ?= /dev/ttyACM0
3+
4+
# Firmware build configuration
5+
MICROPYTHON_REPO ?= https://github.com/steamicc/micropython-steami.git
6+
MICROPYTHON_BRANCH ?= stm32-steami-rev1d-final
7+
BOARD ?= STEAM32_WB55RG
8+
BUILD_DIR ?= .build
9+
MPY_DIR ?= $(BUILD_DIR)/micropython-steami

0 commit comments

Comments
 (0)