mirror of https://github.com/Desuuuu/klipper.git
spi_flash: validate mcu configuration
Prior to attempting a flash, verify that the MCU is successfully configured. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
5517a856cc
commit
ccae1e3ec8
|
@ -119,6 +119,9 @@ FINALIZE_CFG_CMD = "finalize_config crc=%d"
|
||||||
class SPIFlashError(Exception):
|
class SPIFlashError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class MCUConfigError(SPIFlashError):
|
||||||
|
pass
|
||||||
|
|
||||||
class SPIDirect:
|
class SPIDirect:
|
||||||
def __init__(self, ser):
|
def __init__(self, ser):
|
||||||
self.oid = SPI_OID
|
self.oid = SPI_OID
|
||||||
|
@ -862,8 +865,7 @@ class MCUConnection:
|
||||||
self._serial.disconnect()
|
self._serial.disconnect()
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
def check_need_restart(self):
|
def get_mcu_config(self):
|
||||||
output("Checking Current MCU Configuration...")
|
|
||||||
# Iterate through backwards compatible response strings
|
# Iterate through backwards compatible response strings
|
||||||
for response in GET_CFG_RESPONSES:
|
for response in GET_CFG_RESPONSES:
|
||||||
try:
|
try:
|
||||||
|
@ -875,7 +877,11 @@ class MCUConnection:
|
||||||
if response == GET_CFG_RESPONSES[-1]:
|
if response == GET_CFG_RESPONSES[-1]:
|
||||||
raise err
|
raise err
|
||||||
output("Trying fallback...")
|
output("Trying fallback...")
|
||||||
params = get_cfg_cmd.send()
|
return get_cfg_cmd.send()
|
||||||
|
|
||||||
|
def check_need_restart(self):
|
||||||
|
output("Checking Current MCU Configuration...")
|
||||||
|
params = self.get_mcu_config()
|
||||||
output_line("Done")
|
output_line("Done")
|
||||||
if params['is_config'] or params['is_shutdown']:
|
if params['is_config'] or params['is_shutdown']:
|
||||||
output_line("MCU needs restart: is_config=%d, is_shutdown=%d"
|
output_line("MCU needs restart: is_config=%d, is_shutdown=%d"
|
||||||
|
@ -926,9 +932,12 @@ class MCUConnection:
|
||||||
self._serial.send(bus_cmd)
|
self._serial.send(bus_cmd)
|
||||||
config_crc = zlib.crc32('\n'.join(cfg_cmds).encode()) & 0xffffffff
|
config_crc = zlib.crc32('\n'.join(cfg_cmds).encode()) & 0xffffffff
|
||||||
self._serial.send(FINALIZE_CFG_CMD % (config_crc,))
|
self._serial.send(FINALIZE_CFG_CMD % (config_crc,))
|
||||||
|
config = self.get_mcu_config()
|
||||||
|
if not config["is_config"] or config["is_shutdown"]:
|
||||||
|
raise MCUConfigError("Failed to configure MCU")
|
||||||
|
printfunc("Initializing SD Card and Mounting file system...")
|
||||||
self.fatfs = FatFS(self._serial)
|
self.fatfs = FatFS(self._serial)
|
||||||
self.reactor.pause(self.reactor.monotonic() + .5)
|
self.reactor.pause(self.reactor.monotonic() + .5)
|
||||||
printfunc("Initializing SD Card and Mounting file system...")
|
|
||||||
try:
|
try:
|
||||||
self.fatfs.mount(printfunc)
|
self.fatfs.mount(printfunc)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -1098,7 +1107,14 @@ class SPIFlash:
|
||||||
if not self.mcu_conn.connected:
|
if not self.mcu_conn.connected:
|
||||||
self.mcu_conn.connect()
|
self.mcu_conn.connect()
|
||||||
self.old_dictionary = self.mcu_conn.raw_dictionary
|
self.old_dictionary = self.mcu_conn.raw_dictionary
|
||||||
self.mcu_conn.configure_mcu(printfunc=output_line)
|
try:
|
||||||
|
self.mcu_conn.configure_mcu(printfunc=output_line)
|
||||||
|
except MCUConfigError:
|
||||||
|
output_line("MCU configuration failed, attempting restart")
|
||||||
|
self.need_upload = True
|
||||||
|
self.mcu_conn.reset()
|
||||||
|
self.task_complete = True
|
||||||
|
return
|
||||||
self.firmware_checksum = self.mcu_conn.sdcard_upload()
|
self.firmware_checksum = self.mcu_conn.sdcard_upload()
|
||||||
self.mcu_conn.reset()
|
self.mcu_conn.reset()
|
||||||
self.task_complete = True
|
self.task_complete = True
|
||||||
|
|
Loading…
Reference in New Issue