Skip to content

Pyocd rebased#67

Open
Josverl wants to merge 7 commits intomainfrom
pyocd-rebased
Open

Pyocd rebased#67
Josverl wants to merge 7 commits intomainfrom
pyocd-rebased

Conversation

@Josverl
Copy link
Copy Markdown
Owner

@Josverl Josverl commented Apr 2, 2026

this is a rebased version of #36 by Andrew.

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

pi-anl and others added 2 commits April 2, 2026 00:56
…ction

- 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

- 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

- 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

- 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

- `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)

- `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

- **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

```bash
mpflash flash

mpflash flash --method pyocd

mpflash flash --method pyocd --probe-id stlink

uv sync --extra pyocd
```

None - all existing functionality preserved with same default behavior.
- Updated test cases in `test_cli_integration.py` to replace `flash_list` with `flash_tasks` for flashing operations.
- Adjusted mock setups and assertions accordingly to ensure correct behavior and parameter passing.
- Improved test structure by consolidating mock patches and ensuring proper cleanup in setup and teardown methods.
- Enhanced clarity in test descriptions and assertions to better reflect the expected outcomes.
- Ensured consistent use of `create_worklist` in tests where applicable.
- Refactored related tests to maintain functionality while improving readability and maintainability.

Refactor probe management tests for clarity and consistency

- Updated `test_probe_management.py` to improve import organization and mock usage.
- Consolidated mock patches for better readability and reduced redundancy.
- Enhanced test descriptions for clarity on the purpose of each test case.
- Improved handling of mock return values and assertions to ensure accurate testing of probe discovery and flashing functionality.

Refactor target detection tests for improved structure and clarity

- Updated `test_target_detection.py` to enhance the organization of imports and mock usage.
- Improved test descriptions and assertions for better clarity on expected outcomes.
- Consolidated mock patches and ensured proper setup and teardown for target detection tests.
- Enhanced handling of subprocess calls and error scenarios to ensure robustness in testing.

Overall, these changes aim to improve the readability, maintainability, and reliability of the test suite while ensuring that all functionality remains intact.

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 53.61803% with 391 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.51%. Comparing base (d123e45) to head (4987bd5).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
mpflash/cli_pyocd.py 0.00% 146 Missing ⚠️
mpflash/flash/pyocd_core.py 61.84% 95 Missing and 21 partials ⚠️
mpflash/flash/pyocd_flash.py 39.22% 109 Missing and 1 partial ⚠️
mpflash/flash/__init__.py 81.15% 6 Missing and 7 partials ⚠️
mpflash/flash/debug_probe.py 90.32% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #67      +/-   ##
==========================================
- Coverage   74.53%   70.51%   -4.02%     
==========================================
  Files          54       58       +4     
  Lines        2929     3744     +815     
  Branches      464      602     +138     
==========================================
+ Hits         2183     2640     +457     
- Misses        620      965     +345     
- Partials      126      139      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Josverl
Copy link
Copy Markdown
Owner Author

Josverl commented Apr 2, 2026

@pi-anl , I have tried to bang this into shape - but cant really tests this as I don't have the hardware.

Or is it worth testing part of this on other HW ? (not a PyOCD user yet)

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@Josverl Josverl force-pushed the pyocd-rebased branch 2 times, most recently from a947bae to 495088d Compare April 5, 2026 20:24
see: pyocd/libusb-package#28

Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
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.

2 participants