-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for SPI #45
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
base: main
Are you sure you want to change the base?
Conversation
… can use async w/o DMA)
|
@decaday I'm having some issues with this on hardware (I'm in a sort of weird configuration, gee whiz). When transmitting as a SPI slave with DMA it mangles the last three bytes of the communication in a nonsensical way, even in 16 bit mode. In this example I'm transmitting 0x0100, 0x0202, 0x0303, 0x0404, then 0x0101, 0x0202, 0x0303, 0x0404, but then am getting 0x0100, 0x0202, 0x0000, 0x0000, 0x0303, 0x0401, 0x0102, 0x0203 back on the wire. Do you know if there's any errata about DMA and SPI?
|
|
Okay, after quite a bit of headache I've concluded that DMA to SPI is broken. There's something wrong where if the DMA ever fills the TXFIFO up and if the DMA stops then the DMA can't be restarted properly and you start to lose bytes. |
|
@BenChung
Most of PY32's IPs are third-party STM32 clones, but there are differences. These IPs often have stricter register configuration requirements, quirky behaviors, or simply more Undefined Behavior (UB). However, since SPI Slave with DMA is such a fundamental feature, I suspect there might be a way to avoid this issue or a specific workaround. Is the code currently in the PR sufficient to test and reproduce the issue you mentioned? I would like to run some tests to verify a few hypotheses I have. |
|
@decaday
Hmm, the stock code starts with SPE=false when it sets the DMA up; otherwise everything looks right... The behavior I'm seeing is that when the DMA backpressure on the TXFIFO stops it starts acting oddly and missing bytes. If I run in circular mode, for example, it's fine, but in a oneshot 4-byte transaction only one byte and three bytes of 0s make it. |
|
@BenChung I tried writing a standard DMA slave example today, but I wasn't able to reproduce the issue you described: |
|
Huh - maybe it's because I'm using it in txonly mode. I'll throw something together tonight. |
|
And when I MWEify it everything works perfectly. This is bizarre, sorry for the issues... |
|
No worries at all. It happens to the best of us. Just let me know if the issue comes back. |


Adds a driver for the SPI peripheral.
Doesn't presently work (needs metapac work, it looks like), not yet tested in hardware.
Changes are still tied up in the I2C implementation.