spiFlash: verbose mode

This commit is contained in:
Gwenhael Goavec-Merou 2019-11-21 09:19:48 +01:00
parent 9cfe301b41
commit af0fb60101
2 changed files with 21 additions and 14 deletions

View File

@ -72,7 +72,9 @@ static uint8_t reverseByte(uint8_t src)
#define FLASH_WRVECR 0x61 #define FLASH_WRVECR 0x61
#define FLASH_RDVECR 0x65 #define FLASH_RDVECR 0x65
SPIFlash::SPIFlash(FtdiJtag *jtag):_jtag(jtag) {} SPIFlash::SPIFlash(FtdiJtag *jtag, bool verbose):_jtag(jtag), _verbose(verbose)
{
}
/* /*
* jtag : jtag interface * jtag : jtag interface
@ -229,10 +231,12 @@ void SPIFlash::read_id()
for (int i=0; i < 4; i++) { for (int i=0; i < 4; i++) {
d = d << 8; d = d << 8;
d |= (0x00ff & (int)rx[i]); d |= (0x00ff & (int)rx[i]);
printf("%x ", rx[i]); if (_verbose)
printf("%x ", rx[i]);
} }
printf("read %x\n", d); if (_verbose)
printf("read %x\n", d);
/* read extented */ /* read extented */
len += (d & 0x0ff); len += (d & 0x0ff);
@ -247,16 +251,18 @@ void SPIFlash::read_id()
printf("EDID + CFD length : %02x\n", rx[3]); printf("EDID + CFD length : %02x\n", rx[3]);
printf("EDID : %02x%02x\n", rx[5], rx[4]); printf("EDID : %02x%02x\n", rx[5], rx[4]);
printf("CFD : "); printf("CFD : ");
for (int i = 6; i < len; i++) if (_verbose) {
printf("%02x ", rx[i]); for (int i = 6; i < len; i++)
printf("\n"); printf("%02x ", rx[i]);
printf("\n");
}
} }
uint8_t SPIFlash::read_status_reg(bool display) uint8_t SPIFlash::read_status_reg()
{ {
uint8_t rx; uint8_t rx;
jtag_write_read(FLASH_RDSR, NULL, &rx, 1); jtag_write_read(FLASH_RDSR, NULL, &rx, 1);
if (display) { if (_verbose) {
printf("RDSR : %02x\n", rx); printf("RDSR : %02x\n", rx);
printf("WIP : %d\n", rx&0x01); printf("WIP : %d\n", rx&0x01);
printf("WEL : %d\n", (rx>>1)&0x01); printf("WEL : %d\n", (rx>>1)&0x01);
@ -277,7 +283,7 @@ void SPIFlash::power_down()
jtag_write_read(FLASH_POWER_DOWN, NULL, NULL, 0); jtag_write_read(FLASH_POWER_DOWN, NULL, NULL, 0);
} }
int SPIFlash::write_enable(bool verbose) int SPIFlash::write_enable()
{ {
jtag_write_read(FLASH_WREN, NULL, NULL, 0); jtag_write_read(FLASH_WREN, NULL, NULL, 0);
/* wait WEL */ /* wait WEL */
@ -286,7 +292,7 @@ int SPIFlash::write_enable(bool verbose)
return -1; return -1;
} }
if (verbose) if (_verbose)
std::cout << "write en: Success" << std::endl; std::cout << "write en: Success" << std::endl;
return 0; return 0;
} }
@ -298,7 +304,7 @@ int SPIFlash::write_disable()
int ret = wait(FLASH_RDSR_WEL, 0x00, 1000); int ret = wait(FLASH_RDSR_WEL, 0x00, 1000);
if (ret == -1) if (ret == -1)
printf("write disable: Error\n"); printf("write disable: Error\n");
else else if (_verbose)
printf("write disable: Success\n"); printf("write disable: Success\n");
return ret; return ret;
} }

View File

@ -22,13 +22,13 @@
class SPIFlash { class SPIFlash {
public: public:
SPIFlash(FtdiJtag *jtag); SPIFlash(FtdiJtag *jtag, bool verbose);
/* power */ /* power */
void power_up(); void power_up();
void power_down(); void power_down();
void reset(); void reset();
/* protection */ /* protection */
int write_enable(bool verbose=false); int write_enable();
int write_disable(); int write_disable();
int disable_protection(); int disable_protection();
/* erase */ /* erase */
@ -40,13 +40,14 @@ class SPIFlash {
/* combo flash + erase */ /* combo flash + erase */
int erase_and_prog(int base_addr, uint8_t *data, int len); int erase_and_prog(int base_addr, uint8_t *data, int len);
/* display/info */ /* display/info */
uint8_t read_status_reg(bool display=false); uint8_t read_status_reg();
void read_id(); void read_id();
private: private:
void jtag_write_read(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint16_t len = 0); void jtag_write_read(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint16_t len = 0);
int wait(uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose=false); int wait(uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose=false);
FtdiJtag *_jtag; FtdiJtag *_jtag;
bool _verbose;
}; };
#endif #endif