Skip to content

Commit 9892af1

Browse files
saty9stephanosio
authored andcommitted
drivers: flash: soc_flash_nrf: Account for ticker in timeout
We have been encountering timeout issues when erasing large flash sections (before receiving an image via mcuboot) from this semaphore take: https://github.com/zephyrproject-rtos/zephyr/blob/5af0fbc2e30250968289ff4d3ffb69ea45f41d37/drivers/flash/soc_flash_nrf_ticker.c#L225-L233 I think this is because this constant is based on the time taken to erase the chip but doesn't take account of the fact it is being done by a ticker. If I understand correctly the ticker is a timeshare mechanism so the actual max erase time is some factor based on how much time is given to the task by the ticker. This multiplies the max timeout by 1.5 Signed-off-by: Kyle Cooke <[email protected]>
1 parent 230c80e commit 9892af1

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

doc/releases/release-notes-3.3.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Drivers and Sensors
128128

129129
* Flash
130130

131+
* NRF: Added CONFIG_SOC_FLASH_NRF_TIMEOUT_MULTIPLIER to allow tweaking the timeout of flash operations.
132+
131133
* GPIO
132134

133135
* I2C

drivers/flash/Kconfig.nrf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ config SOC_FLASH_NRF_PARTIAL_ERASE_MS
6767
Minimal timeout is 2ms maximum should not exceed half of
6868
FLASH_PAGE_ERASE_MAX_TIME_US im ms.
6969

70+
config SOC_FLASH_NRF_TIMEOUT_MULTIPLIER
71+
int "Multiplier for flash operation timeouts [x0.1]"
72+
depends on !SOC_FLASH_NRF_RADIO_SYNC_NONE
73+
default 15 if SOC_FLASH_NRF_PARTIAL_ERASE && SOC_FLASH_NRF_RADIO_SYNC_TICKER
74+
default 10
75+
help
76+
This is a multiplier that will be divided by 10 that is applied
77+
to the flash erase and write operations timeout. The base for
78+
the multiplication would allow erasing all nRF flash pages in
79+
blocking mode.
80+
7081
config SOC_FLASH_NRF_UICR
7182
bool "Access to UICR"
7283
depends on !TRUSTED_EXECUTION_NONSECURE

drivers/flash/soc_flash_nrf.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@ struct flash_context {
2929

3030
#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE
3131

32-
#if defined(CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE)
33-
/* The timeout is multiplied by 1.5 because switching tasks may take
34-
* significant portion of time.
32+
/* The timeout is multiplied by CONFIG_SOC_FLASH_NRF_TIMEOUT_MULTIPLIER/10
33+
* because switching tasks may take a significant portion of time.
3534
*/
3635
#define FLASH_TIMEOUT_MS ((FLASH_PAGE_ERASE_MAX_TIME_US) * \
37-
(FLASH_PAGE_MAX_CNT) / 1000 * 15 / 10)
38-
#else
39-
40-
#define FLASH_TIMEOUT_MS ((FLASH_PAGE_ERASE_MAX_TIME_US) * \
41-
(FLASH_PAGE_MAX_CNT) / 1000)
42-
#endif /* CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE */
36+
(FLASH_PAGE_MAX_CNT) / 1000 * \
37+
CONFIG_SOC_FLASH_NRF_TIMEOUT_MULTIPLIER / 10)
4338

4439
/**
4540
* @defgroup nrf_flash_sync sync backend API

0 commit comments

Comments
 (0)