spiFlash: extract status register display from read_status_reg

This commit is contained in:
Gwenhael Goavec-Merou 2021-10-19 07:06:46 +02:00
parent 6714400909
commit 3730e8189d
7 changed files with 29 additions and 14 deletions

View File

@ -218,7 +218,7 @@ void Altera::program(unsigned int offset)
try {
epcq.reset();
epcq.read_id();
epcq.read_status_reg();
epcq.display_status_reg(epcq.read_status_reg());
epcq.erase_and_prog(offset, data, length);
} catch (std::exception &e) {
printError(e.what());

View File

@ -100,7 +100,7 @@ void Anlogic::program(unsigned int offset)
flash.reset();
flash.read_id();
flash.read_status_reg();
flash.display_status_reg(flash.read_status_reg());
flash.erase_and_prog(offset, data, len);

View File

@ -238,7 +238,7 @@ void Gowin::program(unsigned int offset)
SPIFlash spiFlash(this, (_verbose ? 1 : (_quiet ? -1 : 0)));
spiFlash.reset();
spiFlash.read_id();
spiFlash.read_status_reg();
spiFlash.display_status_reg(spiFlash.read_status_reg());
if (spiFlash.erase_and_prog(offset, data, length / 8) != 0)
throw std::runtime_error("Error: write to flash failed");
if (_verify)

View File

@ -444,7 +444,7 @@ bool Lattice::program_extFlash(unsigned int offset)
SPIFlash flash(this, _verbose);
flash.reset();
flash.read_id();
flash.read_status_reg();
flash.display_status_reg(flash.read_status_reg());
flash.erase_and_prog(offset, data, length);
int ret = true;

View File

@ -321,18 +321,31 @@ void SPIFlash::read_id()
}
}
void SPIFlash::display_status_reg(uint8_t reg)
{
uint8_t tb, bp;
if (!_flash_model) {
tb = (reg >> 5) & 0x01;
bp = (((reg >> 6) & 0x01) << 3) | ((reg >> 2) & 0x07);
} else {
tb = (reg & _flash_model->tb_offset) ? 1 : 0;
bp = 0;
for (int i = 0; i < _flash_model->bp_len; i++)
if (reg & _flash_model->bp_offset[i])
bp |= 1 << i;
}
printf("RDSR : %02x\n", reg);
printf("WIP : %d\n", reg&0x01);
printf("WEL : %d\n", (reg>>1)&0x01);
printf("BP : %x\n", bp);
printf("TB : %d\n", tb);
printf("SRWD : %d\n", (((reg>>7)&0x01)));
}
uint8_t SPIFlash::read_status_reg()
{
uint8_t rx;
_spi->spi_put(FLASH_RDSR, NULL, &rx, 1);
if (_verbose > 0) {
printf("RDSR : %02x\n", rx);
printf("WIP : %d\n", rx&0x01);
printf("WEL : %d\n", (rx>>1)&0x01);
printf("BP : %x\n", (((rx>>6)&0x01)<<3) | ((rx >> 2) & 0x07));
printf("TB : %d\n", (((rx>>5)&0x01)));
printf("SRWD : %d\n", (((rx>>7)&0x01)));
}
return rx;
}

View File

@ -70,8 +70,10 @@ class SPIFlash {
*/
bool verify(const int &base_addr, const uint8_t *data,
const int &len, int rd_burst = 0);
/* display/info */
/* return status register value */
uint8_t read_status_reg();
/* display/info */
void display_status_reg(uint8_t reg);
virtual void read_id();
uint16_t readNonVolatileCfgReg();
uint16_t readVolatileCfgReg();

View File

@ -276,7 +276,7 @@ void Xilinx::program_spi(ConfigBitstreamParser * bit, unsigned int offset)
SPIFlash spiFlash(this, (_verbose ? 1 : (_quiet ? -1 : 0)));
spiFlash.reset();
spiFlash.read_id();
spiFlash.read_status_reg();
spiFlash.display_status_reg(spiFlash.read_status_reg());
spiFlash.erase_and_prog(offset, data, length);
/* verify write if required */