aboutsummaryrefslogtreecommitdiffstats
path: root/iceprog
diff options
context:
space:
mode:
authorPiotr Esden-Tempski <piotr@esden.net>2018-08-18 16:13:27 -0700
committerPiotr Esden-Tempski <piotr@esden.net>2018-08-18 16:13:27 -0700
commit9a58588772523ec68df51443500888e5f707ad5d (patch)
tree6529287783ac8d09c7a0e9cb504f2f77af4acb1f /iceprog
parent868ac2d93f124fe54034f26f1bc43f7b53676028 (diff)
downloadicestorm-9a58588772523ec68df51443500888e5f707ad5d.tar.gz
icestorm-9a58588772523ec68df51443500888e5f707ad5d.tar.bz2
icestorm-9a58588772523ec68df51443500888e5f707ad5d.zip
Slightly more robust flash wait function.
In cases when the FLASH chip is bit flaky and the status register "bounces" this flash_wait should be able to perform a bit better. Also added more verbose output around block erase.
Diffstat (limited to 'iceprog')
-rw-r--r--iceprog/iceprog.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index a004e28..ad2bb6a 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -527,26 +527,43 @@ static void flash_wait()
if (verbose)
fprintf(stderr, "waiting..");
+ int count = 0;
while (1)
{
uint8_t data[2] = { FC_RSR1 };
- set_gpio(0, 0);
+ flash_chip_select(true);
xfer_spi(data, 2);
- set_gpio(1, 0);
-
- if ((data[1] & 0x01) == 0)
- break;
+ flash_chip_select(false);
- if (verbose) {
- fprintf(stderr, ".");
- fflush(stdout);
+ if ((data[1] & 0x01) == 0) {
+ if(count < 2) {
+ count++;
+ if (verbose) {
+ fprintf(stderr, "r");
+ fflush(stderr);
+ }
+ } else {
+ if (verbose) {
+ fprintf(stderr, "R");
+ fflush(stderr);
+ }
+ break;
+ }
+ } else {
+ if (verbose) {
+ fprintf(stderr, ".");
+ fflush(stderr);
+ }
+ count = 0;
}
+
usleep(1000);
}
if (verbose)
fprintf(stderr, "\n");
+
}
static void flash_disable_protection()
@@ -973,7 +990,6 @@ int main(int argc, char **argv)
flash_release_reset();
usleep(100000);
-
if (test_mode)
{
fprintf(stderr, "reset..\n");
@@ -1085,6 +1101,10 @@ int main(int argc, char **argv)
for (int addr = begin_addr; addr < end_addr; addr += 0x10000) {
flash_write_enable();
flash_64kB_sector_erase(addr);
+ if (verbose) {
+ fprintf(stderr, "Status after block erase:\n");
+ flash_read_status();
+ }
flash_wait();
}
}