Skip to main content

Create and split micro:bit Universal Hex files

Project description

Python Universal Hex Library

A Python library to create and process micro:bit Universal Hex files.

Universal Hex is a superset of the Intel Hex format that can contain data for multiple micro:bit board versions (V1 and V2) in a single file.

Installation

To get easy access to the Universal Hex command line interface we recommend using uv:

uv tool install universal-hex

It can also be pip installed as a normal Python package and used as a library.

pip install universal-hex

Command Line Interface

A CLI is provided via the uhex entry point.

The separate command takes a Universal Hex file and created

# Separate a single Universal Hex into board-specific files
uhex separate file.hex

The join command takes multiple Intel Hex files to combine them into a Universal Hex:

# Join Intel Hex files for micro:bit V1 and V2 boards
uhex join --v1 one.hex --v2 two.hex

# Join using custom board IDs (repeat -b as needed)
uhex join -b 12345 board_a.hex -b 42 board_b.hex

# Mix V1/V2 with custom board IDs
uhex join --v1 one.hex -b 12345 other.hex --v2 two.hex
  • separate writes one output per board next to the input file using the pattern <input-stem>-board-<BOARD_ID>.hex (e.g. firmware-board-9900.hex).
  • join reads all provided hex files and writes the Universal Hex to stdout.
  • Validation happens during CLI parsing: files must exist, must not be directories, must end with .hex, and board IDs must be within 0–65535.

Library Usage

Creating a Universal Hex

from universal_hex import create_uhex, IndividualHex, BoardId

# Load your V1 and V2 hex files
v1_hex = open("program_v1.hex").read()
v2_hex = open("program_v2.hex").read()

# Create a Universal Hex
uhex = create_uhex([
    IndividualHex(hex=v1_hex, board_id=BoardId.V1),
    IndividualHex(hex=v2_hex, board_id=BoardId.V2),
])

# Save the result (always use \n line endings)
with open("program_universal.hex", "w", newline="\n") as f:
    f.write(uhex)

Separating a Universal Hex

from universal_hex import separate_uhex

# Load a Universal Hex file
uhex = open("program_universal.hex").read()

# Separate into individual Intel Hex files
ihexes = separate_uhex(uhex)

for ihex in ihexes:
    print(f"Board ID: 0x{ihex.board_id:04X}")
    # ihex.hex contains the Intel Hex content for this board

Checking if a file is a Universal Hex

from universal_hex import is_uhex

hex_content = open("some_file.hex").read()

if is_uhex(hex_content):
    print("This is a Universal Hex file")
else:
    print("This is a standard Intel Hex file")

Development

# Clone
git clone https://github.com/carlosperate/python-universal-hex.git
cd python-universal-hex

# Install with dev dependencies
uv sync

# Run all checkers and tests
uv run make.py check

License

MIT License - see LICENSE for details.

Related Projects

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

universal_hex-0.0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

universal_hex-0.0.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file universal_hex-0.0.1.tar.gz.

File metadata

  • Download URL: universal_hex-0.0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for universal_hex-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4b63dd8ebd7d71ac08b3ce5d05ea86bcc18b0c8c5d4d1815371d1350148c70d3
MD5 e7703d03c3b9b3ff7c813798b9eed25b
BLAKE2b-256 e1a28ee0c854d7759d7c6b45d305a66d1e11388d2bca1d46565af72b89d355ca

See more details on using hashes here.

File details

Details for the file universal_hex-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: universal_hex-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for universal_hex-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9acf6eaf0e9d92fa5aff463f70ffce430c22dd0afb2da13ca6adb321ff9f3af4
MD5 80a7905b1ee29fe80d8eb11d4ceedd0f
BLAKE2b-256 481a8bca4f9674a1b3c26c4067495e484b02f68c3a0b74ac5a32af57c339a96a

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