Skip to content

fix(spiflash): USB storage cannot persist files copied#7457

Open
richardclli wants to merge 1 commit into
mainfrom
richardclli/fix-pl18-usb-copy-data-loss
Open

fix(spiflash): USB storage cannot persist files copied#7457
richardclli wants to merge 1 commit into
mainfrom
richardclli/fix-pl18-usb-copy-data-loss

Conversation

@richardclli

@richardclli richardclli commented Jun 15, 2026

Copy link
Copy Markdown
Member

The root cause is after USB unplugged, static DSTATUS spi_flash_initialize(BYTE lun) will be called again. frftl need to be initialized only once, a second init will cause memory leak and data loss.

No problem in 2.10.x, the bug is introduce from 2.11 onwards.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced flash memory initialization to properly handle repeated initialization attempts and ensure reliable storage synchronization when the flash file transfer layer is enabled.

@richardclli richardclli added this to the 2.11.7 milestone Jun 15, 2026
@richardclli richardclli self-assigned this Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

spi_flash_initialize gains a two-path control flow under USE_FLASH_FTL: repeated calls now invoke ftlSync and return STA_NOINIT on failure; first-time calls compute flash size in MB, call ftlInit, and set frftlInitDone only on success.

Changes

FRFTL Initialization Control Flow

Layer / File(s) Summary
FRFTL repeat-init and first-init logic
radio/src/targets/common/arm/stm32/diskio_spi_flash.cpp
Adds a branch for already-initialized state (frftlInitDone) that calls ftlSync and returns STA_NOINIT on failure. First-time path computes flash size in MB before calling ftlInit, and guards frftlInitDone = true behind successful initialization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR description lacks required template structure, missing explicit issue reference and detailed summary section. Add 'Fixes #' with issue number and expand summary under 'Summary of changes:' to match template requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title mentions USB storage and files not persisting, which directly aligns with the PR objective of fixing a persistence bug, but it doesn't specify the technical root cause (repeated initialization of spi_flash_initialize).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch richardclli/fix-pl18-usb-copy-data-loss

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@richardclli

Copy link
Copy Markdown
Member Author

@raphaelcoeffic I am not feeling comfortable about the control flow of USB plug and unplugged, maybe you should take a look in it. I solve my problem using a simple fix, but the point is why the driver will be initialized twice that cause the problem.

@richardclli

Copy link
Copy Markdown
Member Author

@pfeerick I have tested this change, it is ready to merge. I asked Raphael to review, but that is another problem.

@pfeerick pfeerick added backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also. labels Jun 16, 2026
@richardclli

Copy link
Copy Markdown
Member Author

I discovered it when I trying to setup my new heli. The new image file, just didn't store properly.

@pfeerick

Copy link
Copy Markdown
Member

I discovered it when I trying to setup my new heli. The new image file, just didn't store properly.

Thanks for confirming I'm not going nuts... I could have sworn I had similar issues with PL18EV or PA01 but it was intermittent and probably thought I'd forgotten to transfer the files or something.

@pfeerick pfeerick changed the title fix(pl18/pl18ev/nb4p): USB storage cannot persist files copied fix(spiflash): USB storage cannot persist files copied Jun 16, 2026
@richardclli

richardclli commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

Should not affect PA01, only nor flash filesystem has this problem, PA01 is just onboard sdcard chip.

@richardclli richardclli added the bug/regression ↩️ A new version of EdgeTX broke something label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.11 To be backported to a 2.11 release also. backport/2.12 To be backported to a 2.12 release also. bug/regression ↩️ A new version of EdgeTX broke something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants