diff options
author | Justin Schuh <jschuh@users.noreply.github.com> | 2021-11-09 09:14:19 -0800 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2021-11-09 20:15:46 -0500 |
commit | cfff8974800a08a138219b195886b47d140db5ff (patch) | |
tree | 0347e9fc5de6cc4e84d3cda033aa2e98021f9e9b /scripts | |
parent | a0615e5e17d701ada93acd59031193a1b231dd7c (diff) | |
download | kutter-cfff8974800a08a138219b195886b47d140db5ff.tar.gz kutter-cfff8974800a08a138219b195886b47d140db5ff.tar.xz kutter-cfff8974800a08a138219b195886b47d140db5ff.zip |
spi_flash: Better fallback on MCU protocol change
Support a set of known past config responses.
Signed-off-by: Justin Schuh <code@justinschuh.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/spi_flash/spi_flash.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/scripts/spi_flash/spi_flash.py b/scripts/spi_flash/spi_flash.py index 0c893ed2..99cd4bae 100644 --- a/scripts/spi_flash/spi_flash.py +++ b/scripts/spi_flash/spi_flash.py @@ -99,7 +99,10 @@ SD_SPI_SPEED = 4000000 # MCU Command Constants RESET_CMD = "reset" GET_CFG_CMD = "get_config" -GET_CFG_RESPONSE = "config is_config=%c crc=%u is_shutdown=%c move_count=%hu" +GET_CFG_RESPONSES = ( # Supported responses (sorted by newer revisions first). + "config is_config=%c crc=%u is_shutdown=%c move_count=%hu", # d4aee4f + "config is_config=%c crc=%u move_count=%hu is_shutdown=%c" # Original +) ALLOC_OIDS_CMD = "allocate_oids count=%d" SPI_CFG_CMD = "config_spi oid=%d pin=%s" SPI_BUS_CMD = "spi_set_bus oid=%d spi_bus=%s mode=%d rate=%d" @@ -856,8 +859,17 @@ class MCUConnection: def check_need_restart(self): output("Checking Current MCU Configuration...") - get_cfg_cmd = mcu.CommandQueryWrapper( - self._serial, GET_CFG_CMD, GET_CFG_RESPONSE) + # Iterate through backwards compatible response strings + for response in GET_CFG_RESPONSES: + try: + get_cfg_cmd = mcu.CommandQueryWrapper( + self._serial, GET_CFG_CMD, response) + break + except Exception as err: + # Raise an exception if we hit the end of the list. + if response == GET_CFG_RESPONSES[-1]: + raise err + output("Trying fallback...") params = get_cfg_cmd.send() output_line("Done") if params['is_config'] or params['is_shutdown']: |