Part 1
요약·해설
can show, bitrate/dbitrate, mode, start/stop, filter, send, recover command를 실제 출력과 함께 설명합니다.
show · statistics · errors
timing · mode · start/stop
filter · receive · send · recover
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
6547416D2B98D5787119EAB771B060C5603FAF2352554ABB811B078D1BEBFC66
.. _can_shell:
CAN Shell
#########
.. contents::
:local:
:depth: 1
Overview
********
The CAN shell provides a ``can`` command with a set of subcommands for the :ref:`shell <shell_api>`
module. It allows for testing and exploring the :ref:`can_api` driver API through an interactive
interface without having to write a dedicated application. The CAN shell can also be enabled in
existing applications to aid in interactive debugging of CAN issues.
The CAN shell provides access to most CAN controller features, including inspection, configuration,
sending and receiving of CAN frames, and bus recovery.
In order to enable the CAN shell, the following :ref:`Kconfig <kconfig>` options must be enabled:
* :kconfig:option:`CONFIG_SHELL`
* :kconfig:option:`CONFIG_CAN`
* :kconfig:option:`CONFIG_CAN_SHELL`
The following :ref:`Kconfig <kconfig>` options enable additional subcommands and features of the
``can`` command:
* :kconfig:option:`CONFIG_CAN_FD_MODE` enables CAN FD specific subcommands (e.g. for setting the
timing for the CAN FD data phase).
* :kconfig:option:`CONFIG_CAN_RX_TIMESTAMP` enables printing of timestamps for received CAN frames.
* :kconfig:option:`CONFIG_CAN_STATS` enables printing of various statistics for the CAN controller
in the ``can show`` subcommand. This depends on :kconfig:option:`CONFIG_STATS` being enabled as
well.
* :kconfig:option:`CONFIG_CAN_MANUAL_RECOVERY_MODE` enables the ``can recover`` subcommand.
For example, building the :ref:`hello_world` sample for the :ref:`frdm_k64f` with the CAN shell and
CAN statistics enabled:
.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: frdm_k64f
:gen-args: -DCONFIG_SHELL=y -DCONFIG_CAN=y -DCONFIG_CAN_SHELL=y -DCONFIG_STATS=y -DCONFIG_CAN_STATS=y
:goals: build
See the :ref:`shell <shell_api>` documentation for general instructions on how to connect and
interact with the shell. The CAN shell comes with built-in help (unless
:kconfig:option:`CONFIG_SHELL_HELP` is disabled). The built-in help messages can be printed by
passing ``-h`` or ``--help`` to the ``can`` command or any of its subcommands. All subcommands also
support tab-completion of their arguments.
.. tip::
All of the CAN shell subcommands take the name of a CAN controller as their first argument, which
also supports tab-completion. A list of all devices available can be obtained using the ``device
list`` shell command when :kconfig:option:`CONFIG_DEVICE_SHELL` is enabled. The examples below
all use the device name ``can@0``.
Inspection
**********
The properties of a given CAN controller can be inspected using the ``can show`` subcommand as shown
below. The properties include the core CAN clock rate, the maximum supported bitrate, the number of
RX filters supported, capabilities, current mode, current state, error counters, timing limits, and
more:
.. code-block:: console
uart:~$ can show can@0
core clock: 144000000 Hz
max bitrate: 5000000 bps
max std filters: 15
max ext filters: 15
capabilities: normal loopback listen-only fd
mode: normal
state: stopped
rx errors: 0
tx errors: 0
timing: sjw 1..128, prop_seg 0..0, phase_seg1 2..256, phase_seg2 2..128, prescaler 1..512
timing data: sjw 1..16, prop_seg 0..0, phase_seg1 1..32, phase_seg2 1..16, prescaler 1..32
transceiver: passive/none
statistics:
bit errors: 0
bit0 errors: 0
bit1 errors: 0
stuff errors: 0
crc errors: 0
form errors: 0
ack errors: 0
rx overruns: 0
.. note::
The statistics are only printed if :kconfig:option:`CONFIG_CAN_STATS` is enabled.
Configuration
*************
The CAN shell allows for configuring the CAN controller mode and timing, along with starting and
stopping the processing of CAN frames.
.. note::
The CAN controller mode and timing can only be changed while the CAN controller is stopped, which
is the initial setting upon boot-up. The initial CAN controller mode is set to ``normal`` and the
initial timing is set according to the ``bitrate``, ``sample-point``, ``bitrate-data``, and
``sample-point-data`` :ref:`devicetree` properties.
Timing
======
The classic CAN bitrate/CAN FD arbitration phase bitrate can be configured using the ``can bitrate``
subcommand as shown below. The bitrate is specified in bits per second.
.. code-block:: console
uart:~$ can bitrate can@0 125000
setting bitrate to 125000 bps
If :kconfig:option:`CONFIG_CAN_FD_MODE` is enabled, the data phase bitrate can be configured using
the ``can dbitrate`` subcommand as shown below. The bitrate is specified in bits per second.
.. code-block:: console
uart:~$ can dbitrate can@0 1000000
setting data bitrate to 1000000 bps
Both of these subcommands allow specifying an optional sample point in per mille and a
(Re)Synchronization Jump Width (SJW) in Time Quanta as positional arguments. Refer to the
interactive help of the subcommands for more details.
It is also possible to configure the raw bit timing using the ``can timing`` and ``can dtiming``
subcommands. Refer to the interactive help output for these subcommands for details on the required
arguments.
Mode
====
The CAN shell allows for setting the mode of the CAN controller using the ``can mode``
subcommand. An example for enabling loopback mode is shown below.
.. code-block:: console
uart:~$ can mode can@0 loopback
setting mode 0x00000001
The subcommand accepts multiple modes given on the same command line (e.g. ``can mode can@0 fd
loopback`` for setting CAN FD and loopback mode). Vendor-specific modes can be specified in
hexadecimal.
Starting and Stopping
=====================
After the timing and mode has been configured as needed, the CAN controller can be started using the
``can start`` subcommand as shown below. This will enable reception and transmission of CAN frames.
.. code-block:: console
uart:~$ can start can@0
starting can@0
Prior to reconfiguring the timing or mode, the CAN controller needs to be stopped using the ``can
stop`` subcommand as shown below:
.. code-block:: console
uart:~$ can stop can@0
stopping can@0
Receiving
*********
In order to receive CAN frames, one or more CAN RX filters need to be configured. CAN RX filters are
added using the ``can filter add`` subcommand as shown below. The subcommand accepts a CAN ID in
hexadecimal format along with an optional CAN ID mask, also in hexadecimal format, for setting which
bits in the CAN ID are to be matched. Refer to the interactive help output for this subcommand for
further details on the supported arguments.
.. code-block:: console
uart:~$ can filter add can@0 010
adding filter with standard (11-bit) CAN ID 0x010, CAN ID mask 0x7ff, data frames 1, RTR frames 0, CAN FD frames 0
filter ID: 0
The filter ID (0 in the example above) returned is to be used when removing the CAN RX filter.
Received CAN frames matching the added filter(s) are printed to the shell. A few examples are shown below:
.. code-block:: console
# Dev Flags ID Size Data bytes
can0 -- 010 [8] 01 02 03 04 05 06 07 08
can0 B- 010 [08] 01 02 03 04 05 06 07 08
can0 BP 010 [03] 01 aa bb
can0 -- 00000010 [0]
can0 -- 010 [1] 20
can0 -- 010 [8] remote transmission request
The columns have the following meaning:
* Dev
* Name of the device receiving the frame.
* Flags
* ``B``: The frame has the CAN FD Baud Rate Switch (BRS) flag set.
* ``P``: The frame has the CAN FD Error State Indicator (ESI) flag set. The transmitting node is
in error-passive state.
* ``-``: Unset flag.
* ID
* ``010``: The standard (11-bit) CAN ID of the frame in hexadecimal format, here 10h.
* ``00000010``: The extended (29-bit) CAN ID of the frame in hexadecimal format, here 10h.
* Size
* ``[8]``: The number of frame data bytes in decimal format, here a classic CAN frame with 8 data
bytes.
* ``[08]``: The number of frame data bytes in decimal format, here a CAN FD frame with 8 data
bytes.
* Data bytes
* ``01 02 03 04 05 06 07 08``: The frame data bytes in hexadecimal format, here the numbers from 1
through 8.
* ``remote transmission request``: The frame is a Remote Transmission Request (RTR) frame and thus
carries no data bytes.
.. tip::
If :kconfig:option:`CONFIG_CAN_RX_TIMESTAMP` is enabled, each line will be prepended with a
timestamp from the free-running timestamp counter in the CAN controller.
Configured CAN RX filters can be removed again using the ``can filter remove`` subcommand as shown
below. The filter ID is the ID returned by the ``can filter add`` subcommand (0 in the example
below).
.. code-block:: console
uart:~$ can filter remove can@0 0
removing filter with ID 0
Sending
*******
CAN frames can be queued for transmission using the ``can send`` subcommand as shown below. The
subcommand accepts a CAN ID in hexadecimal format and optionally a number of data bytes, also
specified in hexadecimal. Refer to the interactive help output for this subcommand for further
details on the supported arguments.
.. code-block:: console
uart:~$ can send can@0 010 1 2 3 4 5 6 7 8
enqueuing CAN frame #2 with standard (11-bit) CAN ID 0x010, RTR 0, CAN FD 0, BRS 0, DLC 8
CAN frame #2 successfully sent
Bus Recovery
************
The ``can recover`` subcommand can be used for initiating manual recovery from a CAN bus-off event
as shown below:
.. code-block:: console
uart:~$ can recover can@0
recovering, no timeout
The subcommand accepts an optional bus recovery timeout in milliseconds. If no timeout is specified,
the command will wait indefinitely for the bus recovery to succeed.
.. note::
The ``recover`` subcommand is only available if :kconfig:option:`CONFIG_CAN_MANUAL_RECOVERY_MODE`
is enabled.
Part 3
한국어 전문 번역
개요
CAN shell은 Zephyr shell module에 여러 subcommand를 가진 can command를 제공합니다. 별도 application을 작성하지 않고 interactive interface로 CAN driver API를 시험하고 탐색할 수 있으며, 기존 application에 켜서 CAN 문제를 interactive debugging하는 데도 쓸 수 있습니다.
Controller 정보 확인, 설정, CAN frame 송수신, bus recovery를 포함해 CAN controller 기능 대부분에 접근합니다.
CAN shell을 활성화하려면 다음 Kconfig option이 필요합니다.
CONFIG_SHELLCONFIG_CANCONFIG_CAN_SHELL
추가 subcommand와 기능은 다음 option으로 활성화합니다.
CONFIG_CAN_FD_MODE: CAN FD data phase timing 같은 CAN FD 전용 subcommand를 켭니다.CONFIG_CAN_RX_TIMESTAMP: 수신 CAN frame의 timestamp를 출력합니다.CONFIG_CAN_STATS:can show에 여러 controller statistic을 출력하며CONFIG_STATS도 필요합니다.CONFIG_CAN_MANUAL_RECOVERY_MODE:can recoversubcommand를 켭니다.
다음은 frdm_k64f용 hello_world sample을 CAN shell과 CAN statistic을 켜서 build하는 예입니다.
# From the root of the zephyr repository
west build -b frdm_k64f samples/hello_world -- -DCONFIG_SHELL=y -DCONFIG_CAN=y -DCONFIG_CAN_SHELL=y -DCONFIG_STATS=y -DCONFIG_CAN_STATS=yCONFIG_SHELL_HELP를 끄지 않았다면 can과 모든 subcommand에 -h 또는 --help를 넘겨 built-in help를 볼 수 있습니다. 모든 subcommand argument는 tab completion을 지원합니다.
모든 CAN shell subcommand의 첫 argument는 CAN controller 이름이며 역시 tab completion을 지원합니다. CONFIG_DEVICE_SHELL을 켰다면 device list로 device 목록을 볼 수 있습니다. 아래 예는 모두 can@0을 사용합니다.
정보 확인
can show는 core CAN clock rate, maximum bitrate, RX filter 수, capability, 현재 mode·state, error counter, timing limit 등을 보여 줍니다.
uart:~$ can show can@0
core clock: 144000000 Hz
max bitrate: 5000000 bps
max std filters: 15
max ext filters: 15
capabilities: normal loopback listen-only fd
mode: normal
state: stopped
rx errors: 0
tx errors: 0
timing: sjw 1..128, prop_seg 0..0, phase_seg1 2..256, phase_seg2 2..128, prescaler 1..512
timing data: sjw 1..16, prop_seg 0..0, phase_seg1 1..32, phase_seg2 1..16, prescaler 1..32
transceiver: passive/none
statistics:
bit errors: 0
bit0 errors: 0
bit1 errors: 0
stuff errors: 0
crc errors: 0
form errors: 0
ack errors: 0
rx overruns: 0CONFIG_CAN_STATS를 켠 경우에만 statistic이 출력됩니다.
설정
CAN shell은 controller mode·timing을 설정하고 CAN frame 처리를 시작·정지할 수 있습니다.
Mode와 timing은 controller가 stopped 상태일 때만 바꿀 수 있으며 boot 직후 초기 상태가 stopped입니다. 초기 mode는 normal, 초기 timing은 devicetree의 bitrate, sample-point, bitrate-data, sample-point-data property에 따릅니다.
Timing
can bitrate로 classic CAN bitrate/CAN FD arbitration phase bitrate를 bit/s 단위로 설정합니다.
uart:~$ can bitrate can@0 125000
setting bitrate to 125000 bpsCONFIG_CAN_FD_MODE를 켜면 can dbitrate로 data phase bitrate를 bit/s 단위로 설정합니다.
uart:~$ can dbitrate can@0 1000000
setting data bitrate to 1000000 bps두 command 모두 permille 단위 sample point와 Time Quanta 단위 (Re)Synchronization Jump Width(SJW)를 positional argument로 선택적으로 받을 수 있습니다. Raw bit timing은 can timing과 can dtiming으로 설정합니다.
Mode
can mode로 controller mode를 설정합니다. 다음은 loopback mode를 켭니다.
uart:~$ can mode can@0 loopback
setting mode 0x00000001한 command line에 mode를 여러 개 줄 수 있습니다. 예를 들어 can mode can@0 fd loopback은 CAN FD와 loopback mode를 함께 켭니다. Vendor-specific mode는 hexadecimal로 지정할 수 있습니다.
시작과 정지
can start는 timing과 mode 설정 후 controller를 시작해 CAN frame 송수신을 활성화합니다.
uart:~$ can start can@0
starting can@0Timing 또는 mode를 다시 설정하기 전에는 can stop으로 controller를 정지해야 합니다.
uart:~$ can stop can@0
stopping can@0수신
CAN frame을 받으려면 CAN RX filter를 하나 이상 설정해야 합니다. can filter add는 hexadecimal CAN ID와, 어느 bit를 비교할지 정하는 선택적 hexadecimal CAN ID mask를 받습니다.
uart:~$ can filter add can@0 010
adding filter with standard (11-bit) CAN ID 0x010, CAN ID mask 0x7ff, data frames 1, RTR frames 0, CAN FD frames 0
filter ID: 0반환된 filter ID(예에서는 0)는 CAN RX filter를 제거할 때 사용합니다. 추가한 filter와 일치하는 수신 frame은 다음처럼 shell에 출력됩니다.
# Dev Flags ID Size Data bytes
can0 -- 010 [8] 01 02 03 04 05 06 07 08
can0 B- 010 [08] 01 02 03 04 05 06 07 08
can0 BP 010 [03] 01 aa bb
can0 -- 00000010 [0]
can0 -- 010 [1] 20
can0 -- 010 [8] remote transmission request출력 column의 의미는 다음과 같습니다.
Dev: frame을 받은 device 이름입니다.Flags:B는 CAN FD Baud Rate Switch(BRS),P는 CAN FD Error State Indicator(ESI)이며 sender가 error-passive임을 뜻합니다.-는 flag가 없다는 뜻입니다.ID:010은 hexadecimal standard 11-bit CAN ID 0x10,00000010은 extended 29-bit CAN ID 0x10입니다.Size:[8]은 8-byte classic CAN frame,[08]은 8-byte CAN FD frame입니다.Data bytes: hexadecimal payload를 표시합니다.remote transmission request는 data가 없는 Remote Transmission Request(RTR) frame입니다.
CONFIG_CAN_RX_TIMESTAMP를 켜면 각 줄 앞에 CAN controller의 free-running timestamp counter 값이 붙습니다.
can filter remove와 can filter add가 반환한 ID로 설정된 filter를 제거합니다.
uart:~$ can filter remove can@0 0
removing filter with ID 0송신
can send는 CAN frame을 transmission queue에 넣습니다. Hexadecimal CAN ID와 선택적인 hexadecimal data byte를 받습니다.
uart:~$ can send can@0 010 1 2 3 4 5 6 7 8
enqueuing CAN frame #2 with standard (11-bit) CAN ID 0x010, RTR 0, CAN FD 0, BRS 0, DLC 8
CAN frame #2 successfully sentBus recovery
can recover로 CAN bus-off event에서 manual recovery를 시작합니다.
uart:~$ can recover can@0
recovering, no timeoutMillisecond 단위 timeout을 선택적으로 받을 수 있고 생략하면 recovery가 성공할 때까지 무기한 기다립니다. 이 command는 CONFIG_CAN_MANUAL_RECOVERY_MODE를 켠 경우에만 사용할 수 있습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.