CAN bus is popular interface in industrial applications especially in automotive. Here described Linux CAN bus support implementation on OpenWrt driven NetSoM. But it might be useful on another devices and Linux distributives.
Schematic inspection and DTS modification.
Adding each new hardware interface to image might be started from DTS. Before this you need check what GPIO used by CAN bus in schematic of device you are working on.
Here CAN bus circuits:
here U3 and U4 are CAN transceivers. Their CANH/CANL pins routed to output connectors. CAN1_TX/CAN1_RX and CAN2_TX/CAN2_RX – to IMX6ULL’s pads:
Here we see that CAN1_TX connected to UART3_CTS pad of IMX6ULL that might be configured as CAN1.TX pin and. In linux hardware configuration we implement using so called DTS.
First we need to add root nodes presenting each interface:
Then time of pinctrl nodes:
It might look like a set of magic numbers and names. It is true. Linux DTS not well documented. So in a case when it can’t shed light to things you need implemented the only way to understand what to do is learning existing code base. Find and grep utils – your best friends. Commits history also might be useful. You may find link to commits implementing CAN bus support to NetSoM at the end of this article.
For example by running (image must be built before you get ability to make a search):
you may discover that there is imx6ul-pinfunc.h header file exists with set of PAD definitions exist:
with following name convention: ARCHITECTURE_PAD_PINNAME_PINFUNCTIONALITY.
Comparing it with schematic above convinces that there is exactly our target definition.
Also you may discover following:
DTS samples! In the easiest case configuration you need already implemented in DTS samples you may just copy and paste it from DTS sample to your DTS.
Unfortunately embedded linux not user friendly so you have to learn on your own.
CAN support enabling in kernel.
After DTS you have to enable hardware support in kernel. You can do it by running
In UI menu navigate to CAN support chapter and enable modules:
Besides this it is also might be useful to enable additional utilities to be included in resulted image to have a tools to test interface you are developing. Later you may exclude them from release image but on development stage they can simplify development process:
Now we are ready to compile and update device firmware. Here explained how you can do that.
Boot device and check logs:
Everything looks fine.
Let’s try to set up CAN interfaces:
and check them using ifconfig:
and send CAN packet to second one:
at first console you should see following:
packet you sent to another interface. It is working!
Next time we continue development process to automate interfaces set up at booting process and will implement separate config called flexcan_ethernet.
Another useful articles
- OpenWrt driven industrial SoM released!
- OpenWrt NetSoM developers guide. How to compile image.
- OpenWrt NetSom users manual. How to configure network.
- OpenWrt NetSoM users manual. How to configure WI-FI in STA+AP mode.
- OpenWrt NetSoM developers guide. Linux CAN bus. Part 1.
- OpenWrt NetSoM developers guide. Linux CAN bus. Part 2.
- OpenWrt NetSoM users guide. Recording audio to file and playing from.
- OpenWrt NetSoM users guide. Video streaming solution.
- OpenWrt NetSoM users guide. VOIP solution using SIP protocol.
- OpenWrt NetSom developers guide. MicroSD card support.
- OpenWrt NetSoM users guide. Running Alexa Voice service.
- OpenWrt NetSoM users guide. Lorawan configuration using Web Interface.
- OpenWrt NetSoM user guide. 3G network configuration.