Skip to content

Commit 2ac4d17

Browse files
richardcllipfeerick
authored andcommitted
fix(spiflash): USB storage cannot persist files copied (#7457)
(cherry picked from commit a6542f9)
1 parent d99c8fb commit 2ac4d17

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,21 @@ static DSTATUS spi_flash_initialize(BYTE lun)
9191
}
9292

9393
#if defined(USE_FLASH_FTL)
94-
int flashSize = flashSpiGetSize();
95-
int flashSizeMB = flashSize / 1024 / 1024;
94+
if (frftlInitDone) {
95+
// Do flush when trying to reinit spi flash,
96+
// because the frftl only need to be initialized once
97+
if (!ftlSync(&_frftl)) {
98+
return STA_NOINIT;
99+
}
100+
} else {
101+
int flashSize = flashSpiGetSize();
102+
int flashSizeMB = flashSize / 1024 / 1024;
96103

97-
if (!ftlInit(&_frftl, &_frftl_cb, flashSizeMB)) {
98-
return STA_NOINIT;
104+
if (!ftlInit(&_frftl, &_frftl_cb, flashSizeMB)) {
105+
return STA_NOINIT;
106+
}
107+
frftlInitDone = true;
99108
}
100-
frftlInitDone = true;
101109
#endif
102110

103111
return 0;

0 commit comments

Comments
 (0)