Skip to content

Commit 81f5a80

Browse files
henrikbrixandersenfabiobaltieri
authored andcommitted
snippets: add snippet for enabling SocketCAN support on native_sim
Add snippet for enabling Linux SocketCAN support on the native simulator. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 69a3ed2 commit 81f5a80

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

MAINTAINERS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ Documentation Infrastructure:
12511251
- samples/net/sockets/can/
12521252
- samples/subsys/canbus/
12531253
- scripts/west_commands/runners/canopen_program.py
1254+
- snippets/socketcan-native-sim/
12541255
- subsys/canbus/
12551256
- subsys/net/l2/canbus/
12561257
- tests/drivers/build_all/can/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. _snippet-socketcan-native-sim:
2+
3+
SocketCAN on Native Simulator Snippet (socketcan-native-sim)
4+
############################################################
5+
6+
.. code-block:: console
7+
8+
west build -S socketcan-native-sim [...]
9+
10+
Overview
11+
********
12+
13+
This snippet allows to configure Controller Area Network (CAN) samples with Linux SocketCAN support
14+
on :ref:`native_sim`.
15+
16+
By default, the native simulator expects a SocketCAN network device called ``zcan0`` (specified in
17+
:zephyr_file:`boards/native/native_sim/native_sim.dts`). This name can be added as an alternative
18+
name for an existing SocketCAN network device (here, a newly created virtual CAN network device
19+
``vcan0``) using a command like the following:
20+
21+
.. code-block:: console
22+
23+
sudo modprobe vcan
24+
sudo ip link add dev vcan0 type vcan
25+
sudo ip link property add dev vcan0 altname zcan0
26+
27+
The SocketCAN device must be configured and brought up before running the native simulator:
28+
29+
.. code-block:: console
30+
31+
sudo ip link set vcan0 up
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: socketcan-native-sim
2+
append:
3+
EXTRA_CONF_FILE: socketcan-native-sim.conf
4+
EXTRA_DTC_OVERLAY_FILE: socketcan-native-sim.overlay
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_CAN=y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Henrik Brix Andersen <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,canbus = &can0;
10+
};
11+
};
12+
13+
&can0 {
14+
status = "okay";
15+
};

0 commit comments

Comments
 (0)