Skip to content

Commit ba1d924

Browse files
rghaddabcarlescufi
authored andcommitted
[nrf fromtree] drivers: flash: nrf_rram: add support for RRAM throttling
Some applications need to throttle RRAM writes to handle peak current management. Add CONFIG_NRF_RRAM_THROTTLING_DATA_BLOCK which defines the maximum chunk length that can be written at once. Add CONFIG_NRF_RRAM_THROTTLING_DELAY which configures the sleep delay in microseconds after each write. Signed-off-by: Riadh Ghaddab <[email protected]> (cherry picked from commit a4f5d9f)
1 parent a2c3a8e commit ba1d924

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

drivers/flash/Kconfig.nrf_rram

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ config SOC_FLASH_NRF_RADIO_SYNC_NONE
5656
bool "none"
5757
help
5858
disable synchronization between flash memory driver and radio.
59+
5960
endchoice
6061

62+
config SOC_FLASH_NRF_THROTTLING
63+
bool "Nordic nRFx throttling for flash write operations"
64+
help
65+
Enable throttling for flash write operations to avoid overloading the
66+
flash memory controller.
67+
6168
config SOC_FLASH_NRF_TIMEOUT_MULTIPLIER
6269
int "Multiplier for flash operation timeouts [x0.1]"
6370
depends on !SOC_FLASH_NRF_RADIO_SYNC_NONE
@@ -81,4 +88,20 @@ config NRF_RRAM_REGION_SIZE_UNIT
8188
help
8289
Base unit for the size of RRAMC's region protection.
8390

91+
config NRF_RRAM_THROTTLING_DELAY
92+
int "Delay between flash write operations"
93+
depends on SOC_FLASH_NRF_THROTTLING
94+
default 2000
95+
help
96+
This is the delay (in microseconds) between consecutive flash write
97+
operations when throttling is enabled.
98+
99+
config NRF_RRAM_THROTTLING_DATA_BLOCK
100+
int "Number of Data blocks for each flash write operations"
101+
depends on SOC_FLASH_NRF_THROTTLING
102+
default 16
103+
help
104+
This is the number of data blocks (in number of 128-bit words) for flash write
105+
operations when throttling is enabled.
106+
84107
endif # SOC_FLASH_NRF_RRAM

drivers/flash/soc_flash_nrf_rram.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,24 @@ static void rram_write(off_t addr, const void *data, size_t len)
164164
nrf_rramc_config_set(NRF_RRAMC, &config);
165165
#endif
166166

167-
if (data) {
168-
memcpy((void *)addr, data, len);
169-
} else {
170-
memset((void *)addr, ERASE_VALUE, len);
167+
size_t chunk_len = len;
168+
169+
#ifdef CONFIG_SOC_FLASH_NRF_THROTTLING
170+
while (len > 0) {
171+
chunk_len = MIN(len, CONFIG_NRF_RRAM_THROTTLING_DATA_BLOCK * WRITE_LINE_SIZE);
172+
#endif /* CONFIG_SOC_FLASH_NRF_THROTTLING */
173+
if (data) {
174+
memcpy((void *)addr, data, chunk_len);
175+
} else {
176+
memset((void *)addr, ERASE_VALUE, chunk_len);
177+
}
178+
#ifdef CONFIG_SOC_FLASH_NRF_THROTTLING
179+
addr += chunk_len;
180+
data = (const uint8_t *)data + chunk_len;
181+
len -= chunk_len;
182+
k_usleep(CONFIG_NRF_RRAM_THROTTLING_DELAY);
171183
}
184+
#endif /* CONFIG_SOC_FLASH_NRF_THROTTLING */
172185

173186
barrier_dmem_fence_full(); /* Barrier following our last write. */
174187

0 commit comments

Comments
 (0)