Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this is stacked on top of #36 so includes that commit too.
Add --build flag for local MicroPython firmware building
Overview
This PR adds a
--buildflag to mpflash that integrates with mpbuild to build MicroPython firmware locally. This solves a critical compatibility issue where pyOCD SWD/JTAG programming requires.hex/.bin/.elffiles, but only.dfufiles are available from micropython.org downloads.Problem Statement
When using
--method pyocdfor SWD/JTAG programming, users encounter errors like:This happens because:
.hex,.bin, or.elffirmware files.dfufiles for most STM32 boardsSolution
The
--buildflag enables local firmware building that generates all formats needed by different flash methods:Key Features
🏗️ Complete Build Integration
.dfu,.hex,.bin,.elf⚡ Smart Caching System
🔄 Database Integration
.hex, DFU prefers.dfu)🛡️ Robust Error Handling
🎯 Backward Compatibility
Technical Implementation
Core Architecture
CLI Integration
The
--buildflag is added to theflashcommand:Dependencies
uv sync --extra build)Usage Examples
Basic Local Build
pyOCD SWD/JTAG Programming
# Now works! Generates .hex files for pyOCD mpflash flash --build --method pyocd --board STM32F4DISCForce Rebuild
# Bypass cache and rebuild mpflash flash --build --force --board NUCLEO_H563ZIError Handling
Python Version Check
Docker Requirement
Missing mpbuild
Files Changed
mpflash/build.py(NEW, 410 lines): Complete build management systemmpflash/cli_flash.py(+40 lines): CLI integration and build workflowpyproject.toml(+3 lines): Optional mpbuild dependencyuv.lock(+66 lines): Dependency lockfile updatesTesting
The implementation includes comprehensive error handling and has been tested with:
Benefits
Migration Path
This is a purely additive feature:
--buildflag when neededFuture Enhancements
Before this PR: pyOCD fails with DFU files ❌
After this PR:
--buildgenerates all formats ✅This addresses a fundamental compatibility gap and provides a foundation for advanced local development workflows.