Skip to content

Commit 6065ddb

Browse files
kamnxtkartben
authored andcommitted
drivers: flash: spi_nor: make wait_until_ready erase delay configurable
The erase time varies between different SPI NOR flash chips. Some have typical erase times in the 20-25ms range, at which point the default 50ms poll interval means we get half the possible erase speed. With slower memory, or larger erases, 50ms might not be a lot, but for block erases, if we are unlucky we may end up polling just as the it's about to finish erasing, and have to wait another poll interval. Signed-off-by: Kamil Krzyzanowski <kamnxt@kamnxt.com>
1 parent edb55ba commit 6065ddb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/flash/Kconfig.nor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ config SPI_NOR_SLEEP_WHILE_WAITING_UNTIL_READY
6868
result in significant flash savings if this driver is the only user
6969
of "k_sleep". This can be the case when building as a bootloader.
7070

71+
config SPI_NOR_SLEEP_ERASE_MS
72+
int "Delay between polls while waiting for an erase operation in ms"
73+
default 50
74+
help
75+
The delay between polling while waiting for the flash to finish
76+
an erase operation.
77+
depends on SPI_NOR_SLEEP_WHILE_WAITING_UNTIL_READY
78+
79+
7180
config SPI_NOR_FLASH_LAYOUT_PAGE_SIZE
7281
int "Page size to use for FLASH_LAYOUT feature"
7382
default 65536

drivers/flash/spi_nor.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,17 @@ static const struct jesd216_erase_type minimal_erase_types_4b[JESD216_NUM_ERASE_
221221
};
222222
#endif /* CONFIG_SPI_NOR_SFDP_MINIMAL */
223223

224+
224225
/* Register writes should be ready extremely quickly */
225226
#define WAIT_READY_REGISTER K_NO_WAIT
226227
/* Page writes range from sub-ms to 10ms */
227228
#define WAIT_READY_WRITE K_TICKS(1)
228-
/* Erases can range from 45ms to 240sec */
229-
#define WAIT_READY_ERASE K_MSEC(50)
229+
230+
#ifdef CONFIG_SPI_NOR_SLEEP_WHILE_WAITING_UNTIL_READY
231+
#define WAIT_READY_ERASE K_MSEC(CONFIG_SPI_NOR_SLEEP_ERASE_MS)
232+
#else
233+
#define WAIT_READY_ERASE K_NO_WAIT
234+
#endif
230235

231236
static int spi_nor_write_protection_set(const struct device *dev,
232237
bool write_protect);

0 commit comments

Comments
 (0)