anlogic: fix high frequency flash programming issue

This commit is contained in:
zhangyh 2025-12-12 04:14:14 +00:00
parent c16e6d0f65
commit 4c17327a65
4 changed files with 25 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@ -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
*/