Skip to content

Commit

Permalink
Force attempting to write unit 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohrer committed Dec 8, 2023
1 parent e9aaabf commit 5e2d875
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions amplipi/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,21 @@ def program(self, filepath: str, unit: int = 0, baud: int = 115200) -> bool:
print(f"Setting {self.unit_num_to_name(p)}'s UART as passthrough")
self.preamps[p].uart_passthrough(True)

# Before attempting programming, verify the unit even exists.
try:
subprocess.run([f'stm32flash -b {baud} {PI_SERIAL_PORT}'], shell=True,
check=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError:
# Failed to handshake with the bootloader. Assume unit not present.
print(f"Couldn't communicate with {self.unit_num_to_name(unit)}'s bootloader.")
plural = 's are' if unit != 1 else ' is'
print(f'Assuming only {unit} unit{plural} present and stopping programming')

# Reset all units to make sure the UART passthrough and
# bootloader modes are cleared.
self.reset()
return False
if unit > 1:
# Before attempting programming, verify the unit even exists.
try:
subprocess.run([f'stm32flash -b {baud} {PI_SERIAL_PORT}'], shell=True,
check=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError:
# Failed to handshake with the bootloader. Assume unit not present.
print(f"Couldn't communicate with {self.unit_num_to_name(unit)}'s bootloader.")
plural = 's are' if unit != 1 else ' is'
print(f'Assuming only {unit} unit{plural} present and stopping programming')

# Reset all units to make sure the UART passthrough and
# bootloader modes are cleared.
self.reset()
return False

prog_success = False
try:
Expand Down

0 comments on commit 5e2d875

Please sign in to comment.