aboutsummaryrefslogtreecommitdiff
path: root/examples/teensy4_blinky/run.py
blob: 1e2fbf3925983ada0bac61e7e3a9a7632d2e0ff2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python

from pathlib import Path
from tempfile import TemporaryDirectory

import subprocess
import sys


def main():
    if len(sys.argv) < 2:
        print("Please provide the binary as first argument!")
        exit(1)

    binary = sys.argv[1]
    print(f"Flashing {binary} ...")

    with TemporaryDirectory() as tmpdir:
        tmpdir = Path(tmpdir)
        hexfile = tmpdir / "firmware.hex"

        subprocess.run(["rust-objcopy", "-O", "ihex", binary, hexfile], check=True)
        subprocess.run(["teensy_loader_cli", "--mcu=imxrt1062", "-wv", hexfile], check=True)

    print("Teensy successfully flashed.")


if __name__ == "__main__":
    main()