From eba9c37027c7a913beaf0835b2233078ca7e8011 Mon Sep 17 00:00:00 2001 From: jgroman Date: Fri, 2 Feb 2024 12:54:17 +0100 Subject: [PATCH] Fix SRAM loading on invalid flash --- src/gowin.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gowin.cpp b/src/gowin.cpp index 1f7cbc0..fef7724 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -883,8 +883,19 @@ void Gowin::sendClkUs(unsigned us) bool Gowin::eraseSRAM() { printInfo("Erase SRAM ", false); + uint32_t status = readStatusReg(); if (_verbose) - displayReadReg("before erase sram", readStatusReg()); + 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(); + send_command(0x3F); + send_command(NOOP); + } if (!enableCfg()) { printError("FAIL");