# CAN IoT Card driver

**URL:** <https://mangoh.discourse.group/t/can-iot-card-driver/997>\
**Category:** mangOH Red\
**Created:** [December 16, 2017, 12:44pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997 "2017-12-16T12:44:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [December 16, 2017, 12:44pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/1 "2017-12-16T12:44:54Z")

</div>

Hello,  
I got this CAN module  
[http://www.taloncom.com/images/Talon%20mangOH%20CAN%20Bus%20Module%20Brief%202016.pdf](http://www.taloncom.com/images/Talon%20mangOH%20CAN%20Bus%20Module%20Brief%202016.pdf)

Is this the right tutorial for MangOH Red in order to get this CAN module to work?  
[https://github.com/mangOH/mangOH/wiki/How-to-build-MCP2515-CAN-drivers-for-mangOH-for-mangOH-Red](https://github.com/mangOH/mangOH/wiki/How-to-build-MCP2515-CAN-drivers-for-mangOH-for-mangOH-Red)

---

<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:** [December 16, 2017, 1:10pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/2 "2017-12-16T13:10:20Z")

</div>

Yes, it is.  
Let us know if you have any issues

---

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [December 23, 2017, 8:33am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/3 "2017-12-23T08:33:58Z")

</div>

The link in step one is broken  
"1. Download Legato Distribution Source Package from Sierra Wireless website:  
Yocto Source (Around 3 GB)"

---

<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:** [December 24, 2017, 2:25am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/4 "2017-12-24T02:25:30Z")

</div>

> [@raxsix](#):
>
> gOH
> 
> Primary mangOH

Thanks. Fixed the link. You need to pick the latest toolchain package

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [December 24, 2017, 10:24am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/5 "2017-12-24T10:24:19Z")

</div>

I have this «module. Do you have the schematic ? Not found on the web site.

---

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [December 24, 2017, 10:54am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/6 "2017-12-24T10:54:49Z")

</div>

Nope, same problem…

---

<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:** [December 24, 2017, 5:20pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/7 "2017-12-24T17:20:52Z")

</div>

The link on the wiki is [https://source.sierrawireless.com/resources/legato/downloads/](https://source.sierrawireless.com/resources/legato/downloads/)

Is this the problem?

---

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [December 24, 2017, 6:00pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/8 "2017-12-24T18:00:54Z")

</div>

Sorry Asyal, the link is ok, I ment the CAN module electrical schematic

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [December 27, 2017, 10:04pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/9 "2017-12-27T22:04:29Z")

</div>

I have builded the new yocto image to support the CAN IoT card. I not see in menu config a way to add can-utils. For example candump is very good utility to monitor can message. Any way to add it in yocto ??? Thanks

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 1, 2018, 10:54pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/10 "2018-01-01T22:54:45Z")

</div>

Hello

I have connected the CAN Iot card TALON to a can viewer.

I meet a problem.

I can send 1 can message only. The next message are not sent.  
Any idea ??

This is my code (using socket CAN). Very basic…  
Hello message is send but not the second message…

int can\_loop(void)  
{  
struct ifreq ifr;  
struct sockaddr\_can addr;  
struct can\_frame frame;  
int s;  
memset(&ifr, 0x0, sizeof(ifr));  
memset(&addr, 0x0, sizeof(addr));  
memset(&frame, 0x0, sizeof(frame));  
/\* open CAN\_RAW socket _/  
s = socket(PF\_CAN, SOCK\_RAW, CAN\_RAW);  
/_ convert interface sting “can0” into interface index _/  
strcpy(ifr.ifr\_name, “can0”);  
ioctl(s, SIOCGIFINDEX, &ifr);  
/_ setup address for bind _/  
addr.can\_ifindex = ifr.ifr\_ifindex;  
addr.can\_family = PF\_CAN;  
/_ bind socket to the can0 interface \*/  
bind(s, (struct sockaddr _)&addr, sizeof(addr));  
/_ first fill, then send the CAN frame \*/  
frame.can\_id = 0x23;  
strcpy((char _)frame.data, “hello”);  
frame.can\_dlc = 5;  
write(s, &frame, sizeof(frame));  
/_ first fill, then send the CAN frame \*/  
frame.can\_id = 0x24;  
strcpy((char \*)frame.data, “iCC2012”);  
frame.can\_dlc = 7;  
write(s, &frame, sizeof(frame));  
close(s);  
return 0;  
}

COMPONENT\_INIT  
{

```
// Run the can-init.sh before advertising the service to ensure that the CAN device is
// available before we allow it to be used.
char line[256];
FILE* fp = popen("can_init.sh 2>&1", "r");
LE_ASSERT(fp != NULL);
while (fgets(line, sizeof(line), fp) != NULL)
{
	LE_INFO("can_init.sh output: %s", line);
}
int canInitResult = pclose(fp);
LE_FATAL_IF(!WIFEXITED(canInitResult), "Could not run can_init.sh");
const int canInitExitCode = WEXITSTATUS(canInitResult);
LE_FATAL_IF(canInitExitCode != 0, "can_init.sh failed with exit code %d", canInitExitCode);

can_loop();

```

}

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 2, 2018, 12:06am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/11 "2018-01-02T00:06:54Z")

</div>

I suspect a patch problem. I not use the patch for the Mangoh Red…  
I must rebuild the yocto linux distro…

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 2, 2018, 8:08am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/12 "2018-01-02T08:08:30Z")

</div>

All is good now with the correct patch 🙂

---

<div class="post-metadata">

**Author:** ![nageshkar](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nageshkar](https://mangoh.discourse.group/u/nageshkar)\
**Post date:** [January 17, 2018, 6:38am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/13 "2018-01-17T06:38:09Z")

</div>

hey,  
can you suggest links related LoRa expansion card ?  
Not found any useful data related to it?  
any documentation releted to it will be really useful

---

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [January 21, 2018, 7:36pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/14 "2018-01-21T19:36:24Z")

</div>

Is that CAN driver tutorial only for wp85?  
I have wp7502, is it ok to follow it until the end or do I need to change some of the commands along the way?

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 21, 2018, 8:33pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/15 "2018-01-21T20:33:23Z")

</div>

I think it’s the same for wp7502.  
For wp76 I m in progress for the patch.

---

<div class="post-metadata">

**Author:** ![raxsix](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@raxsix](https://mangoh.discourse.group/u/raxsix)\
**Post date:** [January 22, 2018, 8:21pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/16 "2018-01-22T20:21:57Z")

</div>

Did you get your wp76 to work according to described steps?

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 22, 2018, 10:23pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/17 "2018-01-22T22:23:02Z")

</div>

I have rebuild the Linux yocto to add can support and mcp2515 driver.  
I use R7 firmware with kernel 3.18 and yocto 2.2.

For the moment it doesn’t work. I have modified the board file 9607.c to add the patch but the mcp2515 seems not detected.

Tommorow I will connect my scope to look if the gpio and spi bus work correctly.

---

<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:** [January 22, 2018, 11:56pm UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/18 "2018-01-22T23:56:46Z")

</div>

In the patch file, can you change #define MSM\_WIFI\_IRQ\_GPIO 80 to be #define MSM\_WIFI\_IRQ\_GPIO 79?  
I havent tried it but let me know if that works.

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 23, 2018, 7:19am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/19 "2018-01-23T07:19:04Z")

</div>

This is my source code of board-9607.c

Tell me if you see a error.

/\*

- Copyright © 2015, The Linux Foundation. All rights reserved.
- 
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 and
- only version 2 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.  
\*/

#include \<linux/kernel.h\>  
#include \<asm/mach/map.h\>  
#include \<asm/mach/arch.h\>  
#include “board-dt.h”

#ifdef CONFIG\_WL\_TI  
#include \<linux/wl12xx.h\>  
#endif

#include \<linux/irq.h\>  
#include \<linux/can/platform/mcp251x.h\>  
#include \<linux/gpio.h\>

/\*

- CAN bus GPIO interrupt line uses kernel GPIO73 which maps to user space
- GPIO42  
\*/  
#define MCP2515\_CAN\_IRQGPIO\_PIN 79

static const char \*mdm9607\_dt\_match[] \_\_initconst = {  
“qcom,mdm9607”,  
NULL  
};

static void \_\_init mdm9607\_init(void)  
{  
board\_dt\_populate(NULL);  
}

/\* CAN driver modification _/  
static struct mcp251x\_platform\_data msm\_mcp2515\_pdata = {  
.oscillator\_frequency = 16_1000\*1000,  
};

/\* CAN driver modification _/  
static struct spi\_board\_info msm\_spi\_mcp2515\_board\_info[] = {  
[0] = {  
.modalias = “mcp2515”,  
.platform\_data = &msm\_mcp2515\_pdata,  
.max\_speed\_hz = 2_1000\*1000,  
.mode = SPI\_MODE\_0,  
.bus\_num = 0,  
.chip\_select = 0,  
},  
};

static void \_\_init msm9615\_mcp2515\_init(void)  
{  
if ((gpio\_request(MCP2515\_CAN\_IRQGPIO\_PIN, “can\_irq”) == 0) &&  
(gpio\_direction\_input(MCP2515\_CAN\_IRQGPIO\_PIN) == 0)) {  
gpio\_export(MCP2515\_CAN\_IRQGPIO\_PIN, 0);  
irq\_set\_irq\_type(gpio\_to\_irq(MCP2515\_CAN\_IRQGPIO\_PIN), IRQ\_TYPE\_EDGE\_FALLING);  
} else {  
printk(KERN\_ERR “Could not obtain gpio for MCP251X CAN bus interrupt\n”);  
return;  
}  
msm\_spi\_mcp2515\_board\_info[0].irq = gpio\_to\_irq(MCP2515\_CAN\_IRQGPIO\_PIN);  
pr\_notice(  
“msm9615\_mcp2515\_init init done(gpio:%d irq:%d).\n”,  
MCP2515\_CAN\_IRQGPIO\_PIN,  
msm\_spi\_mcp2515\_board\_info[0].irq);  
}

#ifdef CONFIG\_WL\_TI  
#define MSM\_WIFI\_IRQ\_GPIO 79  
#endif  
/\* CAN driver modification \*/  
static void \_\_init msm9615\_common\_init(void)  
{  
pr\_notice(“Kernel with CANBUS support initializing\n”);  
msm9615\_mcp2515\_init();  
spi\_register\_board\_info(  
msm\_spi\_mcp2515\_board\_info,  
ARRAY\_SIZE(msm\_spi\_mcp2515\_board\_info));

}

/\* CAN driver modification \*/  
static void \_\_init msm9615\_mtp\_init(void)  
{  
msm9615\_common\_init();  
}

#ifdef CONFIG\_WL\_TI  
static void \_\_init mdm9607\_wl18xx\_init(void)  
{  
struct wl12xx\_platform\_data msm\_wl12xx\_pdata;  
int ret;

```
memset(&msm_wl12xx_pdata, 0, sizeof(msm_wl12xx_pdata));

msm_wl12xx_pdata.irq = gpio_to_irq(MSM_WIFI_IRQ_GPIO);
printk(KERN_ERR "wl12xx GPIO: %d\n", msm_wl12xx_pdata.irq);
if (msm_wl12xx_pdata.irq < 0)
	goto fail;

msm_wl12xx_pdata.use_eeprom = true;
msm_wl12xx_pdata.board_ref_clock = WL12XX_REFCLOCK_38;
msm_wl12xx_pdata.board_tcxo_clock = 0;

ret = wl12xx_set_platform_data(&msm_wl12xx_pdata);
if (ret < 0)
	goto fail;

pr_info("wl18xx board initialization done\n");
return;

```

fail:  
pr\_err("%s: wl12xx board initialisation failed\n", **func** );  
}  
#endif

DT\_MACHINE\_START(MDM9607\_DT,  
“Qualcomm Technologies, Inc. MDM 9607 (Flattened Device Tree)”)  
.init\_machine = mdm9607\_init,  
.dt\_compat = mdm9607\_dt\_match,  
.init\_machine = msm9615\_mtp\_init, /\* CAN driver modification \*/  
#ifdef CONFIG\_WL\_TI  
.init\_late = mdm9607\_wl18xx\_init,  
#endif  
MACHINE\_END

---

<div class="post-metadata">

**Author:** ![Francis.duhaut](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/francis.duhaut/32/350_2.png) [@Francis.duhaut](https://mangoh.discourse.group/u/Francis.duhaut)\
**Post date:** [January 23, 2018, 9:07am UTC](https://mangoh.discourse.group/t/can-iot-card-driver/997/20 "2018-01-23T09:07:55Z")

</div>

I use my scope to debug

- echo 2 \> /sys/class/gpio/export

- echo out \> /sys/class/gpio/gpio2/direction

- echo 1 \> /sys/class/gpio/gpio2/value

- echo 13 \> /sys/class/gpio/export

- echo out \> /sys/class/gpio/gpio13/direction

- echo 1 \> /sys/class/gpio/gpio13/value

level translator is enable and mcp2515 is out of reset

- modprobe can
- modprobe can-dev
- modprobe can-raw
- modprobe mcp251x

I see nothing appear on the SPI\_CLK on the IOT slot.  
It seems SPI is not working…

Any idea ?

[Next page](https://mangoh.discourse.group/t/can-iot-card-driver/997.md?page=2)
