Skip to content

Commit 396ab26

Browse files
committed
stm32/qspi: Implement MP_QSPI_IOCTL_MEMORY_MODIFIED ioctl.
stm32's QSPI driver supports memory-mapped mode. The memory-mapped flash can also be erased/written to. To support both these modes, it switches in and out of memory-mapped mode during an erase/write. If the flash is erased/written and then switched back to memory mapped mode, the cache related to the memory-mapped region that changed must be invalidated. Otherwise subsequent code may end up reading old data. That cache invalidation is currently not being done, and this commit fixes that. This bug has been around ever since QSPI memory-mapped mode existed, but it's never really been observed because it's not common to use flash in memory-mapped mode and also erase/write it. Eg PYBD_SF2 uses the memory-mapped flash in read-only mode to store additional firmware. But since the introduction of ROMFS, things changed. The `vfs.rom_ioctl()` command can erase/write memory-mapped flash. Signed-off-by: Damien George <[email protected]>
1 parent c61e859 commit 396ab26

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ports/stm32/qspi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ static int qspi_ioctl(void *self_in, uint32_t cmd, uintptr_t arg) {
190190
// Switch to memory-map mode when bus is idle
191191
qspi_memory_map();
192192
break;
193+
case MP_QSPI_IOCTL_MEMORY_MODIFIED: {
194+
uintptr_t *addr_len = (uintptr_t *)arg;
195+
volatile void *addr = (volatile void *)(QSPI_MAP_ADDR + addr_len[0]);
196+
size_t len = addr_len[1];
197+
SCB_InvalidateICache_by_Addr(addr, len);
198+
SCB_InvalidateDCache_by_Addr(addr, len);
199+
break;
200+
}
193201
}
194202
return 0; // success
195203
}

0 commit comments

Comments
 (0)