Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env sh
if [ ! -d node_modules ]; then
echo "Error: node_modules is missing. Run 'make setup' or 'npm install' first."
exit 1
fi
npx --no-install commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env sh
if [ ! -d node_modules ]; then
echo "Error: node_modules is missing. Run 'make setup' or 'npm install' first."
exit 1
fi
npx --no-install validate-branch-name && npx --no-install git-precommit-checks && npx --no-install lint-staged
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ test(mcp23009e): Add mock scenarios for mcp23009e driver.
5. Commit — the git hooks will automatically check your commit message and run ruff on staged files
6. Push your branch and open a Pull Request

If git hooks fail because `node_modules/` is missing (for example on a fresh clone or after `make deepclean`), run `make setup` or `npm install` before committing.

## Continuous Integration

All pull requests must pass these checks:
Expand Down Expand Up @@ -122,6 +124,26 @@ 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), link local drivers, build
make firmware-update # Refresh the MicroPython clone and board-specific submodules
make deploy # Flash firmware via OpenOCD
make run SCRIPT=lib/steami_config/examples/show_config.py # Run with live output
make deploy-script SCRIPT=lib/.../calibrate_magnetometer.py # Deploy as main.py for autonomous use
make run-main # Re-execute the deployed main.py
make firmware-clean # Clean firmware build artifacts
```

The firmware source is cloned into `.build/micropython-steami/` (gitignored). A symbolic link replaces the submodule `lib/micropython-steami-lib` with your local working directory, so the firmware always includes your latest changes — even uncommitted ones.

Use `make firmware` for normal rebuilds from the existing local clone. Use `make firmware-update` only when you want to refresh the `micropython-steami` checkout itself or resync the board-specific submodules before rebuilding.

**Requirements**: `arm-none-eabi-gcc` toolchain, OpenOCD for flashing, and `mpremote` for running scripts on the board.

## Notes

* Keep implementations simple and readable
Expand Down
60 changes: 58 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,61 @@ 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 $(CURDIR)/$(MPY_DIR)..."
@mkdir -p $(dir $(CURDIR)/$(MPY_DIR))
git clone --branch $(MICROPYTHON_BRANCH) $(MICROPYTHON_REPO) $(CURDIR)/$(MPY_DIR)
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) submodules

.PHONY: firmware
firmware: $(MPY_DIR) ## Build MicroPython firmware with current drivers
@echo "Linking local drivers..."
rm -rf $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
ln -s $(CURDIR) $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
@echo "Building firmware for $(BOARD)..."
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD)
@echo "Firmware ready: $(CURDIR)/$(MPY_DIR)/ports/stm32/build-$(BOARD)/firmware.hex"

.PHONY: firmware-update
firmware-update: $(MPY_DIR) ## Update the MicroPython clone and board-specific submodules
@echo "Updating micropython-steami..."
rm -rf $(CURDIR)/$(MPY_DIR)/lib/micropython-steami-lib
cd $(CURDIR)/$(MPY_DIR) && git fetch origin && git checkout $(MICROPYTHON_BRANCH) && git checkout -- lib/micropython-steami-lib && git pull --ff-only
@echo "Updating required submodules for $(BOARD)..."
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) submodules

.PHONY: deploy
deploy: $(MPY_DIR) ## Flash firmware to the board via OpenOCD
cd $(CURDIR)/$(MPY_DIR)/ports/stm32 && $(MAKE) BOARD=$(BOARD) deploy-openocd

.PHONY: run
run: ## Run a script on the board with live output (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) run $(SCRIPT)

.PHONY: deploy-script
deploy-script: ## Deploy a script as main.py for autonomous execution (SCRIPT=path/to/file.py)
@if [ -z "$(SCRIPT)" ]; then \
echo "Error: SCRIPT is required. Usage: make deploy-script 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: run-main
run-main: ## Re-execute main.py on the board and capture output
mpremote connect $(PORT) exec "exec(open('/flash/main.py').read())"

.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 +196,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

.PHONY: help
help: ## Show this help
Expand All @@ -159,4 +215,4 @@ printvars:
# Affiche toutes les cibles disponibles dans le Makefile
.PHONY: list
list:
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
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