Skip to content

mike-sul/socketcan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SocketCAN: simple test

Prerequisite

  1. Linux kernel > 2.6.25

    ls -l /lib/modules/$(uname -r)/kernel/net/can
    -rw-r--r-- 1 root root 29673 Sep  4 23:11 can-bcm.ko
    -rw-r--r-- 1 root root 21321 Sep  4 23:11 can-gw.ko
    -rw-r--r-- 1 root root 36417 Sep  4 23:11 can.ko
    -rw-r--r-- 1 root root 18297 Sep  4 23:11 can-raw.ko
  2. Load the CAN modules

    modprobe can
    modprobe can-dev
    modprobe can-raw
    modprobe vcan
  3. Configure a virtual CAN interface

    ip link add dev vcan0 type vcan
    ip link set up vcan0
    ip link show vcan0

Build

mkdir build && cd build
cmake ..
make
./socketcan-test

SocketCAN usage and testing on QEMU VMs baked by Yocto

Kernel config

TODO: Set the required kernel configuration options from the meta-updater recipe

QEMU

The QEMU version that is installed on Ubuntu by default does not support CAN related functionality.

msul@bagger:~$ qemu-system-x86_64 --version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.18)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

The QEMU version that includes this commit https://github.com/qemu/qemu/commit/321af2f5b8285d547468c505fc8ed66b9c1b1907 is required. It means any version >= v2.12.0-rc0 should do the trick

TODO: update QEMU on CI machines as well as each developer should update it too

Run VM in QEMU

Run QEMU VM with following additional options that turns 'CAN' stuff

-object can-bus,id=canbus0 -object can-host-socketcan,id=canhost0,if=vcan0,canbus=canbus0  -device kvaser_pci,canbus=canbus0

Or in case of meta-updater add the following into scripts/qemucommand.py::command_line()

cmdline += ["-object", "can-bus,id=canbus0", "-object", "can-host-socketcan,id=canhost0,if=vcan0,canbus=canbus0", "-device", "kvaser_pci,canbus=canbus0"]

TODO: update scripts/qemucommand.py to support the CAN stuff

Configure SocketCAN interface on VM

ip link set can0 type can bitrate 1000000
ip link set can0 up

TODO: Update meta-updater recipe to automate the socketcan interface configuration

Nice to have

In order to debug & troubleshoot applications that communicates via CAN/SocketCAN as well as CAN interface itself it’s highly recommended to install can-utils and kernel-modules

IMAGE_INSTALL_append += " can-utils kernel-modules "

TODO: update meta-updater recipe to include these tools

About

SocketCAN test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published