Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
78e43b91-b6a2-4e0a-99c2-3f6f74828063_ExportBlock-935e0d48-7286-4b74-aa60-ccd18217ac01
node_modules/
CLAUDE.md
.build/
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ make bump PART=minor # minor: v1.0.1 → v1.1.0
make bump PART=major # major: v1.1.0 → v2.0.0
```

## Firmware build and deploy

The drivers are "frozen" into the MicroPython firmware for the STeaMi board. The Makefile automates cloning, building, and flashing:

```bash
make firmware # Clone micropython-steami (if needed), update submodule, build
make deploy # Flash firmware via OpenOCD
make run SCRIPT=lib/steami_config/examples/calibrate_magnetometer.py # Deploy a script as main.py
make firmware-clean # Clean firmware build artifacts
```

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.

**Requirements**: `arm-none-eabi-gcc` toolchain and OpenOCD for flashing.
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs say the firmware submodule is pointed to “the current HEAD of your local branch” and list requirements only as GCC + OpenOCD, but the Makefile currently fetches from the submodule’s origin (so local/unpushed commits won’t be available) and make run requires mpremote to be installed. Please align this section with the actual behavior and list mpremote as a requirement for deploy/run.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95028ee. Updated CONTRIBUTING.md: added mpremote to requirements, clarified symlink behavior (local working directory, includes uncommitted changes), and documented all new targets (run, deploy-script, run-main).


## Notes

* Keep implementations simple and readable
Expand Down
39 changes: 38 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ ci: lint test test-examples ## Run all CI checks (lint + tests + examples)
.PHONY: build
build: lint test ## Build (lint + test)

# --- Firmware ---

$(MPY_DIR):
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git clone ... $(MPY_DIR) will fail on a fresh checkout if $(BUILD_DIR) (default .build) doesn’t exist, because git clone won’t create missing parent directories. Create $(BUILD_DIR) first (e.g., mkdir -p $(BUILD_DIR)) before cloning, or set MPY_DIR to a path whose parents are guaranteed to exist.

Suggested change
$(MPY_DIR):
$(MPY_DIR):
@mkdir -p $(dir $(MPY_DIR))

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95028ee. Added mkdir -p before clone.

@echo "Cloning micropython-steami into $(MPY_DIR)..."
git clone --branch $(MICROPYTHON_BRANCH) $(MICROPYTHON_REPO) $(MPY_DIR)
cd $(MPY_DIR) && git submodule update --init --recursive

.PHONY: firmware
firmware: $(MPY_DIR) ## Build MicroPython firmware with current drivers
@echo "Updating submodule to current HEAD..."
cd $(MPY_DIR)/lib/micropython-steami-lib && \
git fetch origin && \
git checkout $$(cd $(CURDIR) && git rev-parse HEAD)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “update submodule to current HEAD” logic is unlikely to work for local/unpushed commits: the submodule fetches only from its own origin, then tries to checkout a SHA from the parent repo. If that SHA isn’t present in the submodule clone, this will fail and it also won’t include uncommitted local changes. Consider fetching from the local working tree path (or setting the submodule URL to the local repo) and clarify whether users must commit changes before building firmware.

Suggested change
@echo "Updating submodule to current HEAD..."
cd $(MPY_DIR)/lib/micropython-steami-lib && \
git fetch origin && \
git checkout $$(cd $(CURDIR) && git rev-parse HEAD)
@echo "Updating submodule to current committed HEAD from local repo (uncommitted changes are not included)..."
cd $(MPY_DIR)/lib/micropython-steami-lib && \
git fetch "$(CURDIR)" HEAD && \
git checkout FETCH_HEAD

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95028ee. Replaced git fetch origin with a symlink: rm -rf ... && ln -s $(CURDIR) .... This way the firmware includes all local changes — even uncommitted ones — without needing to fetch or push.

@echo "Building firmware for $(BOARD)..."
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD)
@echo "Firmware ready: $(MPY_DIR)/ports/stm32/build-$(BOARD)/firmware.hex"

.PHONY: deploy
deploy: ## Flash firmware to the board via OpenOCD
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy assumes $(MPY_DIR) already exists; running make deploy in a clean repo will fail because the clone hasn’t happened yet. Make deploy depend on $(MPY_DIR) (and likely firmware if you expect a freshly built hex) so it works from a fresh checkout.

Suggested change
deploy: ## Flash firmware to the board via OpenOCD
deploy: firmware ## Flash firmware to the board via OpenOCD

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95028ee. deploy now depends on $(MPY_DIR) — ensures the clone exists but doesn't force a rebuild. Use make firmware deploy for a full build+flash.

cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) deploy-openocd

.PHONY: run
run: ## Copy and run a script on the board (SCRIPT=path/to/file.py)
@if [ -z "$(SCRIPT)" ]; then \
echo "Error: SCRIPT is required. Usage: make run SCRIPT=lib/.../example.py"; exit 1; \
fi
mpremote connect $(PORT) cp $(SCRIPT) :main.py
mpremote connect $(PORT) reset
@echo "Script deployed as main.py and board reset."
Comment on lines +111 to +125
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This run implementation uses mpremote ... cp directly and does not implement the “wait for PORT” step or the REPL chunked-write workaround described in issue #245 / #244. If the intent is to close #245, the target should match that workflow (or the docs/issue closure should be adjusted).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in 95028ee. make run now uses mpremote run for live output (no copy needed). The chunked-write workaround was only needed for mpremote cp with large files — tracked separately in #244. Added deploy-script for the autonomous copy-as-main.py use case.


.PHONY: firmware-clean
firmware-clean: ## Clean firmware build artifacts
@if [ -d "$(MPY_DIR)/ports/stm32" ]; then \
cd $(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) clean; \
fi

# --- Hardware ---

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

.PHONY: deepclean
deepclean: clean ## Remove everything including node_modules
deepclean: clean ## Remove everything including node_modules and firmware
rm -rf node_modules
@if [ -d "$(BUILD_DIR)" ]; then rm -rf $(BUILD_DIR); fi
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .ONESHELL mode, prefer quoting $(BUILD_DIR) in rm -rf (and you can usually drop the -d guard since rm -rf is already idempotent). Unquoted paths can behave unexpectedly if the variable is overridden with spaces or glob characters.

Suggested change
@if [ -d "$(BUILD_DIR)" ]; then rm -rf $(BUILD_DIR); fi
rm -rf "$(BUILD_DIR)"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 95028ee. Quoted $(BUILD_DIR) in rm -rf.


.PHONY: help
help: ## Show this help
Expand Down
7 changes: 7 additions & 0 deletions env.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export PATH := $(CURDIR)/node_modules/.bin:$(PATH)
PORT ?= /dev/ttyACM0

# Firmware build configuration
MICROPYTHON_REPO ?= https://github.com/steamicc/micropython-steami.git
MICROPYTHON_BRANCH ?= stm32-steami-rev1d-final
BOARD ?= STEAM32_WB55RG
BUILD_DIR ?= .build
MPY_DIR ?= $(BUILD_DIR)/micropython-steami
Loading