py-spidev mod help


7 posts
by flutie98 » Thu Mar 14, 2013 2:39 am
Hi,

I'm trying to use the py-spidev python wrapper to send large lists (~32768) of bytes over SPI in a single shot of spi.writebytes()

It however has a spidev_max_path argument of 4096 and an accompanied error message in spi.writebytes for lists larger than 4096 "Argument must be a list of at least one but not more than 4096 integers"

I've tried simply changing the spidev_max_path argument (hopping it was that simple) and doing a rebuild , obviously no success. I've learned just enough python since getting the raspberry pi to survive but I cannot for the life of me follow C very well.

Anyone have any suggestions?

Thanks,
Flutie98
Posts: 2
Joined: Thu Mar 14, 2013 2:32 am
by notro » Thu Mar 14, 2013 11:33 am
spidev is a limiting factor here. By default it allocates a 4096 bytes buffer.
But it's easy to change:
Code: Select all
# modinfo spidev
[snip]
parm:           bufsiz:data bytes in biggest supported SPI message (uint)

# rmmod spidev
# modprobe spidev bufsiz=65536

# cat /sys/module/spidev/parameters/bufsiz
65536

To make it permanent, create a file /etc/modprobe.d/spidev.conf with contents
Code: Select all
options spidev bufsiz=65536

SPI Controller driver: spi_bcm2708
Here is another limiting factor. An unfinished SPI transfer throws a timeout after 150 ms.
How much you can push in one transfer depends on the bus speed. A SPI message can contain several transfers.
I have hit this ceiling myself, but I don't remember the details.
Source: https://github.com/raspberrypi/linux/bl ... 2708.c#L73

drivers/spi/spidev.c
Default bufsize is set here: https://github.com/raspberrypi/linux/bl ... idev.c#L91
The buffer is allocated in spidev_open(): https://github.com/raspberrypi/linux/bl ... dev.c#L500
Posts: 512
Joined: Tue Oct 16, 2012 6:21 pm
Location: Norway
by flutie98 » Thu Mar 14, 2013 10:24 pm
This worked perfectly! Thank you very much.

This was for a rather strange project. Im using several MCP23S17 16bit GPIO expanders (SPI 10MHz) and was making some code to be able to bit bang multiple serial bus off the GPIO expanders to feed several LCD displays. Now with the large burst SPI transfers working Ive gotten my screens up to 30Hz!

Thanks again,
Flutie98
Posts: 2
Joined: Thu Mar 14, 2013 2:32 am
by sparkinson » Thu Jan 23, 2014 12:59 am
I am trying to apply this fix but get some odd results

Code: Select all
# modinfo spidev
ERROR: Module spidev not found.

# rmmod spidev
libkmod: ERROR ../libkmod/libkmod-module.c:1802 kmod_module_get_holders: could not open '/sys/module/spidev/holders': No such file or directory
Error: Module spidev is in use

# modprobe spidev bufsiz=65536

# cat /sys/module/spidev/parameters/bufsiz
4096


I have also created a file /etc/modprobe.d/spidev.conf with contents
Code: Select all
options spidev bufsiz=65536

and rebooted.

still...
Code: Select all
# cat /sys/module/spidev/parameters/bufsiz
4096


Am I missing something??

Thanks for any help
Posts: 2
Joined: Thu Jan 23, 2014 12:52 am
by kabla » Fri Feb 14, 2014 3:21 pm
sparkinson, did you get it working? Does someone else know what could be causing this? I'm having the exact same problem.

Edit: I should say that I've commented out spi in /etc/modprobe.d/raspi-blacklist.conf and SPI is working properly. I just can't change the buffer size.

I've tried loading spidev using "modprobe spidev". I'm (also) getting the following error, which probably is related to the problem?

Code: Select all
# modinfo spidev
ERROR: Module spidev not found.
Last edited by kabla on Fri Feb 14, 2014 5:12 pm, edited 1 time in total.
Posts: 3
Joined: Fri Feb 14, 2014 3:17 pm
by sparkinson » Fri Feb 14, 2014 4:59 pm
No I still have this issue.
Posts: 2
Joined: Thu Jan 23, 2014 12:52 am
by kabla » Sat Feb 15, 2014 8:52 am
Well, this worked for us:

  • Go to: /sys/module/spidev/parameters
  • You'll find a file called "bufsiz", make sure you have read/write-permissions to it.
  • Change the value in the file from 4096 to whatever you want.
Posts: 3
Joined: Fri Feb 14, 2014 3:17 pm