1 |
$ sudo apt-get install manpages-dev manpages-posix-dev |
manpages-dev: Manual pages about using GNU/Linux for development
manpages-posix-dev: Manual pages about using a POSIX system for development
1 |
$ sudo apt-get install manpages-dev manpages-posix-dev |
manpages-dev: Manual pages about using GNU/Linux for development
manpages-posix-dev: Manual pages about using a POSIX system for development
Three steps:
Add following line in /etc/default/capemgr
1 |
CAPE=BB-DCAN1 |
Add following lines in /etc/network/interfaces
1 2 3 4 5 |
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 |
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.
1 2 3 4 5 |
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.
1 2 |
vi /lib/systemd/startup.service |
1 2 3 4 5 6 7 8 |
[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 |
1 2 3 |
cd /etc/systemd/system/ ln -s /lib/systemd/startup.service startup.service |
1 2 3 4 |
systemctl daemon-reload systemctl start scriptname.service systemctl enable scriptname.service |
1 2 |
reboot |
The operating system is Debian. This is a dirty solution but it does work anyway.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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 ... |
Following operations seem to be necessary every BeagleBone boot. TBD to setup auto configuration on startup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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 |
Used MCP2551 for CAN transceiver.
1 2 3 4 |
Pin 24 -> CAN RX Pin 26 -> CAN TX Pin 2 -> GND Pin 6 -> VDD 5V |
See the picture above.
1 |
naoki-macbook:~ naoki$ screen /dev/tty.usbmodem14244421 |
1 2 3 |
root@beaglebone:~# candump can0 can0 100 [3] 09 4A 46 can0 100 [3] 08 4A 00 |
Serial port monitor:
1 2 |
note on [ 01 00] 4a note off [ 01 00] 4a |
I’ve tried to enable CAN on my BeagleBone Green board. I had to stop the work before verification, because my logic analyzer is unavailable now. I record what I did in this article to make things reproducible when the logic analyzer is back.
There are several helpful links:
http://www.embedded-things.com/bbb/enable-canbus-on-the-beaglebone-black/
http://electronics.stackexchange.com/questions/195416/beaglebone-black-can-bus-setup
Readings to understand device tree overlay:
Device Tree for Dummies:
http://events.linuxfoundation.jp/sites/events/files/slides/petazzoni-device-tree-dummies.pdf
Device Tree Overlays (in adafruit)
https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/device-tree-overlays
Here are what I did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# make a workspace root@beaglebone:~# mkdir can root@beaglebone:~# cd can root@beaglebone:~/can# pwd /root/can # check if CAN is enabled ... no root@beaglebone:~/can# dmesg | grep can # take backup of the original device tree blob file for CAN root@beaglebone:~/can# cp /lib/firmware/BB-CAN1-00A0.dtbo BB-CAN1-00A0.dtbo.orig # make the device tree overlay root@beaglebone:~/can# vi BB-DCAN1-00A0.dts root@beaglebone:~/can# cat !$ cat BB-DCAN1-00A0.dts /dts-v1/; /plugin/; / { compatible = "ti,beaglebone", "ti,beaglebone-black"; /* identification */ part-number = "dcan1pinmux"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { dcan1_pins_s0: dcan1_pins_s0 { pinctrl-single,pins = < 0x180 0x12 /* d_can1_tx, SLEWCTRL_FAST | INPUT_PULLUP | MODE2 */ 0x184 0x32 /* d_can1_rx, SLEWCTRL_FAST | RECV_ENABLE | INPUT_PULLUP | MODE2 */ >; }; }; }; fragment@1 { target = <&dcan1>; __overlay__ { #address-cells = <1>; #size-cells = <0>; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&dcan1_pins_s0>; }; }; }; # install the new device tree blob for CAN root@beaglebone:~/can# dtc -O dtb -o BB-DCAN1-00A0.dtbo -b 0 -@ BB-DCAN1-00A0.dts root@beaglebone:~/can# ls BB-CAN1-00A0.dtbo.orig BB-DCAN1-00A0.dtbo BB-DCAN1-00A0.dts root@beaglebone:~/can# cp BB-DCAN1-00A0.dtbo /lib/firmware/ root@beaglebone:~/can# cmp BB-DCAN1-00A0.dtbo /lib/firmware/BB-DCAN1-00A0.dtbo # add the device root@beaglebone:/lib/firmware# cat /sys/devices/platform/bone_capemgr/slots 0: PF---- -1 1: PF---- -1 2: PF---- -1 3: PF---- -1 root@beaglebone:~/can# echo BB-DCAN1 > /sys/devices/platform/bone_capemgr/slots root@beaglebone:~/can# cat !$ cat /sys/devices/platform/bone_capemgr/slots 0: PF---- -1 1: PF---- -1 2: PF---- -1 3: PF---- -1 4: P-O-L- 0 Override Board Name,00A0,Override Manuf,BB-DCAN1 # check dmesg ... looks fine root@beaglebone:~/can# dmesg | tail -n15 [ 25.499860] wlan0: send auth to 00:1d:73:33:47:a0 (try 1/3) [ 25.522620] wlan0: authenticated [ 25.524815] wl18xx_driver wl18xx.2.auto wlan0: disabling HT/VHT due to WEP/TKIP use [ 25.528911] wlan0: associate with 00:1d:73:33:47:a0 (try 1/3) [ 25.538576] wlan0: RX AssocResp from 00:1d:73:33:47:a0 (capab=0x431 status=0 aid=4) [ 25.764831] wlan0: associated [ 25.765114] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready [ 26.579282] wlcore: Association completed. [ 3395.588267] bone_capemgr bone_capemgr: part_number 'BB-DCAN1', version 'N/A' [ 3395.588337] bone_capemgr bone_capemgr: slot #4: override [ 3395.588380] bone_capemgr bone_capemgr: Using override eeprom data at slot 4 [ 3395.588425] bone_capemgr bone_capemgr: slot #4: 'Override Board Name,00A0,Override Manuf,BB-DCAN1' [ 3395.613523] bone_capemgr bone_capemgr: slot #4: dtbo 'BB-DCAN1-00A0.dtbo' loaded; overlay id #0 [ 3395.648848] CAN device driver interface [ 3395.689001] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=192) # load CAN modules root@beaglebone:~/can# sudo modprobe can root@beaglebone:~/can# sudo modprobe can-dev root@beaglebone:~/can# sudo modprobe can-raw root@beaglebone:~/can# lsmod | grep can can_raw 5852 0 can 28397 1 can_raw c_can_platform 6602 0 c_can 9577 1 c_can_platform can_dev 11663 1 c_can # Startup the CAN interface. Set CAN channel rate 500kbps. root@beaglebone:~# ip link set can0 up type can bitrate 500000 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: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) Interrupt:192 # Check the device status. Status UNKNOWN doesn't sound right... root@beaglebone:~/can# 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 0) restart-ms 0 bitrate 125000 sample-point 0.875 tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 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 0 0 0 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0 |
Then I have to stop here.
Use connmanctl as described in /etc/network/interfaces.
1 2 3 4 5 6 7 8 9 10 |
root@beaglebone:~# connmanctl connmanctl> tether wifi disable Error disabling wifi tethering: Already disabled connmanctl> scan wifi Scan completed for wifi connmanctl> services Analog20 wifi_xxxxxxxxxxxxxxxxxxxxxxxxxxx_managed_psk connmanctl> agent on Agent registered connmanctl> connect wifi_xxxxxxxxxxxxxxxxxxxxxxxxxxx_managed_psk |
… and so on
Following links give useful information:
http://xx-prime.hatenablog.com/entry/2016/08/13/012059 (in Japanese)
https://www.mail-archive.com/beagleboard@googlegroups.com/msg40785.html
The wlan0 device power management can be turned off by
1 |
# iwconfig wlan0 power off |
TBD how to turn this off permanently.
Following link is helpful to know how to backup disks in several styles:
https://wiki.archlinux.org/index.php/disk_cloning
Useful when the SSH access has a problem:
1 2 |
$ ls /dev/tty.* $ screen |