Setup SPI

This topic provides details on how to setup the SPI Service.

To be able to use the SPI Service, you need to install the spidev and spisvc modules on the target.

Verify if spidev isn't already in the /dev directory:

root@swi-mdm9x15:~# ls /dev/spi*
ls: /dev/spi*: No such file or directory

Then verify the spidev and spisvc modules aren't already installed, like this:

root@swi-mdm9x15:~# lsmod
Not tainted
ipv6 287772 14 [permanent], Live 0xbf076000
msm_sdcc 61674 0 - Live 0xbf060000
usb_storage 41205 0 - Live 0xbf04c000
sd_mod 29459 0 - Live 0xbf03f000
scsi_mod 131955 2 usb_storage,sd_mod, Live 0xbf00d000
unix 28948 625 - Live 0xbf000000

Install spidev:

root@swi-mdm9x15:~/ktest_dir# modprobe spidev

Check spidev is now listed:

root@swi-mdm9x15:~/ktest_dir# lsmod
Not tainted
spidev 6060 0 - Live 0xbf0d2000
ipv6 287772 14 [permanent], Live 0xbf076000
msm_sdcc 61674 0 - Live 0xbf060000
usb_storage 41205 0 - Live 0xbf04c000
sd_mod 29459 0 - Live 0xbf03f000
scsi_mod 131955 2 usb_storage,sd_mod, Live 0xbf00d000
unix 28948 625 - Live 0xbf000000

Next, you'll need to create a kernel module .ko file. Follow the instructions in Out of Tree Kernel Module topic howToAddKernelDriver_makeKernel. Your .ko file should use the code in the files located in legato/drivers/spisvc: Makefile, spisvc.c, and spisvc.mdef. Use scp to copy your kernel module (driver) onto the target like this:

scp ktest_module.ko root@$target_IP:/home/root/ktest_dir

After you've copied your kernel module .ko file, install it like this:

root@swi-mdm9x15:~/ktest_dir# insmod spisvc.ko

Check spisvc is installed:

root@swi-mdm9x15:~/ktest_dir# lsmod
Tainted: G
spisvc 694 0 - Live 0xbf0d7000 (O)
spidev 6060 0 - Live 0xbf0d2000
ipv6 287772 14 [permanent], Live 0xbf076000
msm_sdcc 61674 0 - Live 0xbf060000
usb_storage 41205 0 - Live 0xbf04c000
sd_mod 29459 0 - Live 0xbf03f000
scsi_mod 131955 2 usb_storage,sd_mod, Live 0xbf00d000
unix 28948 625 - Live 0xbf000000

Check the target to ensure spidev0.0 now exists:

root@swi-mdm9x15:~/ktest_dir# ls /dev/*spi*
/dev/spidev0.0

Start the spisvc:

root@swi-mdm9x15:~/ktest_dir# app start spisvc