Draft
Conversation
…ction ## Major Features Added ### pyOCD Integration - Add SWD/JTAG programming as alternative to serial bootloader methods - Support for debug probe discovery and management - Automated target chip selection using dynamic detection - Optional pyOCD dependency via `pyocd` extra ### Dynamic Target Detection - Replace hardcoded target mappings with dynamic API-based detection - Parse MCU info from `sys.implementation._machine` strings - Fuzzy matching algorithm for target selection - Direct probe-based target detection with fallback to fuzzy matching - Extensible architecture for future OpenOCD/J-Link support ### CLI Integration - Add `--method pyocd` option for explicit SWD/JTAG programming - Add `--probe-id` option for specific debug probe selection - Maintain existing serial bootloader behavior as default - Clean integration with existing flash method selection ### Architecture Improvements - Abstract debug probe layer for extensibility - Target detector abstraction with registry system - Proper error handling and fallback mechanisms - Performance optimized with caching and lazy loading ## Technical Details ### Files Added - `mpflash/flash/debug_probe.py` - Debug probe abstraction layer - `mpflash/flash/pyocd_probe.py` - pyOCD-specific probe implementation - `mpflash/flash/pyocd_flash.py` - pyOCD flash programming interface - `mpflash/flash/pyocd_targets.py` - Target detection wrapper functions - `mpflash/flash/dynamic_targets.py` - Dynamic target detection engine - `mpflash/cli_pyocd.py` - pyOCD-specific CLI commands (future) ### Files Modified - `mpflash/common.py` - Add FlashMethod enum for different programming methods - `mpflash/flash/__init__.py` - Integrate pyOCD into flash method selection - `mpflash/cli_flash.py` - Add CLI options for pyOCD method and probe selection - `pyproject.toml` - Add optional pyOCD dependency - `mpflash/cli_download.py` - Fix unused pytest import ### Key Benefits - **No hardware requirements change** - existing serial methods remain default - **Automated target selection** - no manual target configuration needed - **Extensible design** - easy to add OpenOCD, J-Link, etc. in future - **Performance optimized** - direct API calls instead of subprocess shells - **Maintainable** - eliminates hardcoded target mappings ## Usage ```bash # Existing behavior unchanged (serial bootloader methods) mpflash flash # Explicit pyOCD SWD/JTAG programming mpflash flash --method pyocd # Specific debug probe selection mpflash flash --method pyocd --probe-id stlink # Install with pyOCD support uv sync --extra pyocd ``` ## Breaking Changes None - all existing functionality preserved with same default behavior.
Integrate mpbuild for building MicroPython firmware locally. - Add BuildManager class with caching for 5-30 minute builds - Implement firmware import to mpflash database - Add --build CLI flag with comprehensive error handling - Support Python 3.10+ requirement with clear messaging
When no --board is specified, use --serial parameter for board detection instead of scanning all ports. This ensures specific serial devices are targeted even during auto-detection. - Use params.serial instead of params.ports in connected_ports_boards_variants() - Only fall back to params.ports when --serial is '*' (scan all) - Prevents unnecessary port scanning when specific device is requested
Author
|
Again, I haven't code reviewed this at all yet, so feel free to not look at it at all either until I do so and un-draft the PR! |
Owner
|
Thanks for making a start on this, I'll be patient 😁 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.