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

Add support for 4-byte QSPI flash addressing #295

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

barbedo
Copy link
Contributor

@barbedo barbedo commented Jan 21, 2023

Refer to #293.

src/spiFlash.cpp Outdated
Comment on lines 122 to 141
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);

Copy link
Owner

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);

Copy link
Contributor Author

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.

@trabucayre trabucayre merged commit 43e6c0c into trabucayre:master Jan 23, 2023
@trabucayre
Copy link
Owner

Applied thanks @barbedo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants