From 3babd5d07dbbd012344d88a7550c95eed7afb2ad Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sun, 5 Mar 2023 10:13:08 +0100 Subject: [PATCH] spiInterface: add read method --- src/spiInterface.cpp | 19 +++++++++++++++++++ src/spiInterface.hpp | 14 +++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/spiInterface.cpp b/src/spiInterface.cpp index 7abe1b8..3d60db5 100644 --- a/src/spiInterface.cpp +++ b/src/spiInterface.cpp @@ -140,6 +140,25 @@ bool SPIInterface::write(uint32_t offset, uint8_t *data, uint32_t len, return ret && ret2; } +bool SPIInterface::read(uint8_t *data, uint32_t base_addr, uint32_t len) +{ + bool ret = true; + /* enable SPI flash access */ + if (!prepare_flash_access()) + return false; + + try { + SPIFlash flash(this, false, _spif_verbose); + ret = flash.read(base_addr, data, len); + } catch (std::exception &e) { + printError(e.what()); + ret = false; + } + + /* reload bitstream */ + return post_flash_access() && ret == 0; +} + bool SPIInterface::dump(uint32_t base_addr, uint32_t len) { bool ret = true; diff --git a/src/spiInterface.hpp b/src/spiInterface.hpp index a1c3995..63b9ed5 100644 --- a/src/spiInterface.hpp +++ b/src/spiInterface.hpp @@ -7,6 +7,7 @@ #define SRC_SPIINTERFACE_HPP_ #include +#include #include /*! @@ -44,6 +45,17 @@ class SPIInterface { */ bool write(uint32_t offset, uint8_t *data, uint32_t len, bool unprotect_flash); + + /*! + * \brief read flash offset byte starting at base_addr and + * store into data buffer + * \param[in] data: buffer where to store + * \param[in] base_addr: offset into flash + * \param[in] len: byte len to read + * \return false when something fails + */ + bool read(uint8_t *data, uint32_t base_addr, uint32_t len); + /*! * \brief read flash offset byte starting at base_addr and * store into filename @@ -103,8 +115,8 @@ class SPIInterface { bool _spif_verify; bool _skip_load_bridge; bool _skip_reset; /*!< don't reset the device after write */ + private: std::string _spif_filename; - }; #endif // SRC_SPIINTERFACE_HPP_