From 9a58588772523ec68df51443500888e5f707ad5d Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Sat, 18 Aug 2018 16:13:27 -0700 Subject: 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. --- iceprog/iceprog.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'iceprog') 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(); } } -- cgit v1.2.3