aboutsummaryrefslogtreecommitdiff
path: root/stm-fpgacfg.c
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2016-05-21 14:40:32 +0200
committerFredrik Thulin <fredrik@thulin.net>2016-05-21 14:40:32 +0200
commitfd60daaeb372759f2990f059ce027616439fac28 (patch)
tree466dcfaeca1ce858203399ed390c118fb5829ff5 /stm-fpgacfg.c
parentac2357b001b970ff281d05566697c3d73f66ea4a (diff)
Bugfix erasing sector 0.
Diffstat (limited to 'stm-fpgacfg.c')
-rw-r--r--stm-fpgacfg.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/stm-fpgacfg.c b/stm-fpgacfg.c
index 9e2a307..6f6114d 100644
--- a/stm-fpgacfg.c
+++ b/stm-fpgacfg.c
@@ -94,19 +94,21 @@ int fpgacfg_check_done(void)
int fpgacfg_erase_sectors(int num)
{
- if (num > N25Q128_NUM_SECTORS - 1 || num < 0) num = N25Q128_NUM_SECTORS - 1;
+ if (num > N25Q128_NUM_SECTORS || num < 0) num = N25Q128_NUM_SECTORS;
while (num) {
- int timeout = 1000;
+ int timeout = 200; /* times 10ms = 2 seconds timeout */
while (timeout--) {
int i = n25q128_get_wip_flag(&fpgacfg_ctx);
if (i < 0) return 0;
if (! i) break;
HAL_Delay(10);
}
+ if (! timeout) return 0;
- if (! n25q128_erase_sector(&fpgacfg_ctx, num--)) {
- return 0;
+ if (! n25q128_erase_sector(&fpgacfg_ctx, num - 1)) {
+ return -1;
}
+ num--;
}
return 1;
}