Skip to content

WIP: stm32/qspi: Detect transfer errors and pass back up to spiflash driver.#6992

Merged
dpgeorge merged 2 commits intomicropython:masterfrom
andrewleech:qspi_errors
Dec 9, 2022
Merged

WIP: stm32/qspi: Detect transfer errors and pass back up to spiflash driver.#6992
dpgeorge merged 2 commits intomicropython:masterfrom
andrewleech:qspi_errors

Conversation

@andrewleech
Copy link
Copy Markdown
Contributor

@andrewleech andrewleech commented Mar 4, 2021

This is an initial attempt to catch and pass up errors in QSPI Flash transfers.

It only has support for stm32 qspi driver.
The regular SPI driver should also likely be extended to pass up errors (if these are detectable).

I haven't looked at what's needed to make other ports compatible with this.

Also, qspi_read_cmd() was already directly returning the read value as a uint32_t. Returning an error code instead of this is not a good way to handle this, likely the return value should be the error code like other functions here now have and the read value passed back in a pointer.

@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Mar 9, 2021

Thanks, this looks like a good improvement but I guess needs a bit more work before it's mergeable.

@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Dec 6, 2022

Actually this looks quite mergeable as-is, and I think we should put it in (it's not a good idea to silently ignore errors).

@andrewleech did you have any further updates to this?

@andrewleech
Copy link
Copy Markdown
Contributor Author

I believe I had this merged in our project and used it as-is.
I didn't make any further changes, no.

Comment thread drivers/memory/spiflash.c Outdated
// Read direct from flash for first part
rest = cache->block * SECTOR_SIZE - addr;
mp_spiflash_read_data(self, addr, rest, dest);
ret = mp_spiflash_read_data(self, addr, rest, dest);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should check for ret!=0 and return here, or the loop will keep going

Comment thread drivers/memory/spiflash.c Outdated
}
}
#endif
return ret;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be return 0, in case USE_WR_DELAY is disabled

Comment thread ports/stm32/qspi.c Outdated
// Wait for write to finish
while (!(QUADSPI->SR & QUADSPI_SR_TCF)) {
if (QUADSPI->SR & QUADSPI_SR_TEF) {
ret = -MP_EIO;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just return -MP_EIO, no need to clear TC because it's not set yet (otherwise this loop would exit). Also TC is cleared on entry to all functions, so it should be OK.

Comment thread ports/stm32/qspi.c Outdated
while (!(QUADSPI->SR & QUADSPI_SR_FTF)) {
if (QUADSPI->SR & QUADSPI_SR_TEF) {
ret = -MP_EIO;
len = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len will be decremented below, then this will loop for a very long time

@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Dec 9, 2022

For the above comments, I'm fixing them during merge.

pi-anl and others added 2 commits December 9, 2022 13:25
This changes the signatures of QSPI write_cmd_data, write_cmd_addr_data and
read_cmd_qaddr_qdata so they return an error code.  The softqspi and stm32
hardware qspi driver are updated to follow this new signature.  Also the
spiflash driver is updated to use these new return values.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge merged commit b042fd5 into micropython:master Dec 9, 2022
@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Dec 9, 2022

Also, qspi_read_cmd() was already directly returning the read value as a uint32_t. Returning an error code instead of this is not a good way to handle this, likely the return value should be the error code like other functions here now have and the read value passed back in a pointer.

I also fixed this in a second commit.

@andrewleech andrewleech deleted the qspi_errors branch August 7, 2024 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants