Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Winbond 512 mbit and 1 gbit flash chips (IDFGH-7854) #9381

Closed
wants to merge 1 commit into from

Conversation

johnboiles
Copy link

@johnboiles johnboiles commented Jul 18, 2022

Currently the flash detection logic doesn't work for Winbond chips 512 megabit and above. The bitwise math assumption that uses the last byte of the ID seems to work fine for all smaller chips but for some unknown reason there's not a clean increment of that value from 256 megabit (which has a last byte of 0x19) to 512 megabit (which has a last byte of 0x20). Seems possible this was a design mistake on Winbond's part that they now can't undo.

LittleFS has a handy list of Winbond IDs and sizes: https://github.com/PaulStoffregen/LittleFS/blob/d5de4cf8d1587aa8b2433962ea995d45a991b918/src/LittleFS.cpp#L46

This PR adds a special case for known Winbond 512 megabit and 1 gigabit flash chips mentioned in the above list. I've personally tested this against the W25Q512JVEQ chip on an ESP32-S3 and it resolves a bootloader failure that looks like this:

I (712) spi_flash: detected chip: winbond
I (716) spi_flash: flash io: dio
E (720) spi_flash: Detected size(0k) smaller than the size in the binary image header(16384k). Probe failed.
E (761) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0

This makes sense, because 1 << 0x20 == 4294967296 which, for a uint32_t like size would be the same as 0.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jul 19, 2022
@github-actions github-actions bot changed the title Support for Winbond 512 and 1000 mbit flash chips Support for Winbond 512 and 1000 mbit flash chips (IDFGH-7854) Jul 19, 2022
@johnboiles johnboiles changed the title Support for Winbond 512 and 1000 mbit flash chips (IDFGH-7854) Support for Winbond 512 mbit and 1 gbit flash chips (IDFGH-7854) Jul 19, 2022
@Alvin1Zhang
Copy link
Collaborator

Thanks for your contribution.

@johnboiles
Copy link
Author

You're welcome! I'm eager to get support for these chips in IDF!

@igrr
Copy link
Member

igrr commented Aug 4, 2022

@johnboiles Do you know if this logic for 512M/1Gbit chips is common for other vendors?

If this is Winbond-specific logic, then it could be a better option to define a Winbond-specific spi_flash_chip_winbond_detect_size function in spi_flash_chip_winbond.c and replace the .detect_size function pointer with the Winbond-specific version:

.detect_size = spi_flash_chip_generic_detect_size,

@johnboiles
Copy link
Author

johnboiles commented Aug 4, 2022

I don't know! But I doubt it's common, seems like a mistake. I'll move this logic to a Winbond specific method. Good idea

@igrr
Copy link
Member

igrr commented Aug 4, 2022

Having checked the GD25Q512 datasheet, the ID is 0xc84020. So at least it's common between GD and Winbond.

@johnboiles
Copy link
Author

Is that enough reason to keep this logic in the common method you think?

@KonssnoK
Copy link
Contributor

KonssnoK commented Aug 5, 2022

Hello, if i may add a suggestion, i would remove magic numbers in favor of defines :)
Like, what is 0x4020 ?

thanks!

@johnboiles
Copy link
Author

Agree that it's worth killing magic numbers in general. What do you think this should be named? COMMON_FLASH_PRODUCT_ID_512MBIT perhaps?

Reading the IDF 4.4.2 release notes I came across #7688 and it's a bit of a mystery to me how they were able to test the 512mbit and 1024mbit Winbond chips without this fix.

@KonssnoK
Copy link
Contributor

KonssnoK commented Aug 8, 2022

I guess they didn't :)
"as soon we can test 256MB, 512MB and the 1024MB i update with a new Pull Request"
(also there seems to be some confusion between bit and bytes, i guess those are bits, since the maximum size offered by Winbond is 4Gbit -> 512MB 🤔 )
W25N04KV

I would take other defines structure.
SPI_FLASH_GENERIC_PAGE_PROGRAM_TIMEOUT_MS
So maybe
SPI_FLASH_GENERIC_ID_512MBIT ? In the end strict naming is not important if it's clear what is it about and where it belongs

also,
@johnboiles could you take a look at
#9503
?
Thanks!

@KonssnoK
Copy link
Contributor

KonssnoK commented Aug 16, 2022

Having checked the GD25Q512 datasheet, the ID is 0xc84020. So at least it's common between GD and Winbond.

Winbond W25N01GV is 1Gbit and has AA21 as identifier, so this change won't work for that.

EDIT:

0x15 = 16Mbit
0x16 = 32Mbit
0x17 = 64Mbit
0x18 = 128Mbit
0x19 = 256Mbit
0x20 = 512Mbit
0x21 = 1Gbit

I guess they didn't count in hex but in decimal...

@KonssnoK
Copy link
Contributor

@igrr
Please check my changes in the above referenced PR
(substitutes this one)

@johnboiles
Copy link
Author

johnboiles commented Aug 17, 2022

Micron also looks like it uses the same weird convention and it extends to 2gbit:

image

@KonssnoK your alternate PR (#9566) looks good to me. Let's run with that instead.

@lorenzopeluso
Copy link

lorenzopeluso commented Nov 5, 2022

Just for information and confirmation, I tried with Winbond W25Q02JVTBIM with 2Mb of capacity. The proposed patch does work!

Need just a other modification:

if ((id & 0xFFFF) == 0x4020 || (id & 0xFFFF) == 0x7020) {
        *size = 0x4000000;
    } else if ((id & 0xFFFF) == 0x4021) {
        *size = 0x8000000;
    } else if ((id & 0xFFFF) == 0x7022) {
        *size = 0x10000000;
    } else {
        *size = 1 << (id & 0xFF);
    }

in order to add the ID (from datasheet) 0x7022 and to assign the right capacity of 262144 KB.

The result is shown in the attached image.

Be careful.....the format takes about 16 minutes. :).

Thanks a lot.
Cheers,
Lorenzo.

Cattura

@KonssnoK
Copy link
Contributor

KonssnoK commented Nov 5, 2022

@lorenzopeluso please try #9566
it should work without changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants