Monthly Archives: January 2017

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
    

 

BeagleBoneGreen: Disabling Wi-Fi Power Management Permanently

The operating system is Debian. This is a dirty solution but it does work anyway.

root@beaglebone:~# cat /etc/pm/power.d/wlan0_pm_off
#!/bin/bash

[ -x /sbin/iwconfig ] || exit 0
[ -n "`/sbin/iwconfig 2>/dev/null | grep wlan0`" ] || exit 0

/sbin/iwconfig wlan0 power off
root@beaglebone:~# crontab -l | grep -v "^#"
*/1 * * * * /etc/pm/power.d/wlan0_pm_off
root@beaglebone:~# iwconfig wlan0
wlan0     IEEE 802.11abgn  ESSID:"*****"  
...
          Power Management:off
...

Test CAN connection between BeagleBone and MIDI/CAN converter

1. Enabled CAN at 1Mbps on BeagleBone:

Following operations seem to be necessary every BeagleBone boot. TBD to setup auto configuration on startup.

root@beaglebone:~# echo BB-DCAN1 > /sys/devices/platform/bone_capemgr/slots
root@beaglebone:~# ip link set can0 up type can bitrate 500000
root@beaglebone:~# ip link set can0 up type can bitrate 1000000
root@beaglebone:~# 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:2 errors:0 dropped:2 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10 
          RX bytes:16 (16.0 B)  TX bytes:0 (0.0 B)
          Interrupt:192 
root@beaglebone:~# ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 127) restart-ms 0 
	  bitrate 1000000 sample-point 0.750 
	  tq 83 prop-seg 4 phase-seg1 4 phase-seg2 3 sjw 1
	  c_can: tseg1 2..16 tseg2 1..8 sjw 1..4 brp 1..1024 brp-inc 1
	  clock 24000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          1          1          0         
    RX: bytes  packets  errors  dropped overrun mcast   
    16         2        0       2       0       0      
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0      

2. Wired CAN ports

Used MCP2551 for CAN transceiver.

Pin 24 -> CAN RX
Pin 26 -> CAN TX
Pin 2 -> GND
Pin 6 -> VDD 5V

3. Connected with MIDI/CAN converter via CAN bus

See the picture above.

4. Monitor MIDI/CAN converter via serial interface

naoki-macbook:~ naoki$ screen /dev/tty.usbmodem14244421

5. Monitor packets on BeagleBone and play

root@beaglebone:~# candump can0
can0 100 [3] 09 4A 46
can0 100 [3] 08 4A 00

Serial port monitor:

note on  [ 01 00] 4a
note off [ 01 00] 4a