hypriot / rpi-kernel

Build a Linux kernel for Raspberry Pi 0/1/2/3/3B+
MIT License
134 stars 46 forks source link

SPI inside Docker Container #24

Closed ThomasSchemmer closed 8 years ago

ThomasSchemmer commented 8 years ago

Hello, first of , thanks for making my life easier. Now I'm afraid I'll have to make yours a tad harder. :( I'm currently trying to enable SPI on my Raspberry Pi 2 B inside a Docker container.(edit: using HypriotOS 0.8) In the end, I want to be able to communicate with a nrf24l01 wireless module via the RF24 lib.

For the image creation im following the tutorial here and adapted the run command to the following docker run --cap-add ALL -v /lib/modules:/lib/modules -v /sys:/sys --device /dev/ttyAMA0:/dev/ttyAMA0 --device /dev/mem:/dev/mem --privileged -ti tschemmer/sensor bash as Jerome states that it should enable modprobe within a container. I even added the --cap-add ALL for good measure ;)

The container starts up fine, sudo modprobe spi-bcm2835 works without error and lsmod returns the appropriate values:

root@24a1bfc0fab5:~/docker/test# lsmod
Module                  Size  Used by
...
uio                     8480  1 uio_pdrv_genirq
i2c_dev                 6372  0
spi_bcm2835             7412  0
snd_bcm2835            20243  0
snd_pcm                76775  1 snd_bcm2835
...

But when I checked the /dev directory, the spidev0.0 isnt there. So i tried to do it in the OS directly, outside of any container, according to Issue 13. Even added spi-bcm2835 to /etc/modules and restarted. The spi is still not in the /dev directory, so trying the loopback test does not work for me. Now my question is: what do I have to do to get that /dev/spidev0.0 up and running? I feel like im missing something :/ On raspbian i would be able to use raspi-config, is there somehting similar here? Thanks for your help Thomas

DieterReuter commented 8 years ago

To enable SPI, you also need to add “dtparam=spi=on” to your /boot/config.txt and reboot. I've successfully used SPI within a container on the HypriotOS 0.7 release (but not tested it on 0.8 yet).

ThomasSchemmer commented 8 years ago

Thank you, that worked perfectly :+1: might i ask where you found the reference?

DieterReuter commented 8 years ago

Just googled for raspberrypi spi enable and the first hit http://raspi.tv/how-to-enable-spi-on-the-raspberry-pi had all the details. Then double-checked what raspi-config does internally to confirm the solution.

ThomasSchemmer commented 8 years ago

Darn, i found the link before, just didnt completely read it. Thx again, closing the issue now.