From 5f0dbfc42c990412293d0f6fcfa8bcb74648e919 Mon Sep 17 00:00:00 2001 From: Patrick Urban Date: Wed, 3 Sep 2025 14:59:06 +0200 Subject: [PATCH] colognechip: add bulk erase + quad enable features and simplify spi_wait overload --- src/colognechip.cpp | 52 +++++++++++++++++++++++++++++++++++++-------- src/colognechip.hpp | 4 ++-- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/colognechip.cpp b/src/colognechip.cpp index 7d928f1..6e8c3a1 100644 --- a/src/colognechip.cpp +++ b/src/colognechip.cpp @@ -213,6 +213,45 @@ 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) +{ + /* prepare SPI access */ + prepare_flash_access(); + + printInfo("Update Quad Enable Bit ", false); + try { + std::unique_ptr flash(_spi ? + new SPIFlash(reinterpret_cast(_spi), false, _verbose): + new SPIFlash(this, false, _verbose)); + flash->set_quad_bit(set_quad); + } catch (std::exception &e) { + printError("Fail"); + printError(std::string(e.what())); + return false; + } + + return post_flash_access(); +} + +/** + * Peform bulk erase. Works in both SPI and JTAG-SPI-bypass mode. + */ +bool CologneChip::bulk_erase_flash() +{ + /* prepare SPI access */ + prepare_flash_access(); + + printInfo("Bulk Erase ", false); + if (!SPIInterface::bulk_erase_flash()) { + return false; + } + + return post_flash_access(); +} + /** * 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 +489,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;}