FX30 with (WP77xx) with Talon mangOH CAN interface

Red.sdef, last line

// Uncomment to include support for the CAN IoT card
#include “sinc/can_iot_card.sinc”

So I don’t need to rebuild the kernel modules? Are u sure this is not for VScode only?

i build it in command line, not vscode.

My test is done on WP77 + mangoh board without the CAN board and my test is just to show you that the can_iot.ko can be installed.

You have to do the verification by yourself.

So the include statement is all need for the CAN board to work? I understand there are several ways to reach the same result, but we would really need to keep it with the leaf environment if possible, instead of jumping from branch to branch. Is there any way we can get the leaf version of this? As I believe un that case we need to build the kernel modules and I can’t see it here. Also to confirm we want to read and write from CAN raw data and not just to use the CAN iot board. Not sure there are differences in these.

I don’t know if that will work, you have to test it.
And i have no experience before to write and read CAN data.
The mangoh source is not downloaded by leaf tool, you need to download by git.

Some key hardware differences between the mangOH and the FX30:

  • FX30 uses UART2 on the IOT card port
  • IOT GPIO are different, please double the UG for the definitions, but I believe you’ll need to ensure the scripts use the correct GPIO:
    IOT_GPIO1 = WP GPIO42
    IOT_GPIO2 = WP GPIO33
    IOT_GPIO3 = WP GPIO13
    IOT_GPIO4 = WP GPIO8

BR,
Chris

mmmhhh, it doesnt look like we are moving big step forwards with this, all the help is very much appreciated but I believe we are running in circles a little bit. As far as I understand this should be quite simple to achieve, is there anybody out there which is currently using the FX30S with the mangOH CAN board (you named it IoT but to me this is just a CAN transducer) and who knows how to set this up with the leaf-legato workspace?? This is the last bit left behind and if we cant get it to work we need to drop this development as it is taking an extensive amount of time, we are getting out of schedule with the whole project.

Someone gets it work, please see here:

I have gone through that before, but I couldn`t get it to work on my FX30S.

image001.jpg

FYI. I can make CAN IOT card work on WP77+R9+mangoh red board:

root@fx30:~# ./start_can.sh red 0
rmmod: can’t unload ‘can_iot’: unknown symbol in module, or unknown parameter
Could not unload the required module, can_iot.ko. (LE_FAULT)
See the device log for details.
Load of module can_iot.ko has been successful.
root@fx30:~#
root@fx30:~# ifconfig can0
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP RUNNING NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

root@fx30:~#
root@fx30:~# legato version
18.06.1_590ae48664b4b2d19394d0637ea7e9bb
root@fx30:~#
root@fx30:~# cm info
Device: WP7702
IMEI: 352653090002874
IMEISV: 2
FSN: [ 134.471009] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:1 cur:0 tx) bc(rx:0 tx:2) mode:FIFO slv_addr:0x3a MSTR_STS:0x0c1300c8 OPER:0x00000090
VU735370521401
Firmware Version: SWI9X06Y_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12
Bootloader Version: SWI9X06Y_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12
MCU Version: 002.009
PRI Part Number (PN): 9907365
PRI Revision: 001.001
Carrier PRI Name: GENERIC
Carrier PRI Revision: 001.028_001
SKU: 1103530
Last Reset Cause: Power Down
Resets Count: Expected: 822 Unexpected: 257

Hi,

I’m the one that posted the working instructions.
I could try to help you if you want. I used to compile my project with Developer Studio.
Below is the system project that I use with the kernel modules, that’s all you need to get it working.

FX30S_CAN.zip (99.0 KB)

Best,
Caio Porto

@caio-porto thank you for the help, did get this to work and the problem was only with the sequence of the loading of the modules, the can/can-dev modules don`t need to be included as k modules and also I just used the kmod load command.
I could then set up the can0 interface and to read data from it.

There is only one weird problem, which is with the identifier where it seems this is only reading the first 11 bits of the identifier, this is the code i am using;

family = can_params.family;
    type =  can_params.type;
    protocol = can_params.protocol;

    if((fd = socket(family, type, protocol)) < 0)
    {
        LE_INFO("cannot open socket");
        return;
    }
    strcpy(ifr.ifr_name, ifname);
    ioctl(fd, SIOCGIFINDEX, &ifr);
    addr.can_family = family;
    addr.can_ifindex = ifr.ifr_ifindex;
    if(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
        LE_INFO("cannot bind socket");
        return;
    }
    //set the filters
    // optional
    struct can_filter rfilter;
    rfilter.can_id   = 0x901;
    rfilter.can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_EFF_MASK);
    setsockopt(fd, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
    
    message.can_id = message.can_id | CAN_EFF_FLAG;

    while(1)
    {
        if(can_read_socket(&message)){
            LE_INFO("READ COB_ID:%x",message.can_id | CAN_EFF_FLAG);
        }
        sleep(1);
    }
    return; 

This is where I am reading from the socket

static int can_read_socket(struct can_frame *msg)
{
    fd_set rdfs;
    struct timeval timeo;
    
    FD_ZERO(&rdfs);
    FD_SET(fd, &rdfs);
    
    timeo.tv_sec  = 0;
    timeo.tv_usec = 0;

    if(select(fd+1, &rdfs, NULL, NULL, &timeo) < 0)
    {
        return 0;
    }
    if(!FD_ISSET(fd, &rdfs))
    {
        return 0;
    }
    if(read(fd, msg, sizeof(struct can_frame)) != sizeof(struct can_frame))
    {
        return 0;
    }
    printf("size:%d,cob_id:%x\n",sizeof(msg->can_id),msg->can_id | CAN_EFF_FLAG);
    return 1;
}

I am seding a CAN frame with idx x901 and the socket always return x101, so I am thinking where is the flag supposed to be set, or if this is to do with hardware filters… I can send a frame with 29bits identifier, no problem…

So I am wondering why this is happening…

I have tried to simplify the code a little bit, still having the same issue:

 struct can_frame message;
    struct sockaddr_can addr;
    struct ifreq ifr;
    int   fd = -1;                  // file descriptor (it´s a socket)

    if((fd = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
    {
        LE_INFO("cannot open socket");
        return;
    }
    strcpy(ifr.ifr_name, "can0");
    ioctl(fd, SIOCGIFINDEX, &ifr);
    addr.can_family = AF_CAN;
    addr.can_ifindex = ifr.ifr_ifindex;
    if(bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
        printf("cannot bind socket\n");
        return;
    }

    uint8_t nbytes;

    message.can_id |= CAN_EFF_FLAG;

    while(1)
    {
        nbytes = read(fd, &message, sizeof(struct can_frame));

        if (nbytes < 0) {
                perror("can raw socket read");
                return;
        }

        /* paranoid check ... */
        if (nbytes < sizeof(struct can_frame)) {
                fprintf(stderr, "read: incomplete CAN frame\n");
                return;
        }

        printf("READ COB_ID:%x\n",message.can_id | CAN_EFF_FLAG);
        
    }
    return;

I anyone has any answer or have had similar problems…

Hi,

I can use Talon CanBus IOT card to get CanBus data well, if you have any problem,we can use email to discuss this.

ahwow120509@gmail.com

Albert

hey, :slight_smile:
I can setup the CAN IoT device, no problem, but I am having issues on reading 29bit idx from the CAN.

i.e. I am sending a message x999 on the CAN bus and the FX30S is reading x199 which is the 11bit part of the message.
Are you actually using the CAN IoT to read 29bit idx with extended flag?

Anyone from SWI which could assist on this?
Or any people who has had experience with using the 29bit identifier with the CAN IoT board from Talon?
We had to postpone the release of our project for issues related with this board, where now is all working but the only issue is with reading the 29 bit idx from the CAN.
That would be very much appreciated!!

Hi @ClaudioBaldo,

I read 29 bits on mine. Here is my old code. I later on converted to use a J1939 library that implements an easy CAN library instead.
My code is in C++, but should work similarly in C. I had it in C in the past, but changed for simplicity.

int openCANSocket()
{
	int s;
	std::string sInt = CAN_INTERFACE;
    char* interface = &sInt[0u];
	int family = PF_CAN;
    int type = SOCK_RAW;
    int proto = CAN_RAW;
	struct sockaddr_can addr;
	struct ifreq ifr;

	// Open network-socket for CAN interface
    if((s = socket(family, type, proto)) < 0)
    {
        perror("socket");
        LE_ERROR("Error on socket at CAN");
        return -1;
    }

    // Get IP-address by interface name
    addr.can_family = family;
    strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
    if(ioctl(s, SIOCGIFINDEX, &ifr))
    {
        perror("ioctl");
        LE_ERROR("Error on IP at CAN");
        return -1;
    }
    addr.can_ifindex = ifr.ifr_ifindex;

    // Bind socket to device
    if (bind(s, (sockaddr *)&addr, sizeof(addr)) < 0)
    {
        perror("bind");
        LE_ERROR("Error binding socket at CAN");
        return -1;
    }

	return s;
}

static void CAN_ReadFunc(void* socket)
{
	int nbytes;
	int* s = (int*)socket;
	struct can_frame frame;

	while(1)
	{
		// Read CAN socket
		nbytes = read(*s, &frame, sizeof(struct can_frame));
		if(nbytes < 0)
		{
			LE_INFO("No data on the CAN bus");
		}
		else
		{
			// Get CAN ID and convert to HEX
			std::stringstream idHex;
			if(frame.can_id & CAN_EFF_FLAG)
				idHex << std::uppercase << std::hex << (frame.can_id & CAN_EFF_MASK);
			else
				idHex << std::uppercase << std::hex << (frame.can_id & CAN_SFF_MASK);

			// Get the data and convert to HEX
			std::stringstream dataHex;
			for(int i = 0; i < frame.can_dlc; i++)
				dataHex << std::setfill('0') << std::setw(2) << std::uppercase << std::hex << __u32(frame.data[i]);

			cout << idHex << ":" << dataHex << std::endl;

		}
	}
}

@caio-porto thank you mate, my code was good but I was using a device which didn`t actually set the extended flag.
I have tested this with a proper J1939 simulator and then I can receive the extended CAN frame.
Cheers

Has anyone used a event handler to handle the received data from the CAN bus, and if yes, which signal have you used to trigger it?

Hi Claudio, I’m doing the same steps as you, but I have a mangOH green with WP7607. I use the Talon CAN Bus IoT extender for Sierra mangOH IoT. After several problems I find myself in this situation:

root@swi-mdm9x28-wp:~# ./start_can.sh green 0
Unload of module can_iot.ko has been successful.
sh: write error: Device or resource busy
Connecting to service ...
Executing 4: Turn SPI on for IoT slot 0
Success
Connecting to service ...
Executing 15: Reset IoT slot 0
Success
Load of module can_iot.ko has been successful.
Cannot find device "can0"
ifconfig: SIOCGIFFLAGS: No such device

I also tried it as suggested by the guide:

how resolve the problem "Cannot find device “can0"”?? PLS Help