Skip to content

Add support for 4-byte QSPI flash addressing#295

Merged
trabucayre merged 2 commits into
trabucayre:masterfrom
barbedo:vcu118-flash-4B-address
Jan 23, 2023
Merged

Add support for 4-byte QSPI flash addressing#295
trabucayre merged 2 commits into
trabucayre:masterfrom
barbedo:vcu118-flash-4B-address

Conversation

@barbedo
Copy link
Copy Markdown
Contributor

@barbedo barbedo commented Jan 21, 2023

Refer to #293.

Comment thread src/spiFlash.cpp
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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