Skip to main content

CI/CD toolkit for flashing and testing embedded devices

Project description

bmlab-toolkit

CI/CD toolkit for flashing and testing embedded devices.

Features

  • Flash embedded devices (currently supports JLink)
  • List and detect connected programmers
  • Automatic STM32 device detection (F1/F4/F7/G0 series)
  • Support for multiple firmware formats (.hex, .bin)
  • Real-Time Transfer (RTT) support - Connect to device RTT for real-time communication
  • Single unified command-line interface
  • Extensible architecture for supporting additional programmers

Installation

pip install bmlab-toolkit

Usage

Command Line

List connected programmers:

bmlab-flash
# or specify programmer type
bmlab-flash --programmer jlink

Flash a device with auto-detected programmer (uses first available JLink):

bmlab-flash <firmware_file>

Flash with specific serial number:

bmlab-flash <firmware_file> --serial <serial_number>

Flash with specific MCU:

bmlab-flash <firmware_file> --mcu STM32F765ZG

Specify programmer explicitly:

bmlab-flash <firmware_file> --programmer jlink --serial 123456

Get help:

bmlab-flash --help

RTT (Real-Time Transfer)

Connect to JLink RTT for real-time communication with the target device:

# Connect with auto-detection and read for 10 seconds
bmlab-jlink-rtt

# Specify JLink serial number
bmlab-jlink-rtt --serial 123456789

# Connect via IP address (no MCU needed)
bmlab-jlink-rtt --ip 192.168.1.100

# Specify MCU explicitly
bmlab-jlink-rtt --mcu STM32F765ZG

# Read indefinitely until Ctrl+C
bmlab-jlink-rtt -t 0

# Send message after connection
bmlab-jlink-rtt --msg "hello\n"

# Send message after custom delay
bmlab-jlink-rtt --msg "test" --msg-timeout 2.0

# Connect without resetting target
bmlab-jlink-rtt --no-reset

# Verbose output
bmlab-jlink-rtt -v

Get RTT help:

bmlab-jlink-rtt --help

Python API

Flashing

from bmlab_toolkit import JLinkProgrammer

# Create programmer instance (auto-detect serial)
prog = JLinkProgrammer()

# Or specify serial number
prog = JLinkProgrammer(serial=123456789)

# Flash firmware (auto-detect MCU)
prog.flash("firmware.hex")

# Flash with specific MCU
prog.flash("firmware.hex", mcu="STM32F765ZG")

# Flash without reset
prog.flash("firmware.hex", reset=False)

RTT Communication

from bmlab_toolkit import JLinkProgrammer
import time

# Create programmer
prog = JLinkProgrammer(serial=123456789)

try:
    # Connect to target
    prog._connect_target(mcu="STM32F765ZG")
    
    # Reset device (optional)
    prog.reset(halt=False)
    time.sleep(0.5)
    
    # Start RTT
    prog.start_rtt(delay=1.0)
    
    # Send data
    prog.rtt_write(b"Hello, device!\n")
    
    # Read data
    data = prog.rtt_read(max_bytes=4096)
    if data:
        print(data.decode('utf-8', errors='replace'))
    
    # Stop RTT
    prog.stop_rtt()
    
finally:
    # Disconnect
    prog._disconnect_target()

Development

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

Currently Supported

Programmers

  • JLink (via pylink-square)

Devices

  • STM32F1 series (Low/Medium/High/XL density, Connectivity line)
  • STM32F4 series (F405/407/415/417, F427/429/437/439)
  • STM32F7 series (F74x/75x, F76x/77x)
  • STM32G0 series (G0x0, G0x1, G0Bx/G0Cx)

Roadmap

Planned Features

  • Device Testing - Automated testing capabilities

    • Run tests on connected devices
    • Collect and analyze test results via RTT
    • Generate test reports
  • Additional Programmers

    • ST-Link support
    • OpenOCD support
    • Custom programmer interfaces

Extending with New Programmers

The library is organized into functional modules:

  • constants.py - Programmer type constants
  • list_devices.py - Device detection and listing functionality
  • flashing.py - Flashing operations
  • jlink_device_detector.py - STM32-specific device detection

To add support for a new programmer:

  1. Add the programmer constant to src/bmlab_toolkit/constants.py:
PROGRAMMER_STLINK = "stlink"
SUPPORTED_PROGRAMMERS = [PROGRAMMER_JLINK, PROGRAMMER_STLINK]
  1. Implement device listing in src/bmlab_toolkit/list_devices.py:
def _get_stlink_devices() -> List[Dict[str, Any]]:
    # Implementation here
    pass

# Update get_connected_devices() function to handle new programmer
  1. Implement flashing function in src/bmlab_toolkit/flashing.py:
def _flash_with_stlink(serial: int, fw_file: str, mcu: str = None) -> None:
    # Implementation here
    pass

# Add case in flash_device_by_usb()
elif programmer_lower == PROGRAMMER_STLINK:
    _flash_with_stlink(serial, fw_file, mcu)
  1. Update documentation and tests

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bmlab_toolkit-0.1.3.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bmlab_toolkit-0.1.3-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file bmlab_toolkit-0.1.3.tar.gz.

File metadata

  • Download URL: bmlab_toolkit-0.1.3.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for bmlab_toolkit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 87ac14c14fc31a350bddb38737c42ed7c82087dd5535fec0a119957255c92a52
MD5 a09661f757e8ba00c85e790e65743146
BLAKE2b-256 fe0846679ef74197f5aee29a13892949d8c8a436e8ad71ab188cb5f90aab9f69

See more details on using hashes here.

File details

Details for the file bmlab_toolkit-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: bmlab_toolkit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for bmlab_toolkit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f6022383520d892b656a03bc6124db0843457baa438725f862f756da326503f3
MD5 3b178ecd138c978c992be640d277aa91
BLAKE2b-256 5691954be2987eba9e19f77e2b367705a435cefc42594b3c02617aa7183938b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page