Beaglebone Green Canbus

Hi,

One of my colleagues suggested using overlays to get the desired result:

Loading overlays from u-boot procedure is standard, enable overlays and the desired overlay to resin-boot/uEnv.txt, for instance:

enable_uboot_overlays=1

uboot_overlay_addr0=/boot/overlays/BB-CAN0-00A0.dtbo

U-boot will then confirm if the dtbo is loaded, on development images it can be observed on the serial console:

uboot_overlays: [fdt_buffer=0x60000] ...

uboot_overlays: loading /boot/overlays/BB-CAN0-00A0.dtbo ...

849 bytes read in 75 ms (10.7 KiB/s)

uboot_overlays: loading /boot/overlays/BB-BONE-eMMC1-01-00A0.dtbo ...

1083 bytes read in 105 ms (9.8 KiB/s)

uboot_overlays: loading /boot/overlays/BB-BBGW-WL1835-00A0.dtbo ...

4515 bytes read in 110 ms (40 KiB/s)

Can you tell us what version of balenaOS you’re running on your BB Green?

Thanks,
John

Client:
 Version:           18.09.8-dev
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        80d443d400dcc85e87322f72866593b46bafb157
 Built:             Mon Sep 23 15:53:28 2019
 OS/Arch:           linux/arm
 Experimental:      false

Server:
 Engine:
  Version:          18.09.8-dev
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       80d443d400dcc85e87322f72866593b46bafb157
  Built:            Mon Sep 23 15:53:28 2019
  OS/Arch:          linux/arm
  Experimental:     true

Would you be able to help me with an example Dockerfile that can perform this overlay?

Hi Drey,

Enabling the Device Tree Overlays are not actually part of the Dockerfile, they are handled elsewhere, and are read into the operating system at boot time. The documentation for this piece of the puzzle is located here: https://www.balena.io/docs/reference/OS/advanced/#setting-device-tree-overlays-dtoverlay-and-parameters-dtparam

To simplify it though, the Device Tree Overlays will enable / add the additional functionality to the device. So, I am not entirely surprised that your script will fail if the OS is not exposing the proper underlying hardware. Thus, the next step is to get the proper device tree overlay loaded. As John mentioned, the uEnv.txt is where this needs to happen. I don’t have a Beaglebone, so I’ll try my best, but ultimately you may have to do some experimentation of your own.

I am assuming you are using an SD Card, so, remove it from the Beaglebone and instead insert it into your laptop or desktop PC. Open up the ‘resin-boot’ partition, which will have all of the bootup files the board uses. Look for ‘uEnv.txt’, and open that with a text editor. Insert these two lines anywhere in the file:

enable_uboot_overlays=1
uboot_overlay_addr0=/boot/overlays/BB-CAN0-00A0.dtbo

Save the file, unmount / eject the SD Card, re-insert to the Beaglebone, and boot it back up. Hopefully your CAN bus will now be available to the containers and you can proceed.

Thank you @dtischler I will give that a try. In the future when I deploy this to many vehicles, how do I get those files on the original sd card image? It would suck to have to do this process with each vehicle.

I tried to edit uEnv.txt. Unfortunately I am not using an sd card on the beaglebone and therefore have no method to plug in and edit a file. I only have the original sd card I used to upload the balenaengine to the beaglebone and this has a uEnv.txt_internal on it but something tells me this is incorrect. There must be a way to turn this CAN on. I have a swarm of vehicles (1000+) I was hoping to install these on but the very first step I have run into so many issues. I see that raspberry pi is significantly more used and support by balena however that doesn’t offer a CAN bus, it only offers SPI bus versions of CAN which I don’t want to use.

12.09.20 11:40:14 (-0700)  main  ./somescript.sh: line 2: /sys/devices/platform/bone_capemgr/slots: Permission denied
12.09.20 11:40:14 (-0700)  main  ./somescript.sh: line 3: /sys/devices/platform/bone_capemgr/slots: Permission denied
12.09.20 11:40:14 (-0700)  main  RTNETLINK answers: Device or resource busy
12.09.20 11:40:14 (-0700)  main  Cannot find device "can1"

I now have a new error after editing the uEnv.txt_internal. Don’t know if this is better or worse but maybe it will help diagnose some things.

Also

/sys/devices/platform/bone_capemgr/slots 

is now no longer in the bone_capemgr directory. So obviously editing the uEnv.txt_internal was a bad idea. Unfortunately the resin-boot partition doesn’t exist on the sd card image so it’s not looking promising. Hopefully someone who has programmed the beaglebone green at some point can find this thread and guide me towards a quick resolution. I unfortunately get a quota on this site for the number of times I can post which is disappointing.

Ok I am making some progress. Here is where I am at. I have used

dmesg

to see the output while booting up the kernel. I found these lines which are relevant to setting up the CAN pins

[    1.416886] CAN device driver interface
[    1.421329] pinctrl-single 44e10800.pinmux: pin PIN95 already requested by ocp:P9_19_pinmux; cannot claim for 481cc000.can
[    1.433033] pinctrl-single 44e10800.pinmux: pin-95 (481cc000.can) status -22
[    1.440493] pinctrl-single 44e10800.pinmux: could not request pin 95 (PIN95) from group pinmux_dcan0_pins  on device pinctrl-single
[    1.452832] c_can_platform 481cc000.can: Error applying setting, reverse things back
[    1.460943] c_can_platform: probe of 481cc000.can failed with error -22

It appears something else is taking over those pins. I am now going to try disabling a bunch of stuff to try to see if the problem gets resolved. The good news however is that by editing the uEnv_internal.txt file on the sd boot card I was able to get can to start setting up.

[    2.141915] bone_capemgr bone_capemgr: Baseboard: 'A335BNLT,BBG1,BBG218030526'
[    2.149547] bone_capemgr bone_capemgr: compatible-baseboard=ti,beaglebone-black - #slots=4
[    2.184491] bone_capemgr bone_capemgr: slot #0: No cape found
[    2.215739] bone_capemgr bone_capemgr: slot #1: No cape found
[    2.248587] bone_capemgr bone_capemgr: slot #2: No cape found
[    2.279853] bone_capemgr bone_capemgr: slot #3: No cape found
[    2.285916] bone_capemgr bone_capemgr: enabled_partno PARTNO 'CAN0' VER 'N/A' PR '0'
[    2.294002] bone_capemgr bone_capemgr: slot #4: override
[    2.299561] bone_capemgr bone_capemgr: Using override eeprom data at slot 4
[    2.306837] bone_capemgr bone_capemgr: slot #4: 'Override Board Name,00A0,Override Manuf,CAN0'
[    2.315897] bone_capemgr bone_capemgr: enabled_partno PARTNO 'CAN1' VER 'N/A' PR '0'
[    2.323990] bone_capemgr bone_capemgr: slot #5: override
[    2.329544] bone_capemgr bone_capemgr: Using override eeprom data at slot 5
[    2.336816] bone_capemgr bone_capemgr: slot #5: 'Override Board Name,00A0,Override Manuf,CAN1'
[    2.346225] bone_capemgr bone_capemgr: initialized OK.
[    2.355635] bone_capemgr bone_capemgr: loader: failed to load slot-5 CAN1:00A0 (prio 0)
[    2.355824] bone_capemgr bone_capemgr: loader: failed to load slot-4 CAN0:00A0 (prio 0)

Well I have disabled everything now and you can see that the capemgr is installing can0 and can1 however something is overridding slots. What is the cause of this?

Hi Drey

I’ll try to answer your questions one by one -

  • if you are looking at OS level customizations, you can always bake your own images for devices. See our docs for getting started with that here - https://www.balena.io/os/docs/custom-build/
  • You haven’t asked for this specifically, but one step that you can go further with the above is that you can preload your application with the image that you want to run so that it won’t have to download it on the first boot. We call this preloading - more about it here : https://www.balena.io/docs/reference/balena-cli/#preload-image
  • After you have flashed the image on the emmc using the SD card, what happens when you connect the device to your laptop using USB? Do you see any specific device partitions mount on your laptop?
  • I am a little lost on this thread, so help me out here : are your scripts or something else in your app using the capemgr utility to mount the capes? Or are you only relying on the uEnv method?

Hi, can you give it a quick test and also disable i2c2 first? I believe this is clashing with can0.
So you would add the following to uEnv.txt_internal:

enable_uboot_overlays=1

uboot_overlay_addr0=/boot/overlays/BB-I2C2N-00A0.dtbo

uboot_overlay_addr1=/boot/overlays/BB-CAN0-00A0.dtbo

@anujdeshpande Thank you for the response. Thank you for the link to baking my own image! That may prove to be very useful.

To answer your questions:
When connected with a usb nothing enumerates or mounts to my laptop.
I am not trying to use capemgr since a lot of forums online have declared that to be an outdated approach. I did at one point attempt to use it and this was the cause for some capemgr output as seen above.

@floion Thank you for the response as well. I have replaced the contents of uEnv.txt_internal with the 3 lines you provided and I still see the error. Here are the pingroups in the beaglebone green.

root@7f1b567:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat pingroups registered pin groups:
group: pinmux_uart0_pins
pin 92 (PIN92)
pin 93 (PIN93)

group: pinmux_P9_19_default_pin
pin 95 (PIN95)

group: pinmux_P9_19_gpio_pin
pin 95 (PIN95)

group: pinmux_P9_19_gpio_pu_pin
pin 95 (PIN95)

group: pinmux_P9_19_gpio_pd_pin
pin 95 (PIN95)

group: pinmux_P9_19_gpio_input_pin
pin 95 (PIN95)

group: pinmux_P9_19_spi_cs_pin
pin 95 (PIN95)

group: pinmux_P9_19_can_pin
pin 95 (PIN95)

group: pinmux_P9_19_i2c_pin
pin 95 (PIN95)

group: pinmux_P9_19_pru_uart_pin
pin 95 (PIN95)

group: pinmux_P9_19_timer_pin
pin 95 (PIN95)

group: pinmux_P9_20_default_pin
pin 94 (PIN94)

group: pinmux_P9_20_gpio_pin
pin 94 (PIN94)

group: pinmux_P9_20_gpio_pu_pin
pin 94 (PIN94)

group: pinmux_P9_20_gpio_pd_pin
pin 94 (PIN94)

group: pinmux_P9_20_gpio_input_pin
pin 94 (PIN94)

group: pinmux_P9_20_spi_cs_pin
pin 94 (PIN94)

group: pinmux_P9_20_can_pin
pin 94 (PIN94)

group: pinmux_P9_20_i2c_pin
pin 94 (PIN94)

group: pinmux_P9_20_pru_uart_pin
pin 94 (PIN94)

group: pinmux_P9_20_timer_pin
pin 94 (PIN94)

group: pinmux_dcan0_pins
pin 95 (PIN95)
pin 94 (PIN94)

group: cpsw_default
pin 66 (PIN66)
pin 67 (PIN67)
pin 68 (PIN68)
pin 69 (PIN69)
pin 70 (PIN70)
pin 71 (PIN71)
pin 72 (PIN72)
pin 73 (PIN73)
pin 74 (PIN74)
pin 75 (PIN75)
pin 76 (PIN76)
pin 77 (PIN77)
pin 78 (PIN78)
pin 79 (PIN79)
pin 80 (PIN80)

group: cpsw_sleep
pin 66 (PIN66)
pin 67 (PIN67)
pin 68 (PIN68)
pin 69 (PIN69)
pin 70 (PIN70)
pin 71 (PIN71)
pin 72 (PIN72)
pin 73 (PIN73)
pin 74 (PIN74)
pin 75 (PIN75)
pin 76 (PIN76)
pin 77 (PIN77)
pin 78 (PIN78)
pin 79 (PIN79)
pin 80 (PIN80)

group: davinci_mdio_default
pin 82 (PIN82)
pin 83 (PIN83)

group: davinci_mdio_sleep
pin 82 (PIN82)
pin 83 (PIN83)

group: pinmux_mmc1_pins
pin 88 (PIN88)
pin 63 (PIN63)
pin 62 (PIN62)
pin 61 (PIN61)
pin 60 (PIN60)
pin 65 (PIN65)
pin 64 (PIN64)

group: pinmux_emmc_pins
pin 32 (PIN32)
pin 33 (PIN33)
pin 0 (PIN0)
pin 1 (PIN1)
pin 2 (PIN2)
pin 3 (PIN3)
pin 4 (PIN4)
pin 5 (PIN5)
pin 6 (PIN6)
pin 7 (PIN7)

group: user_leds_s0
pin 21 (PIN21)
pin 22 (PIN22)
pin 23 (PIN23)
pin 24 (PIN24)

group: pinmux_i2c0_pins
pin 98 (PIN98)
pin 99 (PIN99)

Also here is a useful bit of info from

dmesg
[    1.416316] CAN device driver interface
[    1.420756] pinctrl-single 44e10800.pinmux: pin PIN95 already requested by ocp:P9_19_pinmux; cannot claim for 481cc000.can
[    1.432450] pinctrl-single 44e10800.pinmux: pin-95 (481cc000.can) status -22
[    1.439851] pinctrl-single 44e10800.pinmux: could not request pin 95 (PIN95) from group pinmux_dcan0_pins  on device pinctrl-single
[    1.452189] c_can_platform 481cc000.can: Error applying setting, reverse things back
[    1.460299] c_can_platform: probe of 481cc000.can failed with error -22

Hey Drey, just an update. We can see how much hard work your putting in to getting this working with docker and balena. The team is aware of the issues you are having. Two of our engineers are now working on a solution to help you get this over the line. A member of our customer success team will also be in touch to check if we can assist you in any other way.

1 Like

This is great news @codewithcheese. I am eager to get it working due to the vast quantity of (already purchased) beaglebone greens I have sitting on my desk :slight_smile:

Hi,

Can you please check with the new 2.56.0+rev1 image from the staging dashboard and again add these to uEnv.txt:

Then, from a container that has ENV UDEV=1 try

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

and see if the can0 interface is brought up?

@acostach I am unable to update to 2.56+rev1. The only image I am allowed to download to the beaglebone green is 2.43+rev2.

Hi, My team-mate was suggesting to test an OS release that is currently only available on staging ( https://dashboard.balena-staging.com/ ) and in the process of being released on production to make sure it covers the issues you described

1 Like

Well it finally happened! Looks like whatever changes you made to 2.56+rev1 is exactly what I needed to get can0 working. Thank you every one for your help! Also, when do you expect to push this out of staging?

can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 46  

Also when do you expect to see a beaglebone AI image available?

Hi there – glad to hear things are working better for you! I will check with our engineers about when we can expect this OS version to be released to production, and we’ll get back to you.

As for support for the BeagleboneAI, I’ve created an issue for us to track this here: https://github.com/balena-os/balena-beaglebone/issues/241. Please feel free to add any details of your use case there, and to subscribe to the issue for updates.

All the best,
Hugh

1 Like