DarkElvenAngel
Posts: 125
Joined: Tue Mar 20, 2018 9:53 pm

WiringPi / Raw SPI speed issue

Sun Jun 16, 2019 8:16 pm

Hello I see to have found an issue with the SPI bus and how to get any kind of speed from it.

I have tried three libraries
BCM2835 no issues with speed
WiringPi seems to max out at 500kHz
Raw SPI seems to max out at 500kHz

This all came about when trying to get my OLED to run faster I assumed the driver was no good and began to write my own. Now that I have a Raw SPI driver written and working I find it suffers from the same speed issue.

Does anyone know how to get more speed from the Raw SPI driver / WiringPi?

Thanks

Please note I have gotten slower speeds to work.

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi / Raw SPI speed issue

Sun Jun 16, 2019 8:34 pm

Why not just use the bcm2853 library?

The limit you are reaching is probably the number of SPI transfers per second you can do with the Linux SPI driver.

DarkElvenAngel
Posts: 125
Joined: Tue Mar 20, 2018 9:53 pm

Re: WiringPi / Raw SPI speed issue

Sun Jun 16, 2019 9:09 pm

joan wrote: Why not just use the bcm2853 library?

The limit you are reaching is probably the number of SPI transfers per second you can do with the Linux SPI driver.
I was hoping to avoid the root access required for bcm2853.

I wasn't aware there was transfer limit I did see something about a buffer is there any way to increase this limit?

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi / Raw SPI speed issue

Sun Jun 16, 2019 9:14 pm

The best you can probably do with the Linux SPI driver is pack as much data into each SPI transfer as possible.

DarkElvenAngel
Posts: 125
Joined: Tue Mar 20, 2018 9:53 pm

Re: WiringPi / Raw SPI speed issue

Sun Jun 16, 2019 10:35 pm

I'll give that a try, the way things are written it only sends one byte at a time and I haven't tried this beyond the sample code.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: WiringPi / Raw SPI speed issue

Fri Jun 21, 2019 11:38 am

DarkElvenAngel wrote:
Sun Jun 16, 2019 8:16 pm
Hello I see to have found an issue with the SPI bus and how to get any kind of speed from it.

I have tried three libraries
BCM2835 no issues with speed
WiringPi seems to max out at 500kHz
Raw SPI seems to max out at 500kHz

This all came about when trying to get my OLED to run faster I assumed the driver was no good and began to write my own. Now that I have a Raw SPI driver written and working I find it suffers from the same speed issue.

Does anyone know how to get more speed from the Raw SPI driver / WiringPi?

Thanks

Please note I have gotten slower speeds to work.
wiringPi uses the standard Linux kernel driver. As such, the speed is limited by the hardware - excesses of 48Mb/sec have been achieved.

Your issue is LATENCY, not speed. You need to update the whole device using one single giant write rather that (say) a write per pixel.

-Gordon
--
Gordons projects: https://projects.drogon.net/

DarkElvenAngel
Posts: 125
Joined: Tue Mar 20, 2018 9:53 pm

Re: WiringPi / Raw SPI speed issue

Fri Jun 21, 2019 4:48 pm

[email protected] wrote:
Fri Jun 21, 2019 11:38 am
DarkElvenAngel wrote:
Sun Jun 16, 2019 8:16 pm
Hello I see to have found an issue with the SPI bus and how to get any kind of speed from it.

I have tried three libraries
BCM2835 no issues with speed
WiringPi seems to max out at 500kHz
Raw SPI seems to max out at 500kHz

This all came about when trying to get my OLED to run faster I assumed the driver was no good and began to write my own. Now that I have a Raw SPI driver written and working I find it suffers from the same speed issue.

Does anyone know how to get more speed from the Raw SPI driver / WiringPi?

Thanks

Please note I have gotten slower speeds to work.
wiringPi uses the standard Linux kernel driver. As such, the speed is limited by the hardware - excesses of 48Mb/sec have been achieved.

Your issue is LATENCY, not speed. You need to update the whole device using one single giant write rather that (say) a write per pixel.

-Gordon
This makes sense the software I have only transfers one byte at a time I'm working on a better driver but I have limited time to get into it sadly.

Thanks Gordon I knew that you'd have some light to shine on this. Joan had suggested too that I was hitting some sort of limit.

What about this buffer Gordon I read about how on the WiringPi you can increase it how does one do this with out using the gpio command?

Thanks Gordon and thanks Joan I think I have a good idea of what I must do next.

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: WiringPi / Raw SPI speed issue

Fri Jun 21, 2019 5:21 pm

The Linux SPI driver buffer size is mainly irrelevant to your problem which is caused by the SPI driver transaction overhead.

For the sake of argument assume the Linux SPI driver tops out at 20 thousand transactions per second. If you send one byte per transaction that's 20 thousand bytes per second. If you send one hundred bytes per transaction that's 2 million bytes per second.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: WiringPi / Raw SPI speed issue

Fri Jun 21, 2019 5:34 pm

DarkElvenAngel wrote:
Fri Jun 21, 2019 4:48 pm
[email protected] wrote:
Fri Jun 21, 2019 11:38 am
DarkElvenAngel wrote:
Sun Jun 16, 2019 8:16 pm
Hello I see to have found an issue with the SPI bus and how to get any kind of speed from it.

I have tried three libraries
BCM2835 no issues with speed
WiringPi seems to max out at 500kHz
Raw SPI seems to max out at 500kHz

This all came about when trying to get my OLED to run faster I assumed the driver was no good and began to write my own. Now that I have a Raw SPI driver written and working I find it suffers from the same speed issue.

Does anyone know how to get more speed from the Raw SPI driver / WiringPi?

Thanks

Please note I have gotten slower speeds to work.
wiringPi uses the standard Linux kernel driver. As such, the speed is limited by the hardware - excesses of 48Mb/sec have been achieved.

Your issue is LATENCY, not speed. You need to update the whole device using one single giant write rather that (say) a write per pixel.

-Gordon
This makes sense the software I have only transfers one byte at a time I'm working on a better driver but I have limited time to get into it sadly.

Thanks Gordon I knew that you'd have some light to shine on this. Joan had suggested too that I was hitting some sort of limit.

What about this buffer Gordon I read about how on the WiringPi you can increase it how does one do this with out using the gpio command?

Thanks Gordon and thanks Joan I think I have a good idea of what I must do next.
The default buffer size is 4K. To increase it, I think you need a parameter in /boot/cmdline.txt. You used to be able to set it when you loaded the module, but that changed.

I did some code for an SPI display a few years back - it's resolution was 320x240x16, so I kept a buffer in RAM, updated that and blasted the whole lot in a single transaction to the display in a single operation. I was getting over 20fps that way... I think this is how all the SPI displays work although these days there is a kernel framebuffer driver to for that for you.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “C/C++”