-
Notifications
You must be signed in to change notification settings - Fork 264
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
Fix incorrect QSPI setup #2231
Fix incorrect QSPI setup #2231
Conversation
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.
This actually fixes #2229 - weird given the result of the bisect and also manually checking that commit and the one before - Thanks!
Awesome. The problem is, that the RX/TX swap introduced a buffer size issue and maybe your flash chip flashed the last 256 |
I've been banging my head against ESP32 for a while now, and I think that chip simply can't do a 4-line address phase if it doesn't have data to transmit afterwards. The chip defaults back to 1-line address phase if |
Just return an error if it's not supported I think. |
Why? It's supported everywhere else, users expect it to work and it's simple to work around. |
It's not like all the SPI hardware on all chips works the same. Some have more features that others. It just so happens the ESP32 can't support this one case. If users want it to "just work" everywhere, they should just use the data phase for everything themselves. Doing it secretly is too hacky imo. |
Also, not all implementations of |
One of the jobs of the HAL is to equalize support as much as possible.
Then they will be free to return an error. |
How is that different from just returning an error upfront? User will still end up having to deal with it. Also users won't be expecting their
Yeah but there should be a line somewhere I think. |
There's the option of not using DMA and just using the CPU Buffer for the data phase. (I don't really like this solution either to be honest, but it's better than tampering with the DMA buffer). |
Sorry @bjoernQ I managed to completely hijack this PR, do you want me to send in the original fix separately? |
No problem - thanks for taking care of this |
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.
LGTM, thanks!
esp-hal/src/spi/master.rs
Outdated
// on a single line, regardless of its data mode. | ||
if bytes_to_write == 0 && address.mode() != SpiDataMode::Single { | ||
let bytes_to_write = address.width().div_ceil(8); | ||
let addr_bytes = address.value().to_le_bytes(); |
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.
Don't be hasty, I need to verify if I got the endianness right here.
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.
iirc the bit order of the data phase can changed so you'll probably have to read that register bit to decide the endianness here.
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.
SPI_WR_BIT_ORDER affects all (CMD, ADDR and DATA) phases so I think I'm fine here.
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.
That being said, I wanted to look at this with a logic analyzer because this workaround exists due to the hardware not doing what it's supposed to.
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.
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.
Nice!
I just remembered, will this work as the user expects if they specify a dummy phase?
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.
No, the dummy phase gets moved to before the address which is wrong. But that'll need to be addressed later as there are a few different approaches to deal with that (error, ignore, emulate). This current PR is done the way it is.
Opened #2240 so we don't forget about it.
"Places the SPI driver in RAM for better performance", | ||
), | ||
( | ||
"spi-address-workaround", |
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.
Do you reckon libraries may want to set this?
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.
There should be one source of truth for the config, and it should lie in the hands of the user. In this case, we've enabled it by default, which is a sane thing to do, and users can opt-out. One thing libraries can do is detect if the setting is enabled and either warn/panic if it should be - but even this I would discourage unless the library functionality depended on it.
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.
Thanks!
Hold on there's still something not quite right here :) |
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
Two-parter:
This fixes #2229 and adds test code to make sure we don't break QSPI again. This PR also works around an ESP32 limitation.
Testing
Observed behaviour change using a logic analyzer and also the changed test cases fail before the fix.