|
|
|
@ -1,18 +1,26 @@ |
|
|
|
import logging |
|
|
|
import subprocess |
|
|
|
from pathlib import Path |
|
|
|
from typing import Sequence, Union |
|
|
|
from typing import Sequence |
|
|
|
from typing import Union |
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
|
|
|
|
logger = logging.getLogger("Download") |
|
|
|
|
|
|
|
# APPLICATION_NAME = "nucleo-wb55-ble" |
|
|
|
APPLICATION_NAME = "nucleo-wb55-dongle-ble" |
|
|
|
#APPLICATION_NAME = "nucleo-wb55-dongle-usb" |
|
|
|
#APPLICATION_NAME = "nucleo-wb55-dongle-blinky" |
|
|
|
PORT="USB1" |
|
|
|
CLI_PATH = Path("/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI") |
|
|
|
ELF_FILE = Path.home() / Path(f"Documents/git/nucleo-playground-workspace/{APPLICATION_NAME}/Debug/{APPLICATION_NAME}.elf") |
|
|
|
# APPLICATION_NAME = "nucleo-wb55-dongle-usb" |
|
|
|
# APPLICATION_NAME = "nucleo-wb55-dongle-blinky" |
|
|
|
PORT = "USB1" |
|
|
|
CLI_PATH = Path( |
|
|
|
"/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/" |
|
|
|
"STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI", |
|
|
|
) |
|
|
|
ELF_FILE = Path.home() / Path( |
|
|
|
f"Documents/git/nucleo-playground-workspace/{APPLICATION_NAME}/" |
|
|
|
f"Debug/{APPLICATION_NAME}.elf", |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def execute_command( |
|
|
|
@ -26,17 +34,17 @@ def execute_command( |
|
|
|
) |
|
|
|
|
|
|
|
def _poll_stdout() -> str: |
|
|
|
return process.stdout.readline().decode() |
|
|
|
return process.stdout.readline().decode() # type: ignore |
|
|
|
|
|
|
|
exit_code = None |
|
|
|
command_logger = logger.getChild("Programmer") |
|
|
|
while exit_code is None: |
|
|
|
for line in iter(_poll_stdout, ''): |
|
|
|
for line in iter(_poll_stdout, ""): |
|
|
|
command_logger.info(line.rstrip()) |
|
|
|
|
|
|
|
exit_code = process.poll() |
|
|
|
|
|
|
|
for line in iter(_poll_stdout, ''): |
|
|
|
for line in iter(_poll_stdout, ""): |
|
|
|
command_logger.info(line.rstrip()) # flush pipe |
|
|
|
|
|
|
|
logger.debug(f"Coomand finished with exit code {exit_code}") |
|
|
|
@ -48,7 +56,8 @@ def download(): |
|
|
|
str(CLI_PATH), |
|
|
|
"-c", |
|
|
|
f"port={PORT}", |
|
|
|
"-w", str(ELF_FILE), |
|
|
|
"-w", |
|
|
|
str(ELF_FILE), |
|
|
|
] |
|
|
|
execute_command(command) |
|
|
|
|
|
|
|
|