From 7b9b6b4005dce9f2fac1028648a6b8dee930dcd0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 10 Mar 2020 22:02:12 +0100 Subject: [PATCH] Add an extra delay after erasing a flash memory page Erasing a flash memory page is a relative slow operation and takes a significant amount of time. Therefore, the ready byte is delayed, and the standard timeout is no longer sufficient. Estimate the required delay and wait. Reported-by: Ralph Lembcke --- src/hw_ostc3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 81fd2e0..552ed54 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -1219,12 +1219,16 @@ hw_ostc3_firmware_erase (hw_ostc3_device_t *device, unsigned int addr, unsigned // Convert size to number of pages, rounded up. unsigned char blocks = ((size + SZ_FIRMWARE_BLOCK - 1) / SZ_FIRMWARE_BLOCK); + // Estimate the required delay. Erasing a 4K flash memory page + // takes around 25 milliseconds. + unsigned int delay = blocks * 25; + // Erase just the needed pages. unsigned char buffer[4]; array_uint24_be_set (buffer, addr); buffer[3] = blocks; - return hw_ostc3_transfer (device, NULL, S_ERASE, buffer, sizeof (buffer), NULL, 0, NODELAY); + return hw_ostc3_transfer (device, NULL, S_ERASE, buffer, sizeof (buffer), NULL, 0, delay); } static dc_status_t