Skip to content

Conversation

@andrewleech
Copy link

Major Features Added

pyOCD Integration

  • Add SWD/JTAG programming as alternative to usb bootloader methods
  • Optional pyOCD dependency via pyocd extra
  • Support for debug probe discovery and management
  • Automated target chip selection using dynamic detection

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 option for specific debug probe selection
  • Maintain existing 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

# 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.

@andrewleech
Copy link
Author

andrewleech commented Aug 19, 2025

Hi @Josverl I'm not sure what your appetite is for large changes or if this a direction you like, but I wanted to use it so claude build it :-)

Also, 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!

@andrewleech andrewleech mentioned this pull request Aug 19, 2025
@Josverl
Copy link
Owner

Josverl commented Aug 20, 2025

If you build it, you test it😜

I have found the challenge that in the HIL tests needed. I'm not sure if I have the equipment to test it.

Other than that, if others can benefit from it, I think it is useful

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants