BeagleBone Green: Enable CAN on Startup

Three steps:

  1. Enable CAN overlay by configuring cape manager
  2. Configure network interface
  3. Install startup program

1. Enable CAN overlay

Add following line in /etc/default/capemgr

CAPE=BB-DCAN1

2. Configure network interface

Add following lines in /etc/network/interfaces

auto can0
iface can0 inet manual
    pre-up /sbin/ip link set $IFACE type can bitrate 1000000 listen-only off
    up /sbin/ifconfig $IFACE up
    down /sbin/ifconfig $IFACE down

3. Install startup program

Setting the CAN interface to /etc/network/interface does not enable the CAN interface on startup for some reason. In order to workaround this problem, I installed a startup program as follows.

Following link was helpful:

Running a script on Beaglebone Black boot/ startup

The startup script to run on startup is as follows. This script also turns off wi-fi power management, thus I removed a cron entry I added before to disable the power management.

naoki@beaglebone:~$ cat /usr/bin/startup.sh
#!/bin/sh

ifup -a
/sbin/iwconfig wlan0 power off

Following are the steps to create and enable a service that runs on startup.

  • Create the service
    vi /lib/systemd/startup.service
    
  • Edit the above file as necessary to invoke the different functionalities like network. Enable these only if the code needs that particular service. Disable unwanted ones to decrease boot time.
    [Unit]
    Description=runs startup script after startup
    After=syslog.target network.target
    [Service]
    Type=simple
    ExecStart=/usr/bin/startup.sh
    [Install]
    WantedBy=multi-user.target
  • Create a symbolic link to let the device know the location of the service.
    cd /etc/systemd/system/
    ln -s /lib/systemd/startup.service startup.service
    
  • Make systemd reload the configuration file, start the service immediately (helps to see if the service is functioning properly) and enable the unit files specified in the command line.
    systemctl daemon-reload
    systemctl start scriptname.service
    systemctl enable scriptname.service
    
  • Restart BBB immediately to see if it runs as intended.
    reboot
    

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.