diff --git a/src/ice40.cpp b/src/ice40.cpp index f748132..ea0bffd 100644 --- a/src/ice40.cpp +++ b/src/ice40.cpp @@ -148,6 +148,25 @@ void Ice40::program(unsigned int offset, bool unprotect_flash) post_flash_access(); } +bool Ice40::detect_flash() +{ + /* prepare SPI access */ + prepare_flash_access(); + printInfo("Read Flash ", false); + try { + SPIFlash flash(reinterpret_cast(_spi), false, _verbose_level); + flash.read_id(); + flash.display_status_reg(); + } catch (std::exception &e) { + printError("Fail"); + printError(std::string(e.what())); + return false; + } + + /* release SPI access / reload */ + return post_flash_access(); +} + bool Ice40::dumpFlash(uint32_t base_addr, uint32_t len) { /* prepare SPI access */ diff --git a/src/ice40.hpp b/src/ice40.hpp index 08157ca..e4ab48f 100644 --- a/src/ice40.hpp +++ b/src/ice40.hpp @@ -24,9 +24,7 @@ class Ice40: public Device, SPIInterface { void program(unsigned int offset, bool unprotect_flash) override; bool program_cram(const uint8_t *data, uint32_t length); bool dumpFlash(uint32_t base_addr, uint32_t len) override; - bool detect_flash() override { - return SPIInterface::detect_flash(); - } + bool detect_flash() override; bool protect_flash(uint32_t len) override; bool unprotect_flash() override; bool bulk_erase_flash() override;