From 0409263f87897382aa4dfce1baac1b30c32c4270 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 21 Apr 2020 19:25:35 +0200 Subject: [PATCH] unlock block if locked before erase/flash --- src/spiFlash.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/spiFlash.cpp b/src/spiFlash.cpp index 9a1a30d..2c676e5 100644 --- a/src/spiFlash.cpp +++ b/src/spiFlash.cpp @@ -131,6 +131,14 @@ int SPIFlash::write_page(int addr, uint8_t *data, int len) int SPIFlash::erase_and_prog(int base_addr, uint8_t *data, int len) { + /* check Block Protect Bits */ + uint8_t status = read_status_reg(); + if ((status & 0x1c) !=0) { + if (write_enable() != 0) + return -1; + if (disable_protection() != 0) + return -1; + } ProgressBar progress("Writing", len, 50); if (sectors_erase(0, len) == -1) return -1;