spi_flash: Better fallback on MCU protocol change

Support a set of known past config responses.

Signed-off-by: Justin Schuh <code@justinschuh.com>
This commit is contained in:
Justin Schuh 2021-11-09 09:14:19 -08:00 committed by KevinOConnor
parent a0615e5e17
commit cfff897480
1 changed files with 15 additions and 3 deletions

View File

@ -99,7 +99,10 @@ SD_SPI_SPEED = 4000000
# MCU Command Constants # MCU Command Constants
RESET_CMD = "reset" RESET_CMD = "reset"
GET_CFG_CMD = "get_config" 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" ALLOC_OIDS_CMD = "allocate_oids count=%d"
SPI_CFG_CMD = "config_spi oid=%d pin=%s" SPI_CFG_CMD = "config_spi oid=%d pin=%s"
SPI_BUS_CMD = "spi_set_bus oid=%d spi_bus=%s mode=%d rate=%d" 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): def check_need_restart(self):
output("Checking Current MCU Configuration...") output("Checking Current MCU Configuration...")
# Iterate through backwards compatible response strings
for response in GET_CFG_RESPONSES:
try:
get_cfg_cmd = mcu.CommandQueryWrapper( get_cfg_cmd = mcu.CommandQueryWrapper(
self._serial, GET_CFG_CMD, GET_CFG_RESPONSE) 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() params = get_cfg_cmd.send()
output_line("Done") output_line("Done")
if params['is_config'] or params['is_shutdown']: if params['is_config'] or params['is_shutdown']: