spiInterface: add read method

This commit is contained in:
Gwenhael Goavec-Merou 2023-03-05 10:13:08 +01:00
parent a5489e62f8
commit 3babd5d07d
2 changed files with 32 additions and 1 deletions

View File

@ -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;

View File

@ -7,6 +7,7 @@
#define SRC_SPIINTERFACE_HPP_
#include <iostream>
#include <string>
#include <vector>
/*!
@ -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_