Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/anlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/anlogic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
1 change: 1 addition & 0 deletions src/spiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/spiInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down