CAN BUS on mangOH Red - simplified user experience

Please follow the instructions here:

Look forward to your feedback

@asyal

Many thanks. I will test it tomorrow morning and post my feed back.

:slight_smile:

Hello all,

This work very fine ! Great Job and thanks to theam.

I’am able to send/receive CAN message with socketcan api with my WP7607.
Legato 18.05.1

A solution to start the CAN with your application it’s to embedded the start_can.sh scrpit into your application. It’s a good way when you want to change CAN parameters (baudrate).

1 save to file start_can.sh and add into your project (root)

#!/bin/sh

export PATH=$PATH:/sbin

drv_file=`find /legato/systems/current/modules/ -name "*mcp251x.ko"`
drv=`basename $drv_file`
# remove the driver
rmmod $drv

# Take IoT card out of reset
echo 2 > /sys/class/gpio/export
echo out  > /sys/class/gpio/gpio2/direction
echo 1  > /sys/class/gpio/gpio2/value

# Enable level shifter on the CAN IoT card
echo 13 > /sys/class/gpio/export
echo out  > /sys/class/gpio/gpio13/direction
echo 1  > /sys/class/gpio/gpio13/value

# Bring driver back & iproute2 add in CAN
insmod $drv_file
ip link set can0 type can bitrate 125000 triple-sampling on
ifconfig can0 up
  1. add the following code and call it on COMPONENT_INIT {}

    void cant_start_sh (void)
    {
    char line[256];
    FILE* fp = popen(“start_can.sh 2>&1”, “r”);
    LE_ASSERT(fp != NULL);
    while (fgets(line, sizeof(line), fp) != NULL)
    {
    LE_INFO(“start_can.sh output: %s”, line);
    }
    int driverInitResult = pclose(fp);
    LE_FATAL_IF(!WIFEXITED(driverInitResult), “Could not run start_can.sh”);
    const int driverInitExitCode = WEXITSTATUS(driverInitResult);
    LE_FATAL_IF(driverInitExitCode != 0, “start_can.sh failed with exit code %d”, driverInitExitCode);
    }

Here some log of the can traffic. The apps send message 0x600 every 200ms.

and receive message 0x302 from my PC.

image

@asyal

This is my feedback:

CAN IoT driver work fine !
I start test for several day and let you inform about the result.

Thanks.

2 Likes

second day of test with new CAN IoT build and WP7607.
Any problem with very high traffic on the CANBUS (send/receive multi frame @50ms) Speed bus set to 500Kb/s.

Good !

1 Like

start_can.sh (889 Bytes)

Thank you team. Its working fine.
start_can.sh script attached. FYI.

1 Like

The best place to find the start_can.sh file is in the mangOH git repository under linux_kernel_modules/can_common/start_can.sh

Hello

My customer needs to use two CAN bus standards;
J1939 for collecting the data and KVP2000 for the control.
He will use MangOH red with WP7702 and Talon Iot Can card.

Can bus will work at 500kbps and with 50% of load. It looks we can support it with Legato for the answers here .

But this reference example has plenty of errors when compiling.

Could we get it without errors?
Thanks
Isabel

1 Like

Hey Isabel,

Have you managed to find a solution or workaround to this problem? I’ve also gotten a myriad of errors when attempting to compile the killSwitch app.

Thanks
Garret

Does anybody has experience about using the 29bit identifiers?
I have loaded the kmod for can_iot and mcp251x, then I am using a simple C code to read from the socket but all the identifiers seems to be filtered to the 11bits…
So If I am transmitting the 901h I am actually only reading (can_id from socket) 101h, the C code seems ok so I am wondering if this is a problem with the hardware or the kmodules…?

See C code below:

    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 am sending a CAN frame with idx x901 and this is what is printed:

READ COB_ID:80000101

READ COB_ID:80000101

READ COB_ID:80000101

Anyone able to help on this problem???

I have troubleshooted this in many different ways and it seems that the C code is working as it should, but I suspect the problem to be with the kernel module for either can_iot or mcp251x which is not correctly receiving the extended flag?
Or it may be with some initialization I need to do before running the kernel module???

@dfrey anyone using the Talon Can IoT board to read CAN data with extended identifiers?
It would be fantastic if someone could share his experience, or possibly someone from SWI…?