5 def get_commands(env
, firmware
):
7 platform_name
= platform
.system().lower()
12 flash_start
= app_start
= 0x08000000
14 upload_flags
= env
.get('UPLOAD_FLAGS', [])
16 for line
in upload_flags
:
19 if "BOOTLOADER=" in flag
:
20 bootloader
= flag
.split("=")[1]
21 elif "VECT_OFFSET=" in flag
:
22 offset
= flag
.split("=")[1]
24 offset
= int(offset
, 16)
26 offset
= int(offset
, 10)
27 app_start
= flash_start
+ offset
28 env_dir
= env
['PROJECT_PACKAGES_DIR']
29 if "windows" in platform_name
:
32 "tool-stm32duino", "stlink", "ST-LINK_CLI.exe")
34 if bootloader
is not None:
35 BL_CMD
= [TOOL
, "-c SWD SWCLK=8 -P",
36 bootloader
, hex(flash_start
)]
37 APP_CMD
= [TOOL
, "-c SWD SWCLK=8 -P",
38 firmware
, hex(app_start
), "-RST"]
39 elif "linux" in platform_name
or "darwin" in platform_name
:
42 "tool-stm32duino", "stlink", "st-flash")
43 if bootloader
is not None:
44 BL_CMD
= [TOOL
, "write", bootloader
, hex(flash_start
)]
45 APP_CMD
= [TOOL
, "--reset", "write", firmware
, hex(app_start
)]
46 elif "os x" in platform_name
:
47 print("OS X not supported at the moment\n")
50 print("Operating system: "+ platform_name
+ " is not supported.\n")
53 return " ".join(BL_CMD
), " ".join(APP_CMD
)
56 def on_upload(source
, target
, env
):
57 firmware_path
= str(source
[0])
59 BL_CMD
, APP_CMD
= get_commands(env
, firmware_path
)
64 print("Cmd: {}".format(BL_CMD
))
65 retval
= env
.Execute(BL_CMD
)
67 if retval
== 0 and APP_CMD
:
68 print("Cmd: {}".format(APP_CMD
))
69 retval
= env
.Execute(APP_CMD
)