diff --git a/src/anlogic.cpp b/src/anlogic.cpp index 45e233f..8321ed6 100644 --- a/src/anlogic.cpp +++ b/src/anlogic.cpp @@ -29,7 +29,7 @@ Anlogic::Anlogic(Jtag *jtag, const std::string &filename, const std::string &file_type, Device::prog_type_t prg_type, bool verify, int8_t verbose): Device(jtag, filename, file_type, verify, verbose), - SPIInterface(filename, verbose, 0, verify) + SPIInterface(filename, verbose, 0, verify), _target_freq(0) { if (prg_type == Device::RD_FLASH) { _mode = Device::READ_MODE; @@ -157,6 +157,11 @@ uint32_t Anlogic::idCode() bool Anlogic::prepare_flash_access() { + _target_freq = _jtag->getClkFreq(); + if (_target_freq > 6000000) { + _jtag->setClkFreq(6000000); + } + for (int i = 0; i < 5; i++) _jtag->shiftIR(BYPASS, IRLENGTH); //Verify Device id. @@ -174,6 +179,13 @@ bool Anlogic::prepare_flash_access() return true; } +void Anlogic::restore_flash_access_frequency() +{ + if (_target_freq > 6000000) { + _jtag->setClkFreq(_target_freq); + } +} + /* SPI wrapper * For read operation a delay of one bit is added * So add one bit more and move everything by one diff --git a/src/anlogic.hpp b/src/anlogic.hpp index 366812d..7e95b2c 100644 --- a/src/anlogic.hpp +++ b/src/anlogic.hpp @@ -68,11 +68,18 @@ class Anlogic: public Device, SPIInterface { * \brief move device to SPI access */ virtual bool prepare_flash_access() override; + /*! + * \brief restore frequency after flash ID read + */ + virtual void restore_flash_access_frequency() override; /*! * \brief end of device to SPI access */ virtual bool post_flash_access() override {reset(); return true;} +private: + uint32_t _target_freq; /*< target JTAG frequency */ + }; #endif // SRC_ANLOGIC_HPP_ diff --git a/src/spiInterface.cpp b/src/spiInterface.cpp index 990f5ad..fb357ba 100644 --- a/src/spiInterface.cpp +++ b/src/spiInterface.cpp @@ -187,6 +187,7 @@ bool SPIInterface::write(uint32_t offset, const uint8_t *data, uint32_t len, /* test SPI */ try { SPIFlash flash(this, unprotect_flash, _spif_verbose); + restore_flash_access_frequency(); flash.read_status_reg(); if (flash.erase_and_prog(offset, data, len) == -1) ret = false; diff --git a/src/spiInterface.hpp b/src/spiInterface.hpp index c502d99..c9d2eae 100644 --- a/src/spiInterface.hpp +++ b/src/spiInterface.hpp @@ -108,6 +108,10 @@ class SPIInterface { * \brief prepare SPI flash access */ virtual bool prepare_flash_access() {return false;} + /*! + * \brief restore frequency after flash ID read + */ + virtual void restore_flash_access_frequency() {} /*! * \brief end of SPI flash access */