From a6542f9b0e746d95ebabe4258576c6d5112ec662 Mon Sep 17 00:00:00 2001 From: richardclli Date: Fri, 3 Jul 2026 11:05:45 +0800 Subject: [PATCH] fix(spiflash): USB storage cannot persist files copied (#7457) --- .../common/arm/stm32/diskio_spi_flash.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp b/radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp index 91dc07cf5..df67cb36e 100644 --- a/radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp +++ b/radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp @@ -91,13 +91,21 @@ static DSTATUS spi_flash_initialize(BYTE lun) } #if defined(USE_FLASH_FTL) - int flashSize = flashSpiGetSize(); - int flashSizeMB = flashSize / 1024 / 1024; + if (frftlInitDone) { + // Do flush when trying to reinit spi flash, + // because the frftl only need to be initialized once + if (!ftlSync(&_frftl)) { + return STA_NOINIT; + } + } else { + int flashSize = flashSpiGetSize(); + int flashSizeMB = flashSize / 1024 / 1024; - if (!ftlInit(&_frftl, &_frftl_cb, flashSizeMB)) { - return STA_NOINIT; + if (!ftlInit(&_frftl, &_frftl_cb, flashSizeMB)) { + return STA_NOINIT; + } + frftlInitDone = true; } - frftlInitDone = true; #endif return 0;