-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add support for 4-byte QSPI flash addressing #295
Add support for 4-byte QSPI flash addressing #295
Conversation
src/spiFlash.cpp
Outdated
uint8_t tx[5]; | ||
uint32_t len; | ||
|
||
if (addr <= 0xffffff) { | ||
tx[0] = static_cast<uint8_t>(FLASH_SE ); | ||
tx[1] = static_cast<uint8_t>(0xff & (addr >> 16)); | ||
tx[2] = static_cast<uint8_t>(0xff & (addr >> 8)); | ||
tx[3] = static_cast<uint8_t>(0xff & (addr )); | ||
len = 4; | ||
} else { | ||
tx[0] = static_cast<uint8_t>(FLASH_4SE ); | ||
tx[1] = static_cast<uint8_t>(0xff & (addr >> 24)); | ||
tx[2] = static_cast<uint8_t>(0xff & (addr >> 16)); | ||
tx[3] = static_cast<uint8_t>(0xff & (addr >> 8)); | ||
tx[4] = static_cast<uint8_t>(0xff & (addr )); | ||
len = 5; | ||
} | ||
|
||
_spi->spi_put(tx, NULL, len); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looks good but too avoid to many dupplication maybe it's better to do something like (and of course same idea for next modifications):
uint8_t tx[5];
uint32_t len = 0;
uint8_t cmd = (addr <= 0xffffff) ? FLASH_SE : FLASH_4SE;
if (addr <= 0xffffff) {
tx[len++] = static_cast<uint8_t>(cmd );
if (cmd == FLASH_4SE)
tx[len++] = static_cast<uint8_t>(0xff & (addr >> 24));
tx[len++] = static_cast<uint8_t>(0xff & (addr >> 16));
tx[len++] = static_cast<uint8_t>(0xff & (addr >> 8));
tx[len++] = static_cast<uint8_t>(0xff & (addr ));
_spi->spi_put(tx, NULL, len);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree. Please check the updated version.
To verify that this still works, I've cherry-picked this latest commit on top of my vcu118-flash
branch and loaded/dumped a memory file that is larger than 16 MB.
Applied thanks @barbedo |
Refer to #293.