# SPI on mangOH Green

**URL:** <https://mangoh.discourse.group/t/spi-on-mangoh-green/228>\
**Category:** mangOH Green\
**Created:** [September 20, 2016, 12:55am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228 "2016-09-20T00:55:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [September 20, 2016, 12:55am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/1 "2016-09-20T00:55:42Z")

</div>

Hi,

I have a few questions regarding SPI on mangOH.

1. SPI2:  
Figure 2-13 on page 26 of the Developer’s Guide shows IoT#2 having a direct connection to SPI1. Is this true?  
I checked the schematic and it would seem that the SPI lines on IoT#2 are connected to pins 92, 93, 94, 95 on the CF3 socket, which are not dedicated SPI pins on the WP8548 module. Does SPI2 work? or is it intended to be used with different CF3 modules?

2. SPI (in general)  
I’m trying to use SPI in user space (for the moment), but I cannot find the platform device at /dev/spidev\_B\_._C_  
There’s /dev/sierra\_spi but I get an error (Inappropriate ioctl for device) when trying to set the mode via ioctl.  
Is it instead mapped to some ‘tty#’ device?

_Device: WP8548_  
_Firmware: SWI9X15Y\_07.11.09.00 r32989 CARMD-EV-FRMWR1 2016/08/11 18:03:20_  
_Legato version: 16.07.0\_cd4985660a55cc9a6f9a2ed28bcc757e\_modified_

Can anybody help me get the SPI device to show up in /dev/?  
Are there any mangOH SPI examples I can follow? I couldn’t find one in the sample apps…a very short basic example on how to use each peripheral on the development platform would be most helpful.

Here’s my output after running modprobe -l if that helps

root@swi-mdm9x15:~# modprobe -l  
kernel/fs/quota/quota\_v1.ko  
kernel/fs/quota/quota\_v2.ko  
kernel/fs/quota/quota\_tree.ko  
kernel/fs/nls/nls\_cp737.ko  
kernel/fs/nls/nls\_cp775.ko  
kernel/fs/nls/nls\_cp850.ko  
kernel/fs/nls/nls\_cp852.ko  
kernel/fs/nls/nls\_cp855.ko  
kernel/fs/nls/nls\_cp857.ko  
kernel/fs/nls/nls\_cp860.ko  
kernel/fs/nls/nls\_cp861.ko  
kernel/fs/nls/nls\_cp862.ko  
kernel/fs/nls/nls\_cp863.ko  
kernel/fs/nls/nls\_cp864.ko  
kernel/fs/nls/nls\_cp865.ko  
kernel/fs/nls/nls\_cp866.ko  
kernel/fs/nls/nls\_cp869.ko  
kernel/fs/nls/nls\_cp874.ko  
kernel/fs/nls/nls\_cp932.ko  
kernel/fs/nls/nls\_euc-jp.ko  
kernel/fs/nls/nls\_cp936.ko  
kernel/fs/nls/nls\_cp949.ko  
kernel/fs/nls/nls\_cp950.ko  
kernel/fs/nls/nls\_cp1250.ko  
kernel/fs/nls/nls\_cp1251.ko  
kernel/fs/nls/nls\_iso8859-2.ko  
kernel/fs/nls/nls\_iso8859-3.ko  
kernel/fs/nls/nls\_iso8859-4.ko  
kernel/fs/nls/nls\_iso8859-5.ko  
kernel/fs/nls/nls\_iso8859-6.ko  
kernel/fs/nls/nls\_iso8859-7.ko  
kernel/fs/nls/nls\_cp1255.ko  
kernel/fs/nls/nls\_iso8859-9.ko  
kernel/fs/nls/nls\_iso8859-13.ko  
kernel/fs/nls/nls\_iso8859-14.ko  
kernel/fs/nls/nls\_koi8-r.ko  
kernel/fs/nls/nls\_koi8-u.ko  
kernel/fs/nls/nls\_koi8-ru.ko  
kernel/fs/binfmt\_misc.ko  
kernel/fs/reiserfs/reiserfs.ko  
kernel/fs/minix/minix.ko  
kernel/fs/nfs/nfs.ko  
kernel/fs/nfs/nfsv2.ko  
kernel/fs/nfs/nfsv3.ko  
kernel/fs/nfs/nfsv4.ko  
kernel/fs/lockd/lockd.ko  
kernel/fs/cifs/cifs.ko  
kernel/fs/romfs/romfs.ko  
kernel/fs/autofs4/autofs4.ko  
kernel/fs/fuse/fuse.ko  
kernel/fs/fuse/cuse.ko  
kernel/crypto/cmac.ko  
kernel/crypto/xcbc.ko  
kernel/crypto/crypto\_null.ko  
kernel/crypto/md4.ko  
kernel/crypto/sha256\_generic.ko  
kernel/crypto/sha512\_generic.ko  
kernel/crypto/wp512.ko  
kernel/crypto/blowfish\_generic.ko  
kernel/crypto/blowfish\_common.ko  
kernel/crypto/twofish\_generic.ko  
kernel/crypto/twofish\_common.ko  
kernel/crypto/serpent\_generic.ko  
kernel/crypto/camellia\_generic.ko  
kernel/crypto/cast\_common.ko  
kernel/crypto/cast5\_generic.ko  
kernel/crypto/cast6\_generic.ko  
kernel/crypto/tea.ko  
kernel/crypto/khazad.ko  
kernel/crypto/anubis.ko  
kernel/crypto/ansi\_cprng.ko  
kernel/crypto/tcrypt.ko  
kernel/drivers/block/loop.ko  
kernel/drivers/block/nbd.ko  
kernel/drivers/block/cryptoloop.ko  
kernel/drivers/net/wireless/ti/wl1251/wl1251.ko  
kernel/drivers/net/usb/r8152.ko  
kernel/drivers/net/usb/ax88179\_178a.ko  
kernel/drivers/net/bonding/bonding.ko  
kernel/drivers/net/dummy.ko  
kernel/drivers/net/tun.ko  
kernel/drivers/net/ppp/ppp\_generic.ko  
kernel/drivers/net/ppp/ppp\_async.ko  
kernel/drivers/net/ppp/bsd\_comp.ko  
kernel/drivers/net/ppp/ppp\_deflate.ko  
kernel/drivers/net/ppp/ppp\_synctty.ko  
kernel/drivers/net/ppp/pppox.ko  
kernel/drivers/net/ppp/pppoe.ko  
kernel/drivers/net/slip/slip.ko  
kernel/drivers/net/slip/slhc.ko  
kernel/drivers/usb/storage/usb-storage.ko  
kernel/drivers/usb/storage/ums-alauda.ko  
kernel/drivers/usb/storage/ums-cypress.ko  
kernel/drivers/usb/storage/ums-datafab.ko  
kernel/drivers/usb/storage/ums-freecom.ko  
kernel/drivers/usb/storage/ums-isd200.ko  
kernel/drivers/usb/storage/ums-jumpshot.ko  
kernel/drivers/usb/storage/ums-karma.ko  
kernel/drivers/usb/storage/ums-onetouch.ko  
kernel/drivers/usb/storage/ums-sddr09.ko  
kernel/drivers/usb/storage/ums-sddr55.ko  
kernel/drivers/usb/storage/ums-usbat.ko  
kernel/drivers/input/keyboard/atkbd.ko  
kernel/drivers/input/mouse/psmouse.ko  
kernel/drivers/input/mousedev.ko  
kernel/drivers/watchdog/softdog.ko  
kernel/drivers/mmc/host/msm\_sdcc.ko  
kernel/drivers/scsi/scsi\_mod.ko  
kernel/drivers/scsi/scsi\_tgt.ko  
kernel/drivers/scsi/sd\_mod.ko  
kernel/drivers/scsi/sg.ko  
kernel/drivers/input/serio/serio.ko  
kernel/drivers/input/serio/serport.ko  
kernel/drivers/input/serio/libps2.ko  
kernel/net/core/pktgen.ko  
kernel/net/802/p8022.ko  
kernel/net/802/psnap.ko  
kernel/net/802/stp.ko  
kernel/net/sched/sch\_cbq.ko  
kernel/net/sched/sch\_htb.ko  
kernel/net/sched/sch\_hfsc.ko  
kernel/net/sched/sch\_red.ko  
kernel/net/sched/sch\_gred.ko  
kernel/net/sched/sch\_ingress.ko  
kernel/net/sched/sch\_dsmark.ko  
kernel/net/sched/sch\_sfq.ko  
kernel/net/sched/sch\_tbf.ko  
kernel/net/sched/sch\_teql.ko  
kernel/net/sched/sch\_prio.ko  
kernel/net/sched/sch\_netem.ko  
kernel/net/sched/sch\_codel.ko  
kernel/net/sched/cls\_fw.ko  
kernel/net/sched/cls\_basic.ko  
kernel/net/sched/cls\_cgroup.ko  
kernel/net/netfilter/nfnetlink.ko  
kernel/net/netfilter/nfnetlink\_queue.ko  
kernel/net/netfilter/nfnetlink\_log.ko  
kernel/net/netfilter/nf\_conntrack.ko  
kernel/net/netfilter/nf\_conntrack\_proto\_gre.ko  
kernel/net/netfilter/nf\_conntrack\_proto\_sctp.ko  
kernel/net/netfilter/nf\_conntrack\_proto\_udplite.ko  
kernel/net/netfilter/nf\_conntrack\_netlink.ko  
kernel/net/netfilter/nf\_conntrack\_amanda.ko  
kernel/net/netfilter/nf\_conntrack\_ftp.ko  
kernel/net/netfilter/nf\_conntrack\_h323.ko  
kernel/net/netfilter/nf\_conntrack\_irc.ko  
kernel/net/netfilter/nf\_conntrack\_broadcast.ko  
kernel/net/netfilter/nf\_conntrack\_netbios\_ns.ko  
kernel/net/netfilter/nf\_conntrack\_pptp.ko  
kernel/net/netfilter/nf\_conntrack\_sane.ko  
kernel/net/netfilter/nf\_conntrack\_sip.ko  
kernel/net/netfilter/nf\_conntrack\_tftp.ko  
kernel/net/netfilter/nf\_nat.ko  
kernel/net/netfilter/nf\_nat\_proto\_udplite.ko  
kernel/net/netfilter/nf\_nat\_proto\_sctp.ko  
kernel/net/netfilter/nf\_nat\_amanda.ko  
kernel/net/netfilter/nf\_nat\_ftp.ko  
kernel/net/netfilter/nf\_nat\_irc.ko  
kernel/net/netfilter/nf\_nat\_sip.ko  
kernel/net/netfilter/nf\_nat\_tftp.ko  
kernel/net/netfilter/x\_tables.ko  
kernel/net/netfilter/xt\_tcpudp.ko  
kernel/net/netfilter/xt\_mark.ko  
kernel/net/netfilter/xt\_connmark.ko  
kernel/net/netfilter/xt\_nat.ko  
kernel/net/netfilter/xt\_CLASSIFY.ko  
kernel/net/netfilter/xt\_CT.ko  
kernel/net/netfilter/xt\_DSCP.ko  
kernel/net/netfilter/xt\_HL.ko  
kernel/net/netfilter/xt\_NETMAP.ko  
kernel/net/netfilter/xt\_NFLOG.ko  
kernel/net/netfilter/xt\_NFQUEUE.ko  
kernel/net/netfilter/xt\_REDIRECT.ko  
kernel/net/netfilter/xt\_TCPMSS.ko  
kernel/net/netfilter/xt\_TRACE.ko  
kernel/net/netfilter/xt\_comment.ko  
kernel/net/netfilter/xt\_connbytes.ko  
kernel/net/netfilter/xt\_connlimit.ko  
kernel/net/netfilter/xt\_conntrack.ko  
kernel/net/netfilter/xt\_dccp.ko  
kernel/net/netfilter/xt\_dscp.ko  
kernel/net/netfilter/xt\_ecn.ko  
kernel/net/netfilter/xt\_esp.ko  
kernel/net/netfilter/xt\_hashlimit.ko  
kernel/net/netfilter/xt\_helper.ko  
kernel/net/netfilter/xt\_hl.ko  
kernel/net/netfilter/xt\_length.ko  
kernel/net/netfilter/xt\_limit.ko  
kernel/net/netfilter/xt\_mac.ko  
kernel/net/netfilter/xt\_multiport.ko  
kernel/net/netfilter/xt\_cgroup.ko  
kernel/net/netfilter/xt\_pkttype.ko  
kernel/net/netfilter/xt\_policy.ko  
kernel/net/netfilter/xt\_quota.ko  
kernel/net/netfilter/xt\_realm.ko  
kernel/net/netfilter/xt\_sctp.ko  
kernel/net/netfilter/xt\_state.ko  
kernel/net/netfilter/xt\_statistic.ko  
kernel/net/netfilter/xt\_string.ko  
kernel/net/netfilter/xt\_tcpmss.ko  
kernel/net/netfilter/xt\_u32.ko  
kernel/net/netfilter/ipset/ip\_set.ko  
kernel/net/ipv4/netfilter/nf\_conntrack\_ipv4.ko  
kernel/net/ipv4/netfilter/nf\_nat\_ipv4.ko  
kernel/net/ipv4/netfilter/nf\_defrag\_ipv4.ko  
kernel/net/ipv4/netfilter/nf\_nat\_h323.ko  
kernel/net/ipv4/netfilter/nf\_nat\_pptp.ko  
kernel/net/ipv4/netfilter/nf\_nat\_proto\_gre.ko  
kernel/net/ipv4/netfilter/ip\_tables.ko  
kernel/net/ipv4/netfilter/iptable\_filter.ko  
kernel/net/ipv4/netfilter/iptable\_mangle.ko  
kernel/net/ipv4/netfilter/iptable\_nat.ko  
kernel/net/ipv4/netfilter/iptable\_raw.ko  
kernel/net/ipv4/netfilter/ipt\_ah.ko  
kernel/net/ipv4/netfilter/ipt\_CLUSTERIP.ko  
kernel/net/ipv4/netfilter/ipt\_ECN.ko  
kernel/net/ipv4/netfilter/ipt\_MASQUERADE.ko  
kernel/net/ipv4/netfilter/ipt\_REJECT.ko  
kernel/net/ipv4/netfilter/ipt\_ULOG.ko  
kernel/net/ipv4/netfilter/arp\_tables.ko  
kernel/net/ipv4/netfilter/arpt\_mangle.ko  
kernel/net/ipv4/netfilter/arptable\_filter.ko  
kernel/net/ipv4/ip\_tunnel.ko  
kernel/net/ipv4/ipip.ko  
kernel/net/ipv4/ah4.ko  
kernel/net/ipv4/esp4.ko  
kernel/net/ipv4/ipcomp.ko  
kernel/net/ipv4/xfrm4\_tunnel.ko  
kernel/net/ipv4/xfrm4\_mode\_beet.ko  
kernel/net/ipv4/inet\_lro.ko  
kernel/net/ipv4/tunnel4.ko  
kernel/net/ipv4/xfrm4\_mode\_transport.ko  
kernel/net/ipv4/xfrm4\_mode\_tunnel.ko  
kernel/net/ipv4/inet\_diag.ko  
kernel/net/ipv4/tcp\_diag.ko  
kernel/net/xfrm/xfrm\_algo.ko  
kernel/net/xfrm/xfrm\_user.ko  
kernel/net/xfrm/xfrm\_ipcomp.ko  
kernel/net/ipv6/netfilter/ip6\_tables.ko  
kernel/net/ipv6/netfilter/ip6table\_filter.ko  
kernel/net/ipv6/netfilter/ip6table\_mangle.ko  
kernel/net/ipv6/netfilter/ip6table\_raw.ko  
kernel/net/ipv6/netfilter/ip6t\_eui64.ko  
kernel/net/ipv6/netfilter/ip6t\_frag.ko  
kernel/net/ipv6/netfilter/ip6t\_ipv6header.ko  
kernel/net/ipv6/netfilter/ip6t\_hbh.ko  
kernel/net/ipv6/netfilter/ip6t\_rt.ko  
kernel/net/ipv6/ipv6.ko  
kernel/net/ipv6/ah6.ko  
kernel/net/ipv6/esp6.ko  
kernel/net/ipv6/ipcomp6.ko  
kernel/net/ipv6/xfrm6\_tunnel.ko  
kernel/net/ipv6/tunnel6.ko  
kernel/net/ipv6/xfrm6\_mode\_transport.ko  
kernel/net/ipv6/xfrm6\_mode\_tunnel.ko  
kernel/net/ipv6/xfrm6\_mode\_beet.ko  
kernel/net/ipv6/sit.ko  
kernel/net/ipv6/ip6\_tunnel.ko  
kernel/net/8021q/8021q.ko  
kernel/net/llc/llc.ko  
kernel/net/unix/unix.ko  
kernel/net/key/af\_key.ko  
kernel/net/bridge/bridge.ko  
kernel/net/sunrpc/sunrpc.ko  
kernel/net/sunrpc/auth\_gss/auth\_rpcgss.ko  
kernel/net/sctp/sctp.ko  
kernel/net/tipc/tipc.ko  
kernel/net/dns\_resolver/dns\_resolver.ko  
kernel/lib/ts\_kmp.ko  
kernel/lib/ts\_bm.ko  
kernel/lib/ts\_fsm.ko  
kernel/lib/oid\_registry.ko  
kernel/lttng-modules/probes/lttng-probe-sock.ko  
kernel/lttng-modules/probes/lttng-probe-asoc.ko  
kernel/lttng-modules/lttng-ring-buffer-metadata-client.ko  
kernel/lttng-modules/probes/lttng-probe-printk.ko  
updates/drivers/net/wireless/ti/wlcore/wlcore\_sdio.ko  
kernel/lttng-modules/probes/lttng-probe-napi.ko  
kernel/lttng-modules/lttng-statedump.ko  
kernel/lttng-modules/lttng-ring-buffer-client-mmap-discard.ko  
kernel/lttng-modules/probes/lttng-probe-kmem.ko  
kernel/lttng-modules/probes/lttng-probe-compaction.ko  
updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko  
kernel/lttng-modules/lttng-ring-buffer-client-overwrite.ko  
kernel/lttng-modules/lttng-ring-buffer-client-mmap-overwrite.ko  
kernel/lttng-modules/probes/lttng-probe-sunrpc.ko  
updates/drivers/net/wireless/ti/wlcore/wlcore.ko  
kernel/lttng-modules/probes/lttng-ftrace.ko  
kernel/lttng-modules/probes/lttng-probe-signal.ko  
kernel/lttng-modules/probes/lttng-probe-module.ko  
kernel/lttng-modules/lttng-ring-buffer-client-discard.ko  
kernel/lttng-modules/probes/lttng-probe-timer.ko  
kernel/lttng-modules/probes/lttng-types.ko  
updates/drivers/net/wireless/ti/wl12xx/wl12xx.ko  
kernel/lttng-modules/probes/lttng-probe-net.ko  
kernel/lttng-modules/probes/lttng-probe-gpio.ko  
kernel/lttng-modules/probes/lttng-probe-udp.ko  
kernel/lttng-modules/probes/lttng-kretprobes.ko  
kernel/lttng-modules/lttng-ring-buffer-metadata-mmap-client.ko  
kernel/lttng-modules/lib/lttng-lib-ring-buffer.ko  
kernel/lttng-modules/probes/lttng-probe-jbd2.ko  
kernel/lttng-modules/probes/lttng-probe-statedump.ko  
kernel/lttng-modules/probes/lttng-probe-ext4.ko  
kernel/lttng-modules/probes/lttng-probe-rpm.ko  
kernel/lttng-modules/probes/lttng-probe-rcu.ko  
updates/net/wireless/cfg80211.ko  
kernel/lttng-modules/lttng-tracer.ko  
kernel/lttng-modules/probes/lttng-probe-power.ko  
kernel/lttng-modules/probes/lttng-probe-sched.ko  
kernel/lttng-modules/probes/lttng-probe-block.ko  
kernel/lttng-modules/probes/lttng-probe-jbd.ko  
kernel/lttng-modules/probes/lttng-probe-vmscan.ko  
kernel/lttng-modules/probes/lttng-kprobes.ko  
kernel/lttng-modules/probes/lttng-probe-scsi.ko  
kernel/lttng-modules/probes/lttng-probe-regmap.ko  
kernel/lttng-modules/probes/lttng-probe-skb.ko  
kernel/lttng-modules/probes/lttng-probe-ext3.ko  
kernel/lttng-modules/probes/lttng-probe-regulator.ko  
kernel/lttng-modules/probes/lttng-probe-random.ko  
kernel/lttng-modules/probes/lttng-probe-workqueue.ko  
updates/net/mac80211/mac80211.ko  
updates/compat/compat.ko  
kernel/lttng-modules/probes/lttng-probe-irq.ko

Thanks,  
Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [September 20, 2016, 3:23am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/2 "2016-09-20T03:23:36Z")

</div>

```
Hi Raf,

For your questions:

SPI2: 
Figure 2-13 on page 26 of the Developer's Guide shows IoT#2 having a direct connection to SPI1. Is this true? 
I checked the schematic and it would seem that the SPI lines on IoT#2 are connected to pins 92, 93, 94, 95 on the CF3 socket, which are not dedicated SPI pins on the WP8548 module. Does SPI2 work? or is it intended to be used with different CF3 modules?

--> Yes, SPI2 is meant for different CF3 modules and is not supported on WP8548 module.

SPI (in general)
I'm trying to use SPI in user space (for the moment), but I cannot find the platform device at /dev/spidev_B_.C
There's /dev/sierra_spi but I get an error (Inappropriate ioctl for device) when trying to set the mode via ioctl.
Is it instead mapped to some 'tty#' device?

Can you try adding the following line of code in your user space code:
#ifdef SPI_IOC_MAGIC
#undef SPI_IOC_MAGIC
#define SPI_IOC_MAGIC 'l'
#endif

```

cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [September 20, 2016, 5:34am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/3 "2016-09-20T05:34:32Z")

</div>

Hi Ashish,

Thanks for your assistance.

I’ve added the code to my main application file (after the #include of spidev.h) and the error message has now changed to ‘Invalid argument’.

Is SPI\_IOC\_MAGIC a unique number used with sierra\_spi?

**Legato Logger output**  
Sep 20 05:07:33 | Legato | iot[22141]/iot\_exe T=main | \_main.c main() 55 | == Starting Event Processing Loop ==  
Sep 20 05:07:33 | Legato | iot[22141]/IoT\_SPI\_TestComponent T=main | IoT\_SPI\_Test.c \_IoT\_SPI\_TestComponent\_COMPONENT\_INIT() 81 | SPI Test.  
Sep 20 05:07:33 | Legato | =ERR= | iot[22141] | can’t set spi WR mode: Invalid argument

**Application strace capture**  
…  
open("/dev/sierra\_spi", O\_RDWR) = 7  
ioctl(7, 0x40016c01, 0xb6f8e305) = -1 EINVAL (Invalid argument)  
dup(2) = 8  
fcntl64(8, F\_GETFL) = 0x2 (flags O\_RDWR)  
fstat64(8, {st\_mode=S\_IFCHR|0620, st\_rdev=makedev(136, 0), …}) = 0  
mmap2(NULL, 4096, PROT\_READ|PROT\_WRITE, MAP\_PRIVATE|MAP\_ANONYMOUS, -1, 0) = 0xb6f29000  
write(8, “can’t set spi WR mode: Invalid a”…, 40can’t set spi WR mode: Invalid argument  
) = 40  
close(8)  
…

Here’s my code. It’s basically just the standard ‘spidev\_test.c’ program with minor changes. Sorry for bloating this reply with it. I was unable to attach the files. It fails at setting the spi mode. Note that I’ve tried all 4 modes and each gives the same result - invalid argument.

Thanks again

* * *

**IoT\_SPI\_Test.c**

#include “legato.h”  
#include “stdint.h”  
#include “unistd.h”  
#include "stdio.h’  
#include “stdlib.h”  
#include “getopt.h”  
#include “fcntl.h”  
#include “sys/ioctl.h”  
#include “linux/types.h”  
#include “linux/spi/spidev.h”

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

#ifdef SPI\_IOC\_MAGIC  
#undef SPI\_IOC\_MAGIC  
#define SPI\_IOC\_MAGIC ‘l’  
#endif

#define ARRAY\_SIZE(a) (sizeof(a) / sizeof((a)[0]))

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

static const char \*device = “/dev/sierra\_spi”;

static uint8\_t mode = SPI\_MODE\_0;  
static uint8\_t bits = 8;  
static uint32\_t speed = 1000000;  
static uint16\_t delay = 100;

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
static void pabort(const char \*s)  
{  
perror(s);  
abort();  
}

static void transfer(int fd)  
{

```
int ret;

uint8_t tx[] = {
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
    0xF0, 0x0D,
};

uint8_t rx[ARRAY_SIZE(tx)] = {0, };

struct spi_ioc_transfer tr = {
    .tx_buf = (unsigned long)tx,
    .rx_buf = (unsigned long)rx,
    .len = ARRAY_SIZE(tx),
    .delay_usecs = delay,
    .speed_hz = speed,
    .bits_per_word = bits,
};

ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
    pabort("can't send spi message");

for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
    if (!(ret % 6))
        puts("");
    printf("%.2X ", rx[ret]);
}
puts("");

```

}

COMPONENT\_INIT  
{  
LE\_INFO(“SPI Test.”);

```
int ret = 0;
int fd;

fd = open(device, O_RDWR);
if (fd < 0)
    pabort("can't open device");

// spi mode
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
    pabort("can't set spi WR mode");

ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
    pabort("can't get spi RD mode");

// bits per word
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
    pabort("can't set bits per word");

ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
    pabort("can't get bits per word");

// max speed hz
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
    pabort("can't set max speed hz");

ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
    pabort("can't get max speed hz");

printf("spi mode: %d\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

transfer(fd);

close(fd);

```

}

* * *

And the .adef file, **IoT\_SPI\_Test.adef**

sandboxed: false  
version: 1.0.0  
maxFileSystemBytes: 512K  
executables:  
{  
iot = ( IoT\_SPI\_TestComponent )  
}  
processes:  
{  
envVars:  
{  
LE\_LOG\_LEVEL = DEBUG  
}  
run:  
{  
( iot )  
}  
maxCoreDumpFileBytes: 512K maxFileBytes: 512K  
}  
requires:  
{  
device:  
{  
// I get read and write access to the SPI port.  
[rw] /dev/sierra\_spi /dev/sierra\_spi  
}  
}

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)\
**Post date:** [September 20, 2016, 7:12pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/4 "2016-09-20T19:12:42Z")

</div>

I don’t know if it matters, but you have a requires/device section in your adef file, but your adef also has sandboxed:false. It shouldn’t be necessary to map the device file into the sandbox if there is no sandbox.

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [September 20, 2016, 10:45pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/5 "2016-09-20T22:45:31Z")

</div>

for mode set it as an int:  
static int mode = SPI\_MODE\_0;

let me know how it goes. We plan to release an API for SPI functionality in the next 2-3 weeks.

cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [September 21, 2016, 12:40am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/6 "2016-09-21T00:40:11Z")

</div>

@dfrey Thanks for the tip - It makes sense.

@asyal That did it, Ashish! Loop-back tests are working now. Thanks again.  
Great news. An API would be very handy. I look forward to its release.

Cheers,  
Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [September 24, 2016, 3:53am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/7 "2016-09-24T03:53:29Z")

</div>

Rafi,

We will release our SPI API mid next week. Look forward to feedback.

cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [September 30, 2016, 1:34am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/8 "2016-09-30T01:34:46Z")

</div>

Hi Ashish,

Just checking how the SPI API release is going and where might I be able to find it.

Cheers,  
Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [October 3, 2016, 4:31pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/9 "2016-10-03T16:31:14Z")

</div>

Raf,  
After internal discussions, we plan to integrate the SPI code in the next Legato release.  
However, if you want , we can release it to you as an alpha user. This means that you are aware that it is not fully tested.  
From our side, I would like to get feedback from you on the SPI APIs so we can improve it further.  
Let me know if that is you are ok with this and we can provide the code to you.  
cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [October 4, 2016, 12:42am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/10 "2016-10-04T00:42:23Z")

</div>

Ashish,  
That works for me. I’d be happy to try it out and provide feedback.

Cheers,  
Raf

---

<div class="post-metadata">

**Author:** ![reunan](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@reunan](https://mangoh.discourse.group/u/reunan)\
**Post date:** [October 4, 2016, 12:27pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/11 "2016-10-04T12:27:36Z")

</div>

Hello Asyal,  
I plan to work with SPI and I’m also waiting for the SPI APIs.  
I’d like to help if it’s possible.

cheers,  
Reunan

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [October 4, 2016, 9:18pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/12 "2016-10-04T21:18:51Z")

</div>

Raf/Reunan,

You can get the SpiService and SpiTest from [https://github.com/mangoh](https://github.com/mangoh).  
Note this beta code and will certainly change in the next few weeks.

cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [October 5, 2016, 12:34am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/13 "2016-10-05T00:34:54Z")

</div>

Ashish,

Thanks for providing the code.

I’m just having a little difficulty understanding what to do after after following the steps from [https://github.com/mangOH/SpiService](https://github.com/mangOH/SpiService). Are you able to assist?

I have acquired the mangOH source code from the repository and made the necessary changes to both files.  
Note that I’m using Developer Studio 4.1.1 and my installation did not have a ‘mangOH’ folder before.  
How do I integrate the mangOH folder/files with DS? As far as I can tell, my current setup did not make use of the ‘targetDefs._mangoh_’ and ‘_mangoh_.sdef’ files.

I could just clone both spi components and run them but would prefer to do it properly.

Cheers,  
Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [October 5, 2016, 2:23am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/14 "2016-10-05T02:23:12Z")

</div>

Raf,  
I built this using command line. Dev Studio integration will happen once this code is part of Legato main line (currently it is under review).  
Why dont you use it using command line?  
Ashish

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [October 10, 2016, 2:42am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/15 "2016-10-10T02:42:21Z")

</div>

Hi Ashish,

Here’s what I get when trying to build from the command line:

legato@legato-VirtualBox:~/mangOH/apps/SpiService$ mkapp -v -t wp85 spiService.adef  
Parsing file: ‘/home/legato/mangOH/apps/SpiService/spiService.adef’.  
Modelling application: 'spiService’  
defined in: '/home/legato/mangOH/apps/SpiService/spiService.adef’  
Application ‘spiService’ contains executable ‘spiService’.  
Parsing file: ‘/home/legato/mangOH/apps/SpiService/spiServiceComponent/Component.cdef’.  
Modelling component: 'spiServiceComponent’  
found at: ‘/home/legato/mangOH/apps/SpiService/spiServiceComponent’  
\*\* ERROR:  
/home/legato/mangOH/apps/SpiService/spiServiceComponent/Component.cdef:5:8: error: Couldn’t find file ‘$MANGOH\_ROOT/apps/SpiService/spi.api’.

I receive the same error when attempting to build ‘spiTest’.

The file it’s after is definitely there:  
legato@legato-VirtualBox:~/mangOH/apps/SpiService$ ls  
\_build\_spiService **spi.api** spiService.adef  
[README.md](http://README.md) spiLibraryComponent spiServiceComponent

I’m thinking it’s caused by my environment being configured for DS, thus it’s not aware of mangoh.sdef, targetDefs.mangoh, nor $MANGOH\_ROOT for that matter.

Modules: wp85, wp750x  
SDK Path: /home/legato/legato/packages/legato.sdk.16.7.0.wp85-wp75-native-x86\_64-201609301633  
Framework Path: /home/legato/legato/packages/legato.framework.16.7.0.201609081601 - $LEGATO\_ROOT  
Toolchain Path: /home/legato/legato/packages/legato.toolchain.1.7.3.fw\_SWI9X15Y\_07110900-wp85-wp750x-native-x86\_64-201608171142 - $WP85\_TOOLCHAIN\_DIR $WP750X\_TOOLCHAIN\_DIR  
Device Image Path: /home/legato/legato/packages/legato.device.image.7.11.9.00.wpX5-201609121138 - $WPX5\_DEVICE\_IMAGE  
Recovery tools Path: /home/legato/legato/packages/legato.recovery.4.0.0.linux-201607191626 - $WPX5\_RECOVERY  
No toolchain found for target ‘ar7’.  
Unable to find compatible cross-build toolchain for target ‘ar7’.  
No toolchain found for target ‘ar86’.  
Unable to find compatible cross-build toolchain for target ‘ar86’.  
/home/legato  
legato@legato-VirtualBox:~$

How can I reconfigure the legato environment to make this work?  
Sorry if this is not the correct forum to be discussing this.

Thanks again,  
Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [October 10, 2016, 11:31pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/16 "2016-10-10T23:31:24Z")

</div>

Can you change the path in cdef from: $MANGOH\_ROOT/apps/SpiService/spi.api to: /home/legato/mangOH/apps/SpiService/spi.api

---

<div class="post-metadata">

**Author:** ![Raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Raf](https://mangoh.discourse.group/u/Raf)\
**Post date:** [October 11, 2016, 1:31am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/17 "2016-10-11T01:31:05Z")

</div>

Thanks Ashish - that did the trick.

There’s a bunch of cdef files from other services dependent on $MANGOH\_ROOT so I just added these two lines to /home/legato/legato/packages/legato.sdk.latest/resources/configlegatoenv to make things easier.

sourceMangOHPath=/home/legato/mangOH/  
export MANGOH\_ROOT=${sourceMangOHPath}

All up and running now.

Raf

---

<div class="post-metadata">

**Author:** ![asyal](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/asyal/32/78_2.png) [@asyal](https://mangoh.discourse.group/u/asyal)\
**Post date:** [October 11, 2016, 10:38pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/18 "2016-10-11T22:38:56Z")

</div>

Thanks for the update.  
Cheers,  
Ashish

---

<div class="post-metadata">

**Author:** ![gregnietsky](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/gregnietsky/32/66_2.png) [@gregnietsky](https://mangoh.discourse.group/u/gregnietsky)\
**Post date:** [March 14, 2017, 5:49pm UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/19 "2017-03-14T17:49:02Z")

</div>

using Legato 16.10.1 you need to add  
..le\_spi -\> spiService.le\_spi  
as binding in adef

and  
le\_spi.api

to requires api in Component.cdef

This is missing from the documentation and should be added for completeness.

---

<div class="post-metadata">

**Author:** ![kent1ukr](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@kent1ukr](https://mangoh.discourse.group/u/kent1ukr)\
**Post date:** [May 8, 2017, 10:13am UTC](https://mangoh.discourse.group/t/spi-on-mangoh-green/228/21 "2017-05-08T10:13:07Z")

</div>

Hi everyone.  
I am trying to enable SPI on my WP8548 and have some troubles with it  
First of all i have legato 16.10on my target & i’m using this tutorial to enable SPI -\> [http://legato.io/legato-docs/latest/howToSPI.html](http://legato.io/legato-docs/latest/howToSPI.html) I did all till step “Next, you’ll need to create a kernel module .ko file.” and went to -\> [http://legato.io/legato-docs/latest/yoctoOutofTreeKernelModule.html#howToAddKernelDriver\_makeKernel](http://legato.io/legato-docs/latest/yoctoOutofTreeKernelModule.html#howToAddKernelDriver_makeKernel) there i did all till step “Build Kernel” and tryed to compile my spisvc.c module with “make” like in tutorial and it failed with error. Then i tryed to compile module with “sudo make” and it started to ask me about a hundred config questions, that i don’t even realize how to answer, and finaly it failed with error.  
Can someone help me solving this issues? Or just say what am i doing wrong  
**Makefile**

```
# Kernel module build command for ARM targets is:
# make PATH=$PATH:~opt/swiy17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi-
#
# List of object file(s) to be built
obj-m+=spisvc.o
#
# Point to the directory containing sources for the kernel running on target
# system. The kernel directory must have the configuration build step executed,
# i.e. it must contain the target system's .config file.
#
# Legato tools contain such a directory, point to it.
KBUILD_DIR=/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel
#
# Kernel module build dependency
all: 
	make -C $(KBUILD_DIR) M=$(PWD) modules
#
# Kernel module clean dependency
clean: 
	make -C $(KBUILD_DIR) M=$(PWD) clean   

```

**spisvc.c**

[spoiler]/ \*  
\* This program is free software; you can redistribute it and/or modify  
\* it under the terms of the version 2 of the GNU General Public License  
\* as published by the Free Software Foundation  
\*  
\* This program is distributed in the hope that it will be useful,  
\* but WITHOUT ANY WARRANTY; without even the implied warranty of  
\* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
\* GNU General Public License for more details.  
\*  
\* You should have received a copy of the GNU General Public License  
\* along with this program; if not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).  
\*  
\* Copyright © 2016 Sierra Wireless Inc.  
\*/

```
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/spi/spi.h>

#define MOD_DESC "Spidev creation module"

MODULE_DESCRIPTION(MOD_DESC);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Sierra Wireless, Inc.");

static struct spi_device *spidev;

static __init int spisvc_init(void)
{
	struct spi_master *master;
	struct spi_board_info board = {
		.modalias = "spidev",
		.max_speed_hz = 15058800,
		.mode = SPI_MODE_3,
		.platform_data = NULL,
		.bus_num = 0,
		.chip_select = 0,
		.irq = 0,
	};

	master = spi_busnum_to_master(0);
	if (!master) {
		pr_err("No master for SPI bus 0.\n");
		return -ENODEV;
	}

	spidev = spi_new_device(master, &board);
	if (!spidev) {
		pr_err("Error creating device '%s'\n", board.modalias);
		return -ENODEV;
	}
	return 0;
}
module_init(spisvc_init);

static __exit void spisvc_exit(void)
{
	if (spidev)
		spi_unregister_device(spidev);
}
module_exit(spisvc_exit);

```

[/spoiler]

**spisvc.mdef**

```
//-------------------------------------------------------------------------------------------------
// Definition file for spisvc kernel module.
//
// Inserting this kernel module results in the creation of a spidev-type device /dev/spidev0.0.
// Removing this module removes the device. The device uses CS0 so any other SPI driver attempting
// to use the same chip-select would report a conflict.
//
// For use with a MangOH reference design, SPI device has to be plugged into IoT slot 0.
//
// Copyright (C) Sierra Wireless Inc.
//-------------------------------------------------------------------------------------------------

sources:
{
    spisvc.c
}

```

**error.txt**

shpp-admin@Aspire-V5-573G:~/kmodule$ make  
make -C /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel M=/home/shpp-admin/kmodule modules  
make[1]: Entering directory ‘/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel’  
CC [M] /home/shpp-admin/kmodule/spisvc.o  
In file included from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/bitops.h:16:0,  
from include/linux/bitops.h:36,  
from include/linux/kernel.h:10,  
from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/percpu.h:44,  
from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/preempt.h:5,  
from include/linux/preempt.h:20,  
from include/linux/spinlock.h:50,  
from include/linux/seqlock.h:35,  
from include/linux/time.h:5,  
from include/linux/stat.h:18,  
from include/linux/module.h:10,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/arch\_hweight.h: In function ‘\_\_arch\_hweight64’:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/arch\_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’  
asm (ALTERNATIVE(“call \_\_sw\_hweight64”, POPCNT64, X86\_FEATURE\_POPCNT)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/alternative.h:98:31: note: in definition of macro ‘ALTINSTR\_REPLACEMENT’  
b\_replacement(number)":\n\t" newinstr “\n” e\_replacement(number) “:\n\t”  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/arch\_hweight.h:53:7: note: in expansion of macro ‘ALTERNATIVE’  
asm (ALTERNATIVE(“call \_\_sw\_hweight64”, POPCNT64, X86\_FEATURE\_POPCNT)  
^  
In file included from include/linux/cache.h:5:0,  
from include/linux/time.h:4,  
from include/linux/stat.h:18,  
from include/linux/module.h:10,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/processor.h: At top level:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/cache.h:7:25: error: ‘CONFIG\_X86\_L1\_CACHE\_SHIFT’ undeclared here (not in a function)  
#define L1\_CACHE\_SHIFT (CONFIG\_X86\_L1\_CACHE\_SHIFT)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/cache.h:8:30: note: in expansion of macro ‘L1\_CACHE\_SHIFT’  
#define L1\_CACHE\_BYTES (1 \<\< L1\_CACHE\_SHIFT)  
^  
include/linux/cache.h:12:25: note: in expansion of macro ‘L1\_CACHE\_BYTES’  
#define SMP\_CACHE\_BYTES L1\_CACHE\_BYTES  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/processor.h:131:30: note: in expansion of macro ‘SMP\_CACHE\_BYTES’  
} **attribute** (( **aligned** (SMP\_CACHE\_BYTES)));  
^  
In file included from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/thread\_info.h:22:0,  
from include/linux/thread\_info.h:54,  
from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/preempt.h:6,  
from include/linux/preempt.h:20,  
from include/linux/spinlock.h:50,  
from include/linux/seqlock.h:35,  
from include/linux/time.h:5,  
from include/linux/stat.h:18,  
from include/linux/module.h:10,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/processor.h:164:0: warning: “cache\_line\_size” redefined  
#define cache\_line\_size() (boot\_cpu\_data.x86\_cache\_alignment)  
^  
In file included from include/linux/time.h:4:0,  
from include/linux/stat.h:18,  
from include/linux/module.h:10,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
include/linux/cache.h:64:0: note: this is the location of the previous definition  
#define cache\_line\_size() L1\_CACHE\_BYTES  
^  
In file included from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic.h:255:0,  
from include/linux/atomic.h:4,  
from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/thread\_info.h:23,  
from include/linux/thread\_info.h:54,  
from /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/preempt.h:6,  
from include/linux/preempt.h:20,  
from include/linux/spinlock.h:50,  
from include/linux/seqlock.h:35,  
from include/linux/time.h:5,  
from include/linux/stat.h:18,  
from include/linux/module.h:10,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:19:40: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_read(const atomic64\_t _v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h: In function ‘atomic64\_read’:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:21:32: error: request for member ‘counter’ in something not a structure or union  
return (_(volatile long \*)&(v)-\>counter);  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h: At top level:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:31:33: error: unknown type name ‘atomic64\_t’  
static inline void atomic64\_set(atomic64\_t \*v, long i)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:43:41: error: unknown type name ‘atomic64\_t’  
static inline void atomic64\_add(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:57:41: error: unknown type name ‘atomic64\_t’  
static inline void atomic64\_sub(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:73:49: error: unknown type name ‘atomic64\_t’  
static inline int atomic64\_sub\_and\_test(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:84:33: error: unknown type name ‘atomic64\_t’  
static inline void atomic64\_inc(atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:97:33: error: unknown type name ‘atomic64\_t’  
static inline void atomic64\_dec(atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:112:41: error: unknown type name ‘atomic64\_t’  
static inline int atomic64\_dec\_and\_test(atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:125:41: error: unknown type name ‘atomic64\_t’  
static inline int atomic64\_inc\_and\_test(atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:139:49: error: unknown type name ‘atomic64\_t’  
static inline int atomic64\_add\_negative(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:151:48: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_add\_return(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:156:48: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_sub\_return(long i, atomic64\_t \*v)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:164:37: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_cmpxchg(atomic64\_t \*v, long old, long new)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:169:34: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_xchg(atomic64\_t \*v, long new)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:183:39: error: unknown type name ‘atomic64\_t’  
static inline int atomic64\_add\_unless(atomic64\_t \*v, long a, long u)  
^  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/atomic64\_64.h:207:45: error: unknown type name ‘atomic64\_t’  
static inline long atomic64\_dec\_if\_positive(atomic64\_t \*v)  
^  
In file included from include/linux/elf.h:4:0,  
from include/linux/module.h:14,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/elf.h: In function ‘elf\_common\_init’:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/elf.h:173:3: error: ‘struct thread\_struct’ has no member named ‘fs’  
t-\>fs = t-\>gs = 0;  
^  
In file included from include/linux/module.h:22:0,  
from /home/shpp-admin/kmodule/spisvc.c:17:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/module.h: At top level:  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/include/asm/module.h:57:2: error: #error unknown processor family  
#error unknown processor family  
^  
In file included from /home/shpp-admin/kmodule/spisvc.c:17:0:  
include/linux/module.h:305:27: error: field ‘arch’ has incomplete type  
struct mod\_arch\_specific arch;  
^  
In file included from include/linux/sched.h:30:0,  
from include/linux/kthread.h:5,  
from include/linux/spi/spi.h:25,  
from /home/shpp-admin/kmodule/spisvc.c:19:  
include/linux/cputime.h:4:25: fatal error: asm/cputime.h: No such file or directory  
compilation terminated.  
scripts/Makefile.build:314: recipe for target ‘/home/shpp-admin/kmodule/spisvc.o’ failed  
make[2]: \*\*\* [/home/shpp-admin/kmodule/spisvc.o] Error 1  
Makefile:1276: recipe for target ‘_module_/home/shpp-admin/kmodule’ failed  
make[1]: \*\*\* [_module_/home/shpp-admin/kmodule] Error 2  
make[1]: Leaving directory ‘/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel’  
Makefile:16: recipe for target ‘all’ failed  
make: \*\*\* [all] Error 2

**sudo error.txt**

[spoiler]shpp-admin@Aspire-V5-573G:~/kmodule$ sudo make  
[sudo] password for shpp-admin:  
make -C /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel M= modules  
make[1]: Entering directory ‘/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel’

make[2]: \*\*\* No rule to make target ‘arch/x86/tools/relocs\_32.c’, needed by ‘arch/x86/tools/relocs\_32.o’. Stop.  
/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel/arch/x86/Makefile:179: recipe for target ‘archscripts’ failed  
make[1]: \*\*\* [archscripts] Error 2  
make[1]: Leaving directory ‘/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel’  
Makefile:16: recipe for target ‘all’ failed  
make: \*\*\* [all] Error 2

[/spoiler]  
[error.txt](https://mangoh.discourse.group/uploads/short-url/7joRwXwnbf5QUHNgqVPQFImh80y.txt) (11.8 KB)  
[sudo error.txt](https://mangoh.discourse.group/uploads/short-url/bGrJTMyLlRyZAcd4Y39n3NT8HnN.txt) (85.3 KB)

[Next page](https://mangoh.discourse.group/t/spi-on-mangoh-green/228.md?page=2)
