From ab8d8fc0d34374d551774eee0d455fe014d259dd Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Thu, 6 Mar 2025 20:05:31 +0100 Subject: [PATCH] gowin: Arora V: fix SRAM erase/load when flash is blank and timeout bit is set --- src/gowin.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/gowin.cpp b/src/gowin.cpp index cc79703..d819a88 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -394,13 +394,6 @@ void Gowin::programSRAM() if (!eraseSRAM()) return; - /* GW5AST-138k WA. Temporary until found correct solution/sequence */ - if (is_gw5a && _idcode == 0x0001081b) { - printf("double eraseSRAM\n"); - if (!eraseSRAM()) - return; - } - /* load bitstream in SRAM */ if (!writeSRAM(_fs->getData(), _fs->getLength())) return; @@ -912,13 +905,18 @@ bool Gowin::eraseSRAM() displayReadReg("before erase sram", status); // If flash is invalid, send extra cmd 0x3F before SRAM erase - // This is required on GW5A-25 - bool auto_boot_2nd_fail = (status & 0x8) >> 3; - if ((_idcode == 0x0001281B) && auto_boot_2nd_fail) - { - disableCfg(); + // This is required on GW5A-25 or GW5AST-138 when timeout bit + // is set + bool auto_boot_2nd_fail = (status & (1 << 4)) == (1 << 4); + bool is_timeout = (status & (1 << 3)) == (1 << 3); + if (is_gw5a && (is_timeout || auto_boot_2nd_fail)) { + send_command(CONFIG_ENABLE); send_command(0x3F); + send_command(CONFIG_DISABLE); send_command(NOOP); + send_command(READ_IDCODE); + send_command(NOOP); + _jtag->toggleClk(125 * 8); } if (!enableCfg()) {