boards/sim: add CAN support and configuration

Add host CAN support for sim target.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
p-szafonimateusz 2025-03-13 12:57:34 +01:00 committed by Xiang Xiao
parent 76e1b80076
commit 7e99c9582b
5 changed files with 163 additions and 0 deletions

View file

@ -1886,6 +1886,66 @@ NOTES:
you will find this annoying. You can disable the password protection
by de-selecting CONFIG_NSH_CONSOLE_LOGIN=y.
can
---
This is a configuration with simulated CAN support. Both CAN character driver
and SocketCAN are enabled and use the host ``vcan0`` interface.
The ``vcan0`` host interface must be available when NuttX is started.
For the CAN character device, there is ``examples/can`` application enabled in
read-only mode.
Additionally, SocketCAN ``candump`` and ``cansend`` utils are enabled.
Below is an example of receiving CAN frames from host to NuttX.
Requirement: ``cansequence`` tool from ``linux-can/can-utils``
1. Create virtual CAN on host::
ip link add dev can0 type vcan
ifconfig can0 up
2. Run NuttX::
./nuttx
3. Bring up can0 on NuttX::
nsh> ifup can0
ifup can0...OK
4. read CAN messages from SocketCAN on NuttX::
nsh> candump can0
5. send CAN messages from host to NuttX::
$ cansequence can0
6. frames from host should be received on NuttX::
nsh> candump can0
can0 002 [1] 00
can0 002 [1] 01
can0 002 [1] 02
can0 002 [1] 03
can0 002 [1] 04
can0 002 [1] 05
can0 002 [1] 06
can0 002 [1] 07
can0 002 [1] 08
can0 002 [1] 09
can0 002 [1] 0A
can0 002 [1] 0B
can0 002 [1] 0C
can0 002 [1] 0D
can0 002 [1] 0E
can0 002 [1] 0F
can0 002 [1] 10
can0 002 [1] 11
can0 002 [1] 12
README.txt
==========

View file

@ -103,6 +103,21 @@ You should see some squares in different colors displayed in remmina:
remmina connected to sim's VNC Server
Running Simulated CAN
=====================
The simulator supports CAN support via SocketCAN on the host.
The CAN interface of the host must be properly configured::
ip link set can0 type can bitrate 1000000
ip link set can0 up
Virtual CAN interface can be used as well::
ip link add dev can0 type vcan
ifconfig can0 up
Supported Boards
================

View file

@ -63,3 +63,23 @@ config SIM_RNDIS_MACADDR
with this selection.
endif
if SIM_CANDEV_CHAR
config SIM_CANDEV_CHAR_IDX
int "CAN chardev interface"
default 0
---help---
Host SocketCAN network interface used by simulated CAN character driver
endif
if SIM_CANDEV_SOCK
config SIM_CANDEV_SOCK_IDX
int "CAN SocketCAN interface"
default 0
---help---
Host SocketCAN network interface used by simulated SocketCAN
endif

View file

@ -0,0 +1,52 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
CONFIG_ALLOW_BSD_COMPONENTS=y
CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_CHIP="sim"
CONFIG_ARCH_SIM=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
CONFIG_BUILTIN=y
CONFIG_CAN=y
CONFIG_CANUTILS_CANDUMP=y
CONFIG_CANUTILS_CANSEND=y
CONFIG_CANUTILS_LIBCANUTILS=y
CONFIG_CAN_EXTID=y
CONFIG_CAN_FD=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXAMPLES_CAN=y
CONFIG_EXAMPLES_CAN_READ=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_NET=y
CONFIG_NETDEV_IFINDEX=y
CONFIG_NET_CAN=y
CONFIG_NET_CAN_ERRORS=y
CONFIG_NET_CAN_EXTID=y
CONFIG_NET_CAN_SOCK_OPTS=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_PS=y
CONFIG_NSH_READLINE=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_EVENTS=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_WAITPID=y
CONFIG_SIM_CANDEV=y
CONFIG_SIM_CANDEV_CHAR=y
CONFIG_SIM_CANDEV_SOCK=y
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2008
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y

View file

@ -553,5 +553,21 @@ int sim_bringup(void)
usbdev_rndis_initialize(mac);
#endif
#ifdef CONFIG_SIM_CANDEV_CHAR
ret = sim_canchar_initialize(CONFIG_SIM_CANDEV_CHAR_IDX, 0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sim_canchar_initialize() failed: %d\n", ret);
}
#endif
#ifdef CONFIG_SIM_CANDEV_SOCK
ret = sim_cansock_initialize(CONFIG_SIM_CANDEV_SOCK_IDX);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: sim_cansock_initialize() failed: %d\n", ret);
}
#endif
return ret;
}