WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: SPI and lirc_rpi kernel drivers  (Read 11648 times)

Offline letaage

  • Newbie
  • *
  • Posts: 12
SPI and lirc_rpi kernel drivers
« on: October 03, 2013, 02: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/ and 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

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #1 on: October 03, 2013, 03:40:21 AM »
Tom

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

Bela
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #2 on: October 03, 2013, 03: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?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #3 on: October 03, 2013, 04: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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #4 on: October 03, 2013, 05: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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline sbp

  • Sr. Member
  • ****
  • Posts: 429
    • piCorePlayer homepage
Re: SPI and lirc_rpi kernel drivers
« Reply #5 on: October 03, 2013, 12: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

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #6 on: October 03, 2013, 07: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!

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #7 on: October 07, 2013, 07: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 that lead me here 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?
« Last Edit: October 07, 2013, 07:08:50 AM by letaage »

Offline gpulido

  • Jr. Member
  • **
  • Posts: 57
Re: SPI and lirc_rpi kernel drivers
« Reply #8 on: October 22, 2013, 02: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

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #9 on: October 23, 2013, 12: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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #10 on: October 23, 2013, 02: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

Bummer.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #11 on: October 23, 2013, 02:55:09 AM »
Hi

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

Bela
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #12 on: October 23, 2013, 03: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.
« Last Edit: October 23, 2013, 02:33:05 PM by letaage »

Offline letaage

  • Newbie
  • *
  • Posts: 12
Re: SPI and lirc_rpi kernel drivers
« Reply #13 on: October 23, 2013, 03: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?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: SPI and lirc_rpi kernel drivers
« Reply #14 on: October 23, 2013, 12: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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."