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']: