Open1722 libraries being written in C can be compiled easily into Zephyr applications. An example here is the acf-can-bridge.. A brief explanation of how to create Zephyr applications including Open1722 is as follows:
Install the Zephyr SDK and toolchain as mentioned in their Getting Started Guide.
The acf-can-bridge application is made as a freestanding application, i.e., it is located outside the Zephyr workspace. For more information on such applications, refer Zephyr build system.
To build freestanding Zephyr applications, refer the blog article.
For this, we will source the Zephyr dependencies in the terminal:
source ~/zephyrproject/.venv/bin/activate
source ~/zephyrproject/zephyr/zephyr-env.sh
Subsequently, you can build the application using west. We have integrated the build dependencies of the acf-can-bridge application into the main CMake of the project. Hence build commands are executed from the main folder of the repository.
west build --pristine -b <board_name> . -- -DCONF_FILE=./examples/acf-can/zephyr/prj.conf -DOPEN1722_ZEPHYR_APP=acf-can-bridge -DDTC_OVERLAY_FILE=<overlay file if reqd.>
west build -t run # OR west build -t flash
The parameters of the application (e.g. use UDP or the TSCF format) can be set from the prj.conf.
In theory, this should work with any supported Zephyr boards having a CAN and an Ethernet interface. You may need to adjust the name of the interface in the corresponding device tree or code. We have tested the application with following Zephyr boards.
- native_sim (Use overlay file: native_sim.overlay)
- arduino_portenta_h7 (Use overlay file: arduino_portenta_h7.overlay)
west build -b native_sim -d build_native_sim . -- -DCONF_FILE=examples/acf-can/zephyr/prj.conf -DOPEN1722_ZEPHYR_APP=acf-can-bridge -DDTC_OVERLAY_FILE=examples/acf-can/zephyr/boards/native_sim.overlay # For native_sim
west build -b arduino_portenta_h7/stm32h747xx/m7 -d build_arduino . -- -DCONF_FILE=examples/acf-can/zephyr/prj.conf -DOPEN1722_ZEPHYR_APP=acf-can-bridge -DDTC_OVERLAY_FILE=examples/acf-can/zephyr/boards/arduino_portenta_h7.overlay # For arduino_portenta_h7
- arduino_portenta_h7 (Use overlay file: arduino_portenta_h7.overlay)
To test on native sim, we first create an Ethernet interface and a CAN interface for the simulator.
For creation of an Ethernet interface, have a look at the net-tools repository from zephyrproject. Clone this repository and execute the net-setup script in another terminal.
./net-setup.sh
This creates the zeth Ethernet interface. You must also create a virtual CAN interface based on the devicetree (vcan0) of the native_sim.
With a virtual Ethernet and CAN interface, the application can be executed on native_sim from the main repository folder as follows:
west build -b native_sim . -- -DCONF_FILE=examples/acf-can/zephyr/prj.conf -DOPEN1722_ZEPHYR_APP=acf-can-bridge -DDTC_OVERLAY_FILE=examples/acf-can/zephyr/boards/native_sim.overlay
west build -t run # Or ./<build_directory>/zephyr/zephyr.exe
For testing, one can use can-utils to generate traffic on vcan0 and observe the Ethernet packets on zeth and vice-versa.