Conversation
w25n_performCommandWithPageAddress() sent a fixed zero byte followed by 16 bits of page address. That is correct for the 1Gbit W25N01GV, which has 1024 blocks of 64 pages and therefore 65536 pages, but not for the 2Gbit W25N02KV and MX35LF2G. Both have 2048 blocks of 64 pages, so page addresses run up to 131071 and the first address byte carries bit 16. With the upper bit dropped, page data read, program execute and block erase all addressed the lower half of the chip, so the upper half mirrored onto the lower half: erasing a block in the upper half erased the wrong block, and the data of the upper half was never reachable. Pass bits 23..16 of the page address in the first address byte. On the W25N01GV those bits are zero for every valid page address, so the instruction sequence for that device is unchanged. Found while investigating iNavFlight#11376
Raffi1202
marked this pull request as ready for review
September 11, 2026 15:42
Contributor
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoSend full page addresses to 2 Gbit W25N flash devices
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can switch off images and animations for a plain-text comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#11376 reports that on a RADIOLINKF405
flash_eraseprints "Done" andflash_infoshowsusedSize=0, but after a power cycle the oldusedSizeis back. That board has a 1 Gbit W25N01GV. While reading the driver for that report, a second defect turned up that affects only the 2 Gbit parts served by the same driver (W25N02KV on NEXUSX and ORBITH743, MX35LF2G): bit 16 of the page address is never sent, so every read, program and erase aimed at the upper 128 MB lands in the lower half. This PR fixes that defect only; the bytes sent to a W25N01GV are unchanged, so it does not close #11376.Cause
src/main/drivers/flash_w25n.c:163on maintenance-10.x:w25n_performCommandWithPageAddress()sends{ command, 0, pageAddress >> 8, pageAddress }, a fixed zero followed by 16 address bits. The W25N01GV has 1024 blocks x 64 pages = 65536 pages (:38), which fits; the W25N02KV and MX35LF2G have 2048 blocks (:39-40), so page addresses reach 131071 and bit 16 is lost. All three callers go through this helper: block erase (:305), program execute (:345), page data read (:494). FLASHFS spans every sector (src/main/drivers/flash.c:217), so addresses above 128 MB are reached in normal logging.Change
The first address byte now carries bits 23..16 of the page address instead of a constant zero, with a comment explaining why. On the W25N01GV those bits are zero for every valid page, so its wire sequence is byte-for-byte unchanged. No die select is added: the driver's geometry gives 2048 blocks per die for both 2 Gbit parts.
Test
Not run on hardware, and no CI run exists for this branch yet. Cause verified by reading
flash_w25n.c:163and the geometry table at:237-274on maintenance-10.x. The byte layout matches Betaflight's driver, which sends(pageAddress >> 16) & 0xffin the same position: https://github.com/betaflight/betaflight/blob/master/src/main/drivers/flash/flash_w25n.c. Qodo review on 31d637f: 0 bugs.Flash / RAM
Not measured yet. The upstream firmware CI has not been released for this PR, so no size report exists.
Docs
No documentation change needed:
docs/Blackbox.md:125anddocs/development/targets/common-issues.md:361already list the W25N02 as a 2 Gbit / 256 MB chip; the driver now matches that.