From f9eb32c7785055f2edd75a9795c7407199fece21 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 29 Mar 2022 07:49:08 +0200 Subject: [PATCH] spiFlash: handle case where TB is not configurable --- src/spiFlash.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spiFlash.cpp b/src/spiFlash.cpp index 93a6893..2c43fac 100644 --- a/src/spiFlash.cpp +++ b/src/spiFlash.cpp @@ -646,7 +646,7 @@ int SPIFlash::enable_protection(uint32_t length) * check if tb is already set and if not warn * current (temporary) policy: do nothing */ - if (_flash_model->tb_otp) { + if (_flash_model->tb_otp && _flash_model->tb_register != NONER) { uint8_t tb = get_tb(); /* check if TB is set */ if (tb == 0) { @@ -683,6 +683,10 @@ int SPIFlash::enable_protection(uint32_t length) /* update status register */ int ret = enable_protection(bp); + /* No TB available -> nothing to do */ + if (_flash_model->tb_register == NONER) + return ret; + /* tb is in different register */ if (_flash_model->tb_register != STATR) { if (ret == -1) // check if enable_protection has failed @@ -730,6 +734,9 @@ int8_t SPIFlash::get_tb() case CONFR: // function register _spi->spi_put(FLASH_RDCR, NULL, &status, 1); break; + case NONER: // no TB bit + return 0; + break; default: // unknown printError("Unknown Top/Bottom register"); return -1;