Close

The right CAN bus overlay for the ATOM Light

A project log for Industrial Network Playground

This is a remote playground to learn more about different types of software components that can be used in industrial setups.

nikolaNikola 12/11/2023 at 21:020 Comments

The CAN bus modules are only connected to two ATOM HUB SwitchDs. The "intelligence" in one SwitchD is an ATOM Lite. It contains the same ESP32-PICO as the M5StickC Plus, but the gpio pins are used differently.

As many of you may know, Zephyr OS needs to know what target it is built for and in what setting. So not only the MCU, but also the used data buses and some peripherals.
Unfortunately, the ATOM Lite is currently not available as a target

https://github.com/zephyrproject-rtos/zephyr/tree/main/boards/xtensa/
but the M5StickC Plus can be used.

To build the

https://github.com/zephyrproject-rtos/zephyr/tree/main/modules/canopennode
example, the following command can be used


$ west build -b m5stickc_plus samples/modules/canopennode -- -DCONF_FILE="prj_no_storage.conf"

The only thing that needs to be added to the build is the overlay file that enables the CAN module and sets the RX/TX pins.
How to use a device tree overlay in Zephyr can be found here

https://docs.zephyrproject.org/latest/build/dts/howtos.html#set-devicetree-overlays

NOTE: The CAN bus is called the TWAI (Two-Wire Automotive Interface) on the ESP32.

To enable the TWAI in the ATOM Lite, the following lines are required in the overlay file:

&twai {
        status = "okay";
        pinctrl-0 = <&twai_default>;
        pinctrl-names = "default";
        bus-speed = <125000>;
    
        can-transceiver {
            max-bitrate = <1000000>;
        };
    };
    
    &pinctrl {
        twai_default: twai_default {
            group1 {
                pinmux = <TWAI_RX_GPIO32>,
                        <TWAI_TX_GPIO26>;
            };
        };
    };

Maybe when I start using the ATOM Lite more with Zephyr, I will try to create a target for it and commit it to source. Like I did with the nRF52840 MDK USB dongle

https://github.com/zephyrproject-rtos/zephyr/tree/main/boards/arm/nrf52840_mdk_usb_dongle

Discussions