msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

registration of SPI-devices without recompiling the kernel

Wed Oct 02, 2013 4:12 pm

Hi!

I have just published an initial version of a new kernel module "spi-config" that allows you to configure devices of your choice on the SPI bus.

For example - configuring the CAN Bus for PYCAN could look like this (assuming Raspien would provide an updated kernel with the module compiled in):

Code: Select all

modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=140024f4000220
This would configure a mcp2515 on SPI0.0 with a max SPI-bus speed of 10MHz and the interrupt on GPIO25. It also configures the MCP2515 to have a clock of 16MHz.

You can change mcp2515 for any other module of your choice.

Code: Select all

modprobe spi-config devices=bus=0:cs=1:modalias=spidev:speed=4000000
and you add on spi0.1 SPIDEV at a max speed of 4MBit.

or

Code: Select all

modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=140024f4000220,bus=0:cs=1:modalias=enc28j60:speed=16000000:gpioirq=22
to get the Ethernet controller on SPI0.1 to work with GPIO22 as interrupt plus on SPI0.0 you get the CAN controller...

For the code please see: https://github.com/msperl/spi-config

Hopefully this gets integrated with the Raspian linux kernel (posted an issue here: https://github.com/raspberrypi/linux/issues/391 to get it started). Then most of our lives may be easier without the need to compile our personal SPI-kernels...

Please review it and if it helps your work, then please ask nicely to get it included in the Raspian kernel - the more people ask for it the quicker we will get a solution...

Thanks,
Martin

msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

Re: registration of SPI-devices without recompiling the kern

Sun Oct 06, 2013 4:05 pm

Should now also compile for 3.6.y kernels - also tested with 3.6.11+

Please give it some testing and feedback!

sam nazarko
Posts: 152
Joined: Wed Apr 25, 2012 5:05 pm

Re: registration of SPI-devices without recompiling the kern

Sun Oct 06, 2013 6:48 pm

@msperl: are you having success with SPI on 3.10.x? I am not: please see http://www.raspberrypi.org/phpBB3/viewt ... 44&t=57516

msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

Re: registration of SPI-devices without recompiling the kern

Wed Oct 09, 2013 7:54 pm

Found a bug with spi-config, that can result in a crash when unloading the module, if the spi-bcm2708 driver has been removed first...

The new version on GitHub fixes this issue and tries to be more diligent avoiding such a situation - it will only remove a device it has assigned and only if it has not been changed since...

So beware...

Martin

msperl
Posts: 344
Joined: Thu Sep 20, 2012 3:40 pm

Re: registration of SPI-devices without recompiling the kern

Wed Oct 09, 2013 7:55 pm

I have no issues either with 3.10 or 3.11.

My typical cases work as usual...

Return to “Interfacing (DSI, CSI, I2C, etc.)”