Skip to content

Commit a2396e7

Browse files
committed
[rp2350] Added cache in RAM for hal_flash_write
1 parent 82e4950 commit a2396e7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

hal/rp2350.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,21 @@ void hal_prepare_boot(void)
224224

225225
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
226226
{
227-
flash_range_program(address - XIP_BASE, data, len);
227+
uint8_t cache[WOLFBOOT_SECTOR_SIZE];
228+
uint32_t written = 0;
229+
uint32_t sz;
230+
if (((uintptr_t)data & 0x20000000UL) == 0) {
231+
/* Not in RAM: copy to cache before writing */
232+
while (written < len) {
233+
sz = WOLFBOOT_SECTOR_SIZE;
234+
if (sz > (len - written))
235+
sz = len - written;
236+
memcpy(cache, data + written, sz);
237+
flash_range_program(address - XIP_BASE + written, cache, sz);
238+
written += sz;
239+
}
240+
} else
241+
flash_range_program(address - XIP_BASE, data, len);
228242
return 0;
229243
}
230244

0 commit comments

Comments
 (0)