-
Notifications
You must be signed in to change notification settings - Fork 1k
SPI library optimization #257
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
Hi @d21d3q, |
I thought that it will be easier, but since SPI has to work with default settings (without How about making function |
Last CS pin used and its |
I've also been looking at the SPI code today, and I'm a bit confused about how the CS pin handling works. It actually looks like there might be some misunderstanding about how the To better understand the Arduino SPI API, let me explain how this API came to be. Originally, the SPI library on AVR worked like this:
This worked well for simple sketches, but was a bit problematic for sketches that needed to talk to multiple devices, especially when the SPI communication and initialization happened inside libraries. Since there is only a single set of SPI settings, all communication would use the same settings, which is the last set of settings passed to To prevent this, we invented the
Mixing both approaches was also valid, but then the "legacy" code (that did not use transactions) would simply use whatever config was used by the last transaction (leaving it potentially just as broken or working as when it used the configuration from the last In addition, this transaction approach had one extra advantage: It could also be used to disable certain interrupts during every SPI transaction when you know that those interrupt handlers are going to use SPI transfers as well (this is what the not-so-greatly-named Furthermore, the SAM MCU (Arduino Due) has support for hardware-controlled CS pins, so it added a variant of However, now I look more closely at the SAM implementation, it actually seems that most of the API in the STM32 core actually comes from the SAM core. Looking there, they also pass pin numbers to transfer and store configuration. However:
I actually think that most of this API does not really make sense (at all, and even less on STM32). In fact, I think that there is not even any real point in letting the hardware manage CS at all. It just adds confusion, is not really portable and only helps for a single slave device, for the others you need to manage CS manually anyway. So I would think the SPI library can be greatly simplified, when the regular API outlined above (as used by most other Arduino cores) is adopted. In particular:
|
@matthijskooijman I know, this could be improved. This "driver" has never been updated nor improved while it should. That's the purpose of this issue. I agree that all your remark's make sense and have to be take in account for this rework. |
I'm missing a simple way to set up a SPI-slave. |
I totally DO NOT use the "standard" SPI libraries. Found an alternative one that works with DMA and non-DMA and it can be "brutally" fast. Have a SSD1322 OLED (256*64 * 4 bpp) running 50+ fps with 16Khz sound from the SD. It also allows use of all SPI pins and can mix and match. I also "murdered" my copy of the 1.8 core and removed ALL "PinName" references as D1, D2, D3, A1, A2, just do not make any sense when the board has PA_1, PB_13 etc. https://stm32f4-discovery.net/api/group___t_m___d_e_l_a_y.html |
PYn, Dx, Ax,... are pin numbers and it make sense for Arduino compatibility. 😉 This is a community project. Our first goal was to be as far as possible Arduino compatible. |
@Hoek67 What is the fast DMA library you are using? And what STM32 MCU are you using with your screen? |
I use exclusively now STM32F407VET6. Has inbuilt RTC, SDIO micro SD, 2 * 12 bit DAC and lot of other features that made it superior to the Due I was using. (512KB EPROM, 192K SRAM, 168Mhz) Libraries are by Tilen Majerie and are a little bit dated but works as advertised. http://stm32f4-discovery.net/2015/07/all-stm32-hal-libraries/ He has sample code for each part. 3 main libraries of use. DMA, SPI and SPI DMA. One thing I didn't like about the core was the PinNames that I wanted to use conflicted with my library as the pins are all uint8_t. Also a STM32 pin ie (PA_1) should map directly to a port and offset and every reference to a pin in the core needs a lookup to get the actual port 1st which for some low level stuff adds a lot of overhead. Got confusing when some libraries have pin as the physical pin and the Arduino core had a mapped pin. I added a bit of functionality to the SPI DMA library when I sussed it out. By default they do the transfer and wait for it to finish. With my higher level library that hooks in waiting is optional.
I also use his I2C library instead of the Arduino one, seems to work well. Hope this helps. |
To be aligned with Arduino API. Only Hardware CS pin support kept. Allows to save memory space and increase execution speed. Fixes stm32duino#257. Signed-off-by: Frederic Pillon <[email protected]>
To be aligned with Arduino API. Only Hardware CS pin support kept. Allows to save memory space and increase execution speed. Fixes stm32duino#257. Signed-off-by: Frederic Pillon <[email protected]>
To be aligned with Arduino API. Only Hardware CS pin support kept. Allows to save memory space and increase execution speed. Fixes stm32duino#257. Signed-off-by: Frederic Pillon <[email protected]>
Can I refer to problem described here?
Actually it refers to both stm32duino and other libraries.
beginTransaction
could check if SPI is initialized and skip it.transfer
also seems to take longer on Nucleo rather than on Nano (see images in referenced issue).The text was updated successfully, but these errors were encountered: