From cfddee36110c321c55c52903df93f6ccd43d968d Mon Sep 17 00:00:00 2001 From: Patrick Urban Date: Wed, 3 Sep 2025 16:26:16 +0200 Subject: [PATCH] colognechip: add bulk erase + quad enable features and simplify spi_wait overload (#582) * colognechip: add bulk erase + quad enable features and simplify spi_wait overload * colognechip: remove unnecessary code in `set_quad_bit` and `bulk_erase_flash` --- src/colognechip.cpp | 37 ++++++++++++++++++++++++++++--------- src/colognechip.hpp | 4 ++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/colognechip.cpp b/src/colognechip.cpp index 7d928f1..4b6167e 100644 --- a/src/colognechip.cpp +++ b/src/colognechip.cpp @@ -213,6 +213,30 @@ bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len) return post_flash_access(); } +/** + * Set QE bit, if available. Works in both SPI and JTAG-SPI-bypass mode. + */ +bool CologneChip::set_quad_bit(bool set_quad) +{ + if (!SPIInterface::set_quad_bit(set_quad)) { + return false; + } + + return true; +} + +/** + * Peform bulk erase. Works in both SPI and JTAG-SPI-bypass mode. + */ +bool CologneChip::bulk_erase_flash() +{ + if (!SPIInterface::bulk_erase_flash()) { + return false; + } + + return true; +} + /** * Parse bitstream from *.bit or *.cfg and program FPGA in SPI or JTAG mode * or write configuration to external flash via SPI or JTAG-SPI-bypass. @@ -450,15 +474,10 @@ int CologneChip::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, _jtag->read_write(&tx, NULL, 8, 0); do { - if (count == 0) { - _jtag->read_write(dummy, rx, 16, 0); - uint8_t b0 = ConfigBitstreamParser::reverseByte(rx[0]); - uint8_t b1 = ConfigBitstreamParser::reverseByte(rx[1]); - tmp = (b0 << 1) | ((b1 >> 7) & 0x01); - } else { - _jtag->read_write(dummy, rx, 8, 0); - tmp = ConfigBitstreamParser::reverseByte(rx[0]); - } + _jtag->read_write(dummy, rx, 16, 0); + uint8_t b0 = ConfigBitstreamParser::reverseByte(rx[0]); + uint8_t b1 = ConfigBitstreamParser::reverseByte(rx[1]); + tmp = (b0 << 1) | ((b1 >> 7) & 0x01); count++; if (count == timeout) { diff --git a/src/colognechip.hpp b/src/colognechip.hpp index fa5fca1..29ec58b 100644 --- a/src/colognechip.hpp +++ b/src/colognechip.hpp @@ -42,8 +42,8 @@ class CologneChip: public Device, SPIInterface { printError("protect flash not supported"); return false;} virtual bool unprotect_flash() override { printError("unprotect flash not supported"); return false;} - virtual bool bulk_erase_flash() override { - printError("bulk erase flash not supported"); return false;} + bool set_quad_bit(bool set_quad) override; + bool bulk_erase_flash() override; void program(unsigned int offset, bool unprotect_flash) override; uint32_t idCode() override {return 0;}