diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2017-12-07 12:45:17 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-08 20:37:25 -0800 |
commit | 316a8cb3988f192242023b01625d467aea6d1b19 (patch) | |
tree | a61e8d6ede8629d9e57b22c0ed5c7be26ebcceaa | |
parent | 9e73e2235eb0b510d2a1a1cf53895cdf52cce447 (diff) | |
download | chrome-ec-316a8cb3988f192242023b01625d467aea6d1b19.tar.gz |
stm32: Add proper flash erase timeout
stm32f0 / f3 can take up to 40ms to erase a single sector of flash. Also
add a note about instruction fetch being blocked on flash operation
completion.
TEST=`make buildall -j`
BUG=b:70193071
BRANCH=None
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Icb6c199a975b31f4fa7c73ceb6ad8ec06150abb1
Reviewed-on: https://chromium-review.googlesource.com/815276
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | chip/stm32/flash-f.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c index f1e5b4d85f..51fcf806ae 100644 --- a/chip/stm32/flash-f.c +++ b/chip/stm32/flash-f.c @@ -24,12 +24,20 @@ */ #define CYCLE_PER_FLASH_LOOP 10 +/* + * While flash write / erase is in progress, the stm32 CPU core is mostly + * non-functional, due to the inability to fetch instructions from flash. + * This may greatly increase interrupt latency. + */ + /* Flash page programming timeout. This is 2x the datasheet max. */ -#define FLASH_TIMEOUT_US 16000 +#define FLASH_WRITE_TIMEOUT_US 16000 +/* 20ms < tERASE < 40ms on F0/F3, for 1K / 2K sector size. */ +#define FLASH_ERASE_TIMEOUT_US 40000 static inline int calculate_flash_timeout(void) { - return (FLASH_TIMEOUT_US * + return (FLASH_WRITE_TIMEOUT_US * (clock_get_freq() / SECOND) / CYCLE_PER_FLASH_LOOP); } @@ -353,7 +361,7 @@ int flash_physical_erase(int offset, int size) timeout_us = sector_size * 4 / CONFIG_FLASH_WRITE_SIZE; #else sector_size = CONFIG_FLASH_ERASE_SIZE; - timeout_us = FLASH_TIMEOUT_US; + timeout_us = FLASH_ERASE_TIMEOUT_US; #endif /* Do nothing if already erased */ if (flash_is_erased(offset, sector_size)) |