-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
RP2: machine.spi LSB first is unsupported (also SoftSPI) #11404
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
Comments
Any update? |
I made a PR once for LSB first with SoftSPI, but closed it since there were too many PRs open. I can re-open that PR, such that people can build their own firmware based on it. |
See PR #15436. |
@robert-hh thank you! |
The RP2040 hardware SPI doesn't support LSB mode. And it's quite difficult to synthesize LSB mode: eg if the driver transforms all the bytes before sending them out that won't be possible if the data to send is a read-only bytes object (and in ROM). So I think the rp2 port just has to remain without SPI.LSB for hardware SPI. Instead one would need to use software SPI if LSB mode is needed (and software SPI.LSB will be implemented in #15436). |
@dpgeorge i see thanks. Currently I am using hardware SPI by preprocessing the data thru a function that converts MSB to LSB. Not optimal but the only way I found. |
Once #15436 is merged I suggest you use |
@dpgeorge thanks, will do! |
Being able to send data out in LSB format can be useful, and having support in the low-level driver is much better than requiring Python code to reorder the bits before sending them / after receiving them. In particular if the hardware does not support the LSB format (eg RP2040) then one needs to use the SoftSPI in LSB mode. For this change a default definition of `MICROPY_PY_MACHINE_SPI_MSB/_LSB` was added to `py/mpconfig.h`, making them available to all ports. The identical defines in `esp32/mpconfigport.h` were deleted. Resolves issues micropython#5340, micropython#11404. Signed-off-by: robert-hh <robert@hammelrath.com>
LSB for SoftSPI was implemented in ee10360 @peterhinch I think we can now close this issue. I know rp2 hardware SPI still doesn't support LSB, but that's a hardware limitation that we can't really resolve. Unless it automatically switches to software SPI when configured in LSB mode... the argument for that would be to make it transparently support LSB mode, instead of the user having to explicitly use SoftSPI when they want LSB. |
What's the behaviour when you try to use HW SPI and LSB on a port that doesn't have it? Ideally I think it should not be a syntax error (ie firstbit should still be present) but an exception should be raised (ValueError?) that indicates that the option is not available for that port. I don't think it should automatically switch to SoftSPI... |
On rp2, if you try to construct a hardware SPI object in LSB mode, it raises a
As a counterpoint, the rp2 hardware I2C implementation switches automatically to software I2C for zero-length writes, eg But in the case of SPI LSB mode, arguably you don't switch between LSB and MSB dynamically. Rather, you pick one of those modes at the start and stick with it. So if you need LSB then just use |
Being able to send data out in LSB format can be useful, and having support in the low-level driver is much better than requiring Python code to reorder the bits before sending them / after receiving them. In particular if the hardware does not support the LSB format (eg RP2040) then one needs to use the SoftSPI in LSB mode. For this change a default definition of `MICROPY_PY_MACHINE_SPI_MSB/_LSB` was added to `py/mpconfig.h`, making them available to all ports. The identical defines in `esp32/mpconfigport.h` were deleted. Resolves issues micropython#5340, micropython#11404. Signed-off-by: robert-hh <robert@hammelrath.com>
This arose here. The driver sets up a passed SPI instance as follows:
which fails with
NotImplementedError: LSB
(hard SPI) orValueError:firstbit must be MSB
(soft SPI).The constant
LSB
does exist.The text was updated successfully, but these errors were encountered: