[Cryptech-Commits] [sw/stm32] branch ksng updated: Wait for WIP to clear before returning from erase operations too.
git at cryptech.is
git at cryptech.is
Wed Nov 2 23:24:37 UTC 2016
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch ksng
in repository sw/stm32.
The following commit(s) were added to refs/heads/ksng by this push:
new 66348b6 Wait for WIP to clear before returning from erase operations too.
66348b6 is described below
commit 66348b6986cf38d9d0fe707eca7bbfd7be3def18
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Wed Nov 2 19:02:58 2016 -0400
Wait for WIP to clear before returning from erase operations too.
Wrong-block-type race condition errors went away after adding the WIP
check after flash write operations, then came back once (isolated
incident) while running a series of tests which had written enough
flash blocks that ks_flash may have finally had to erase something
rather than just zeroing.
Code inspection confirmed that the erase code was not waiting for WIP
to clear before exiting. Difficult to prove that this was the cause
of an unreproducible failure, but seems like a likely candidate given
previous behavior and change should be harmless, so adding it.
Timeout for this flag check is 2000 ms, which is what other
erase-related WIP flag checks were already using.
---
spiflash_n25q128.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/spiflash_n25q128.c b/spiflash_n25q128.c
index 0c2abd7..c23f244 100644
--- a/spiflash_n25q128.c
+++ b/spiflash_n25q128.c
@@ -216,6 +216,18 @@ int n25q128_get_wip_flag(struct spiflash_ctx *ctx)
return (spi_rx[1] & 1);
}
+/* Wait until the flash memory is done writing (wip = Write In Progress) */
+inline int _wait_while_wip(struct spiflash_ctx *ctx, uint32_t timeout)
+{
+ int i;
+ while (timeout--) {
+ i = n25q128_get_wip_flag(ctx);
+ if (i < 0) return 0;
+ if (! i) break;
+ HAL_Delay(10);
+ }
+ return 1;
+}
static int n25q128_erase_something(struct spiflash_ctx *ctx, uint8_t command, uint32_t byte_offset)
{
@@ -259,6 +271,10 @@ static int n25q128_erase_something(struct spiflash_ctx *ctx, uint8_t command, ui
// check
if (ok != HAL_OK) return 0;
+ // wait for erase to finish
+
+ if (! _wait_while_wip(ctx, 2000)) return 0;
+
// done
return 1;
}
@@ -303,19 +319,6 @@ int _n25q128_get_wel_flag(struct spiflash_ctx *ctx)
return ((spi_rx[1] >> 1) & 1);
}
-/* Wait until the flash memory is done writing (wip = Write In Progress) */
-inline int _wait_while_wip(struct spiflash_ctx *ctx, uint32_t timeout)
-{
- int i;
- while (timeout--) {
- i = n25q128_get_wip_flag(ctx);
- if (i < 0) return 0;
- if (! i) break;
- HAL_Delay(10);
- }
- return 1;
-}
-
/* This function performs erasure if needed, and then writing of a number of pages to the flash memory */
int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t *buf, const uint32_t len, const int auto_erase)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Commits
mailing list