From 06d6958df944fb0a5d8285bf6d8223b635fc07c5 Mon Sep 17 00:00:00 2001 From: Richard Li Date: Mon, 15 Jun 2026 13:10:02 +0800 Subject: [PATCH] Fixed PL18 USB storage file copy will not persist problem --- .../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 91dc07cf54f..df67cb36e56 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;