spiFlash: handle case where TB is not configurable

This commit is contained in:
Gwenhael Goavec-Merou 2022-03-29 07:49:08 +02:00
parent 9c51a0610f
commit f9eb32c778
1 changed files with 8 additions and 1 deletions

View File

@ -646,7 +646,7 @@ int SPIFlash::enable_protection(uint32_t length)
* check if tb is already set and if not warn * check if tb is already set and if not warn
* current (temporary) policy: do nothing * 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(); uint8_t tb = get_tb();
/* check if TB is set */ /* check if TB is set */
if (tb == 0) { if (tb == 0) {
@ -683,6 +683,10 @@ int SPIFlash::enable_protection(uint32_t length)
/* update status register */ /* update status register */
int ret = enable_protection(bp); int ret = enable_protection(bp);
/* No TB available -> nothing to do */
if (_flash_model->tb_register == NONER)
return ret;
/* tb is in different register */ /* tb is in different register */
if (_flash_model->tb_register != STATR) { if (_flash_model->tb_register != STATR) {
if (ret == -1) // check if enable_protection has failed if (ret == -1) // check if enable_protection has failed
@ -730,6 +734,9 @@ int8_t SPIFlash::get_tb()
case CONFR: // function register case CONFR: // function register
_spi->spi_put(FLASH_RDCR, NULL, &status, 1); _spi->spi_put(FLASH_RDCR, NULL, &status, 1);
break; break;
case NONER: // no TB bit
return 0;
break;
default: // unknown default: // unknown
printError("Unknown Top/Bottom register"); printError("Unknown Top/Bottom register");
return -1; return -1;