Skip to content
Open
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
59 changes: 59 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Cross platform shebang:
shebang := if os() == 'windows' {
'pwsh.exe'
} else {
'/usr/bin/env pwsh'
}

# Set shell for non-Windows OSs:
set shell := ["pwsh", "-c"]

# Set shell for Windows OSs:
set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"]

# Show recipes
help:
@just --list



# install project in edi mode and install dev dependencies
sync:
uv sync --extra dev,test

# run full pytest suite
test:
uv run pytest -v

# create coverage report, build html report
coverage:
uv run pytest --cov --cov-report=term-missing
coverage html
start coverage/index.html

# bump mpflash's version
bump bump="patch":
uv version --bump {{bump}}

# build the project for distribution
build:
uv build

# publish the project to PyPI
publish : build
uv publish

# delete and regen the lockfile - useful in merge conficts
lock:
#!{{shebang}}
del uv.lock -erroraction ignore
uv lock


# [script('python')]
# python:
# print('Hello from python!')
# from pathlib import Path
# print(f'Current directory: {Path.cwd()}')


2 changes: 0 additions & 2 deletions mpflash/cli_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""CLI to Download MicroPython firmware for specific ports, boards and versions."""

from pathlib import Path

import rich_click as click
from loguru import logger as log
Expand All @@ -15,7 +14,6 @@
from .ask_input import ask_missing_params
from .cli_group import cli
from .common import DownloadParams
from .config import config
from .download import download


Expand Down
46 changes: 40 additions & 6 deletions mpflash/cli_flash.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sys
from typing import List

import rich_click as click
from loguru import logger as log

import mpflash.download.jid as jid
import mpflash.mpboard_id as mpboard_id
import rich_click as click
from loguru import logger as log
from mpflash.ask_input import ask_missing_params
from mpflash.cli_download import connected_ports_boards_variants
from mpflash.cli_group import cli
from mpflash.cli_list import show_mcus
from mpflash.common import BootloaderMethod, FlashParams, filtered_comports
from mpflash.common import BootloaderMethod, FlashMethod, FlashParams, filtered_comports
from mpflash.errors import MPFlashError
from mpflash.flash import flash_tasks
from mpflash.flash.worklist import FlashTaskList, create_worklist
Expand Down Expand Up @@ -112,6 +112,27 @@
show_default=True,
help="""How to enter the (MicroPython) bootloader before flashing.""",
)
@click.option(
"--method",
"--flash-method",
"flash_method",
type=click.Choice([e.value for e in FlashMethod]),
default="auto",
show_default=True,
help="""Flash programming method. 'auto' uses serial bootloader methods (existing behavior). Use 'pyocd' for SWD/JTAG programming via debug probe.""",
)
@click.option(
"--probe",
"--probe-id", # Keep as alias for backwards compatibility
"probe_id",
help="""Specific pyOCD probe ID to use (partial match). Required when multiple probes are connected.""",
metavar="PROBE_ID",
)
@click.option(
"--auto-install-packs/--no-auto-install-packs",
default=True,
help="""Automatically install CMSIS packs for missing pyOCD targets. Default: enabled.""",
)
@click.option(
"--force",
"-f",
Expand Down Expand Up @@ -144,6 +165,14 @@ def cli_flash_board(**kwargs) -> int:
kwargs.pop("board")
else:
kwargs["boards"] = [kwargs.pop("board")]

# Convert flash_method to method and convert to enum
flash_method_str = kwargs.pop("flash_method", "auto")
flash_method = FlashMethod(flash_method_str)

# Extract pyOCD options
probe_id = kwargs.pop("probe_id", None)
auto_install_packs = kwargs.pop("auto_install_packs", True)

params = FlashParams(**kwargs)
params.versions = list(params.versions)
Expand Down Expand Up @@ -187,7 +216,7 @@ def cli_flash_board(**kwargs) -> int:
# Ask for missing input if needed
params = ask_missing_params(params)
if not params: # Cancelled by user
return 2
sys.exit(2)
assert isinstance(params, FlashParams)

if len(params.versions) > 1:
Expand Down Expand Up @@ -240,6 +269,7 @@ def cli_flash_board(**kwargs) -> int:
params.versions[0],
serial_ports=comports,
board_id=board_id,
custom_firmware=params.custom,
port=params.ports[0] if params.ports else None,
)
else:
Expand All @@ -251,15 +281,19 @@ def cli_flash_board(**kwargs) -> int:
)
if not params.custom:
jid.ensure_firmware_downloaded_tasks(tasks, version=params.versions[0], force=params.force)
# TODO: CHECK MERGE
if flashed := flash_tasks(
tasks,
params.erase,
params.bootloader,
method=flash_method,
probe_id=probe_id,
auto_install_packs=auto_install_packs,
flash_mode=params.flash_mode,
):
log.info(f"Flashed {len(flashed)} boards")
show_mcus(flashed, title="Updated boards after flashing")
return 0
else:
log.error("No boards were flashed")
return 1
sys.exit(1)
Loading
Loading