-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflasher.py
70 lines (55 loc) · 1.7 KB
/
flasher.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# A thin wrapper around the stm32loader.
# Build on top of stm32loader
# https://pypi.org/project/stm32loader/
# https://github.com/florisla/stm32loader
import stm32loader.main as loader
import sys
import argparse
import os.path
# Local imports
sys.path.insert(0, "..")
from lib.sys_config import SysConfig
parser = argparse.ArgumentParser()
parser.add_argument(
"--sys_config",
dest="sys_config",
default="sys_config.toml",
help="Path to system configuration file.",
)
parser.add_argument(
"--firmware",
dest="firmware",
default="controller_firmware.bin",
help="Path to firmware .bin file.",
)
parser.add_argument(
"--dry_run",
dest="dry_run",
default=False,
action=argparse.BooleanOptionalAction,
help="If true, ID the MCU and exit without flashing.",
)
args = parser.parse_args()
sys_config = SysConfig()
sys_config.load_from_file(args.sys_config)
serial_port = sys_config.data_link_port()
print(f"Dry run mode: {args.dry_run}", flush=True)
print(f"Sys config file: {args.sys_config}", flush=True)
print(f"Firmware file: {args.firmware}", flush=True)
print(f"Serial port: {serial_port}", flush=True)
# Construct the loader command line params
params = []
params.extend(["-p", serial_port])
params.extend(["-f", "H7"])
if not args.dry_run:
params.extend(["-e"])
params.extend(["-w"])
params.extend(["-v"])
if not os.path.exists(args.firmware):
print(f"Firmware file {args.firmware} not found. Check the --firmware flag.")
sys.exit(1)
params.extend([args.firmware])
#print(f"Constructed params: {params}", flush=True)
print(f"Equivalent command: {'stm32loader ' + " ".join(params) }", flush=True)
# Call the loader
loader.main(*params)