-
Notifications
You must be signed in to change notification settings - Fork 896
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
Add CS pin to SPIConfig in all architectures #3801
Comments
This has been suggested before, but it's not that simple. If you want to add an API for this, you also need to think of the following cases:
|
I understand this could be a big hit.
My suggestions are not meant as a criticism. It is clear that with limited resources you cannot cover everything. But practically, only one device is currently supported on the SPI bus. It is true that this configuration covers the vast majority of implementations. But it would probably be fair to mention this limitation in the documentation, as well as not supporting 3-wire/half duplex communication. I would like to know if it makes sense to even start discussing this. |
True in a strict sense, but in many cases the settings are in fact the same and reconfiguring the SPI is not necessary. For frequency it's always possible to run at a lower frequency. And most devices work at mode 0, or both mode 0 and mode 3. So the only thing different would be the CS pin.
If you switch at each byte transmitted, it is certainly not minimal: it can increase each byte from 8 ticks to 9 or 9.5 ticks (in the case of the rp2040, it's 9.5). That's a 19% loss in performance.
I see, you mean supporting CS inside the machine package for chips that don't support it. Yes, that would satisfy my API concerns. However, this would still be a slight loss in performance for chips that don't support CS in hardware. Take a look at tinygo-org/drivers#549 for example. In this case I only switch CS when needed, combining multiple transactions and only changing CS at the start and end of it. Can you provide some concrete examples where configuring SPI in hardware would be beneficial, and how a driver would use this feature? It doesn't really help talking about hypothetical situations. |
I agree that it is good to deal with real problems and situations. And while I believe that HW support for the CS pin in the SPI driver is a good thing and would not be too complicated to implement properly, there are many issues with higher priority. One of them, in my opinion, is the lack of support for the ESP32 family in tinygo. I'd be happy to help improve it, but I'd address this in a separate thread. Here I would just like to mention an outline of HW support for CS:
|
This seems like a hardware dependent thing... could we not add a method on the machine.SPI type, i.e: |
Also duplicate of #1615 |
When configuring the SPI bus, the CS (SS) pin is not directly part of the bus configuration in most MCUs (currently only in ESP32C3 and MIMXRT1062). This does not allow to take full advantage of HW SPI support and activation of the CS pin is part of the driver (see tinygo-org/drivers#583). Where possible it would be a good idea to add the option to configure the CS pin directly in the
machine.SPIConfig
type definition.I can try to add it for ESP32 architecture.
The text was updated successfully, but these errors were encountered: