Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: letaage on October 03, 2013, 05:52:31 AM

Title: SPI and lirc_rpi kernel drivers
Post by: letaage on October 03, 2013, 05:52:31 AM
I'm trying to get a couple of drivers working under piCore Linux. 

I've previously got them working under Raspbian, but I'm keen to use piCore because of the fast boot time and other factors.

I've started with the piCorePlayer distribution because ultimately I want to end up with what piCorePlayer does, with a couple of other features/packages tacked on, namely lcdproc and lirc to turn my Raspberry Pi into a basic Squeezebox replacement.

Previously I've got the I2C and SPI interfaces working and I've written a SPI device driver for lcdproc for the VFD I want to use as a display and it worked just fine under Raspbian.

So I've followed much the same method and I've got the I2C interface working correctly under piCore but I'm having problems with the SPI interface.

lsmod shows that the SPI kernel drivers are loaded:

Code: [Select]
tc@box:~$ lsmod
Module                  Size  Used by    Not tainted
spidev                  5669  0
i2c_dev                 5623  0
snd_bcm2835            16165  0
snd_usb_audio         112768  0
snd_usbmidi_lib        18259  1 snd_usb_audio
snd_rawmidi            21199  1 snd_usbmidi_lib
snd_seq_device          6437  1 snd_rawmidi
snd_pcm                80315  2 snd_bcm2835,snd_usb_audio
snd_page_alloc          5148  1 snd_pcm
snd_timer              20001  1 snd_pcm
snd_hwdep               5932  1 snd_usb_audio
snd                    58518  8 snd_bcm2835,snd_usb_audio,snd_usbmidi_lib,snd_rawmidi,snd_seq_device,snd_pcm,snd_timer,snd_hwdep
squashfs               23590 71
loop                   16102 142
evdev                   9305  0
i2c_bcm2708             3941  0
spi_bcm2708             4738  0

But no SPI devices (as far as I can tell) are appearing in /dev.  I'm used to seeing something like "/dev/spidev0.0" but there's nothing remotely like it in /dev (I'll spare you the listing at this point in time but can provide it if required).

Any ideas why I'm not seeing the SPI devices?

Also I want to add an IR remote receiver to my set up using lirc and a IR receiver connected to a GPIO pin as described at the following pages:  http://aron.ws/projects/lirc_rpi/ (http://aron.ws/projects/lirc_rpi/) and http://wiki.openelec.tv/index.php?title=Guide_To_lirc_rpi_GPIO_Receiver (http://wiki.openelec.tv/index.php?title=Guide_To_lirc_rpi_GPIO_Receiver).

I quickly discovered that the lirc_rpi kernel module isn't in the distribution, I'm very new to Tiny Core Linux and find the Wiki hard to follow, can someone point me towards instructions on how I might compile the kernel and/or driver modules for TCL myself?

Finally, I'm having trouble working out which extensions are available for piCore and not everything seems to exist right now.  Is there an easy way to find out?

Thanks in advance!!

Tom
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 03, 2013, 06:40:21 AM
Tom

welcome on board. Which piCore version are you working with, 4.7.7, 5.0alpha1/2 or alpha3?

Bela
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 03, 2013, 06:54:21 AM
I'm using the piCorePlayer distribution, which I believe is Core 4.7.5.

Would I be better off starting with a newer version?  If so, can I upgrade?
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 03, 2013, 07:34:40 AM
I do not know piCorePlayer. I would suggest to test SPI/I2C on the latest 5.0alpha3 separately and when it works, player part can be added.

To reduce size less frequently used kernel modules are not in the base. I will add IRC modules for 5.0alapha3 to the repo shortly.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 03, 2013, 08:23:09 AM
Install rc-3.11.1-piCore.tcz from the repo to have rc kernel modules. Please note is for 5.0alpha3, not suitable for other piCore versions due to different kernel.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: sbp on October 03, 2013, 03:01:25 PM
Hi letaage

Nice to see you here also.
I think that you should try to get it working on piCore version 5 (currently alpha3).
I'm building the new version of piCorePlayer on this as well, the only thing that is missing right now is a working wifi.

Then it should be easy for you to port your stuff to piCorePlayer when they both are build on the same version of microcore (=piCore)

Please report if I can help in any way.

Steen
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 03, 2013, 10:38:31 PM
Thanks for your fast responses and helpful advice, I'll will try from scratch with version 5 over the weekend (if I get the chance) and report back.

As I said, I've previously got a display working over SPI using lcdProc and a IR interface working using GPIO and lirc under Raspbian so I don't expect too many problems once I get the drivers sorted out and I'm more familiar with the piCore way of doing things.

Famous last words!
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 07, 2013, 10:01:53 AM
So I've had some time to try and get SPI working on fresh installation of piCore 5.0alpha4, but have run into the same problem I had before, that is the SPI kernel modules appear to be present and loaded but there are no SPI devices being created in /dev.

The i2c driver modules are loading correctly and appear as /dev/i2c-0 and /dev/i2c-1 but the SPI driver isn't playing ball

Here's the output from lsmod:

Code: [Select]
tc@box:~$ lsmod
Module                  Size  Used by    Not tainted
i2c_dev                 5659  0
spidev                  5677  0
squashfs               28699 45
spi_bcm2708             4779  0
i2c_bcm2708             3949  0

Both the spi_bcm2708 and spidev drivers are present and loaded, as are the i2c driver modules, so I am expecting to see /dev/spidev0.0 and /dev/spidev0.1 like I see the i2c devices but the SPI devices are not there.

Code: [Select]
tc@box:~$ ls /dev/i2c*
/dev/i2c-0  /dev/i2c-1
tc@box:~$ ls /dev/spi*
ls: /dev/spi*: No such file or directory
tc@box:~$

I've tried to understand what's stopping the SPI devices from working, and the best I can come up with is that the devices in /dev haven't been created using something like mknod or MAKEDEV or udev - but just how I'm not sure!

I'm confused as to what to do to create the device files, from what I've read MAKEDEV should do it automagically but isn't installed (and I can't locate it in other extensions).  mknod seems like it should do the trick manually, but other messages in the TCL forums suggest that I should be using udev to create devices but aren't much help beyond that.

I've searched for hints on how to get SPI working and came across some information here http://www.brianhensley.net/2012/02/python-controlling-spi-bus-on.html (http://www.brianhensley.net/2012/02/python-controlling-spi-bus-on.html) that lead me here https://www.kernel.org/doc/Documentation/spi/spidev (https://www.kernel.org/doc/Documentation/spi/spidev) which suggests that managing the /dev character device by hand is a bad idea, I should be using udev or mdev (which isn't part of busy box in this release)

I've tried to look into how to use udev, which is installed, but I was lost in the detail pretty quickly.

So I've attempted to create the device files manually, but it doesn't seem to have worked.  I've looked up the SPI driver major number (153) in the Raspberry Pi kernel source and in the kernel source file /Documentation/devices.txt and it's a character device, so I tried:

Code: [Select]
tc@box:~/vfd$ sudo mknod /dev/spidev0.0 c 153 0
This creates the device /dev/spidev0.0 but it doesn't work when I try and open the device:
Code: [Select]
tc@box:~/vfd$ sudo ./spidev_test
can't open device: No such device or address
Aborted

And for completeness, spidev_test.c contains the following lines:

Code: [Select]
static const char *device = "/dev/spidev0.0";
....
fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");

The spidev_test.c code has worked for me previously on Raspbian. 

Any ideas what to try next?
Title: Re: SPI and lirc_rpi kernel drivers
Post by: gpulido on October 22, 2013, 05:52:54 PM
Hello,
I would like to control led lights using a python script that uses SPI and I2C.
The program already works on raspbian.
I realized that the i2c module is already ported and is available through the  ic2-tools package.
How can I get the SPI module working?

Thank you very much in advance
Best regards
Gabriel
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 23, 2013, 03:40:24 AM

How can I get the SPI module working?


Do you mean Kernel SPI modules? They are in the base

Code: [Select]
sudo modprobe spidev.ko
will activate it.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 23, 2013, 05:46:55 AM
I've tried to get the SPI interface working, but still can't get the SPI device to appear in /dev

I just downloaded piCore 5.0alpha5 and ran "sudo modprobe spidev.ko" and I still don't get anything that looks like a SPI device in SPI dev.  In Raspbian you see /dev/spidev0.0 and /dev/spidev0.1 but no new devices appear in /dev in the latest (and previous versions) of piCore linux.

Running "lsmod" shows that both spidev and spi_bcm2700 are loaded so why the devices don't show up in /dev remains a mystery.

bmarkus, can you run "sudo mod probe spidev.ko" and tell me if you see any SPI devices or not in your set up?

I have spent some time trying to compile my own kernel under piCore5.0alpha4 (cross compiling on OS X) to try and fix this problem.  I think I managed to compile a kernel but I think I messed up the repackaging of the kernel and modules etc for Tiny Core Linux.  The new kernel booted but froze after 3 lines of output, and I haven't had time to try and work out why.

I find the tutorials in the Wiki on the kernel building and repackaging process for the Raspberry Pi (and others tutorials) hard to follow and very x86 centric.  This would put off a lot of people from using piCore.  Lots of reading between the lines and translating from x86 world to Raspberry Pi world is required on top of the differences between rolling your own kernel in a regular distribution and doing things the Tiny Core way. 

But I have been documenting the process so that I can post it as a (hopefully) comprehensive guide for others once I've worked out how to do it.

However, just looking over at the Raspberry Pi forums right now, it seems that I'm not the only one having trouble getting the SPI module to work, it seems to be broken in the latest source and needs to be compiled into the kernel to work :

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=57516 (http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=57516)

Bummer.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 23, 2013, 05:55:09 AM
Hi

can you try it with the previous 4.7.x release?

Bela
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 23, 2013, 06:41:12 AM
I just downloaded tried 4.7.5 (linked from the download page) and the SPI devices are there in /dev, both spidev0.0 and spidev0.1 are present,  they are even enabled by default!

The I2C devices are also there but not enabled by default.

I can confirm that the I2C interface works (using i2c-tools.tcz) under the 4.7.5 release, I have to download a lot of extensions before I can test the SPI interface - I'll report back when I have tested.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 23, 2013, 06:52:00 AM
I can confirm that the SPI interface works under release 4.7.5

So there must be a bug in the new kernel source?

What are the major differences between 4.7.5 and the 5.0.x releases?

More specifically for what I want to do, is there support for the lirc GPIO kernel module in the 4.7.5 release?
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 23, 2013, 03:58:07 PM

What are the major differences between 4.7.5 and the 5.0.x releases?


There are many

- kernel is updated to 3.11.x
- eglibc updated
- BusyBox updated
- apps not provided by BusyBox updated
- TC scripts updated to common TC 5.0.x base


More specifically for what I want to do, is there support for the lirc GPIO kernel module in the 4.7.5 release?


No plane for 4.7.5, focus is on 5.0

The good news is, that I have SPI working (at least /dev/spidev0.0 and /dev/spidev0.1 is there, not tested with real hardware yet) in piCore5.0alpha6 with 3.11.6 kernel. It will be available for testing shortly.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 24, 2013, 02:57:02 AM
I'm willing to test the I2C and SPI drivers when piCore5.0alpha6 is ready!
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 24, 2013, 03:00:02 AM
I'm willing to test the I2C and SPI drivers when piCore5.0alpha6 is ready!

It is:

http://forum.tinycorelinux.net/index.php/topic,16110.0.html
Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 24, 2013, 07:02:28 AM
Thanks, I missed that it was now available.

I'll post comment about testing piCore5.0alpha6 in the thread in piCore News....

Title: Re: SPI and lirc_rpi kernel drivers
Post by: letaage on October 25, 2013, 07:41:58 PM
For anyone following this thread I can report that the SPI interface works in piCore5.0alpha6.

It appears to be compiled into the kernel in the latest release, not a module, but it is now working.

Next things to test on my Pi are the GPIO IR driver running under lirc and porting over my SPI VDF driver for lcdproc.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 26, 2013, 02:26:23 AM
Thanks for reporting it works. Yes, it was necessary to build into the kernel.
Title: Re: SPI and lirc_rpi kernel drivers
Post by: gpulido on October 27, 2013, 02:01:37 PM
Hello,
 are avaliable the ic2-tools for the 5.x version of tinycore?
I can't find it on the tcz repos

Gabriel
Title: Re: SPI and lirc_rpi kernel drivers
Post by: bmarkus on October 27, 2013, 06:28:30 PM
Hello,
 are avaliable the ic2-tools for the 5.x version of tinycore?
I can't find it on the tcz repos

Gabriel

i2c-tools is in the repo