Skip to content

Commit 7ed4954

Browse files
authored
Merge pull request #599 from zh522130/fix-analogic-high-freq-flash
anlogic: fix high frequency flash programming issue
2 parents fe115e1 + 4c17327 commit 7ed4954

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/anlogic.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Anlogic::Anlogic(Jtag *jtag, const std::string &filename,
2929
const std::string &file_type,
3030
Device::prog_type_t prg_type, bool verify, int8_t verbose):
3131
Device(jtag, filename, file_type, verify, verbose),
32-
SPIInterface(filename, verbose, 0, verify)
32+
SPIInterface(filename, verbose, 0, verify), _target_freq(0)
3333
{
3434
if (prg_type == Device::RD_FLASH) {
3535
_mode = Device::READ_MODE;
@@ -157,6 +157,11 @@ uint32_t Anlogic::idCode()
157157

158158
bool Anlogic::prepare_flash_access()
159159
{
160+
_target_freq = _jtag->getClkFreq();
161+
if (_target_freq > 6000000) {
162+
_jtag->setClkFreq(6000000);
163+
}
164+
160165
for (int i = 0; i < 5; i++)
161166
_jtag->shiftIR(BYPASS, IRLENGTH);
162167
//Verify Device id.
@@ -174,6 +179,13 @@ bool Anlogic::prepare_flash_access()
174179
return true;
175180
}
176181

182+
void Anlogic::restore_flash_access_frequency()
183+
{
184+
if (_target_freq > 6000000) {
185+
_jtag->setClkFreq(_target_freq);
186+
}
187+
}
188+
177189
/* SPI wrapper
178190
* For read operation a delay of one bit is added
179191
* So add one bit more and move everything by one

src/anlogic.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,18 @@ class Anlogic: public Device, SPIInterface {
6868
* \brief move device to SPI access
6969
*/
7070
virtual bool prepare_flash_access() override;
71+
/*!
72+
* \brief restore frequency after flash ID read
73+
*/
74+
virtual void restore_flash_access_frequency() override;
7175
/*!
7276
* \brief end of device to SPI access
7377
*/
7478
virtual bool post_flash_access() override {reset(); return true;}
7579

80+
private:
81+
uint32_t _target_freq; /*< target JTAG frequency */
82+
7683
};
7784

7885
#endif // SRC_ANLOGIC_HPP_

src/spiInterface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ bool SPIInterface::write(uint32_t offset, const uint8_t *data, uint32_t len,
187187
/* test SPI */
188188
try {
189189
SPIFlash flash(this, unprotect_flash, _spif_verbose);
190+
restore_flash_access_frequency();
190191
flash.read_status_reg();
191192
if (flash.erase_and_prog(offset, data, len) == -1)
192193
ret = false;

src/spiInterface.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class SPIInterface {
108108
* \brief prepare SPI flash access
109109
*/
110110
virtual bool prepare_flash_access() {return false;}
111+
/*!
112+
* \brief restore frequency after flash ID read
113+
*/
114+
virtual void restore_flash_access_frequency() {}
111115
/*!
112116
* \brief end of SPI flash access
113117
*/

0 commit comments

Comments
 (0)