boards/native/nrf_bsim/doc/nrf52_bsim.html · boards/native/nrf_bsim/doc/nrf52_bsim.rst 공식 원문 ↗

Zephyr 3.7.0 · Boards · Native · nRF52 · BabbleSim

nRF52 시뮬레이션 보드 (BabbleSim)

nRF52833 주변장치와 2.4GHz 무선 환경을 Linux 네이티브 코드로 빠르고 결정론적으로 시험하는 보드입니다.

Official pathboards/native/nrf_bsim/doc/nrf52_bsim.html
Source fileboards/native/nrf_bsim/doc/nrf52_bsim.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

무선이 없으면 -nosim으로 단독 실행하고, BLE 상호작용은 장치 프로세스들과 bs_2G4_phy_v1을 같은 simulation ID로 묶습니다.

SoC model

nRF52833 · 주변장치 모델

Radio

BabbleSim 2G4 PHY

Execution

Linux native · deterministic

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 0FE10C9F9280D95C66B0F77E623E49BFDCC6B208F572A459FCD182D42E5082CB
.. _nrf52_bsim:

NRF52 simulated board (BabbleSim)
#################################

.. contents::
   :depth: 1
   :backlinks: entry
   :local:


Overview
********

To allow simulating a nRF52833 SOC a Zephyr target boards is provided: the
nrf52_bsim.

This uses `BabbleSim`_ to simulate the radio activity, and the
:ref:`POSIX architecture<Posix arch>` and the `native simulator`_ to
run applications natively on the development system. This has the benefit of
providing native code execution performance and easy debugging using
native tools, but inherits :ref:`its limitations <posix_arch_limitations>`.

This board includes models of some of the nRF52 SOC peripherals:

* Radio
* Timers
* AAR (Accelerated Address Resolver)
* AES CCM & AES ECB encryption HW
* CLOCK (Clock control)
* EGU (Event Generator Unit)
* FICR (Factory Information Configuration Registers)
* GPIO & GPIOTE
* NVMC (Non-Volatile Memory Controller / Flash)
* PPI (Programmable Peripheral Interconnect)
* RNG (Random Number Generator)
* RTC (Real Time Counter)
* TEMP (Temperature sensor)
* UART & UARTE (UART with Easy DMA)
* UICR (User Information Configuration Registers)

and will use the same drivers as the nrf52 dk targets for these.
For more information on what is modelled to which level of detail,
check the `HW models implementation status`_.

Note that unlike a real nrf52 device, the nrf52_bsim has unlimited RAM and flash for code.

.. _BabbleSim:
   https://BabbleSim.github.io

.. _native simulator:
   https://github.com/BabbleSim/native_simulator/blob/main/docs/README.md

.. _HW models implementation status:
   https://github.com/BabbleSim/ext_nRF_hw_models/blob/main/docs/README_impl_status.md

.. _nrf52bsim_build_and_run:

Building and running
********************

This board requires the host 32 bit C library. See
:ref:`POSIX Arch dependencies<posix_arch_deps>`.

To target this board you also need to have `BabbleSim`_ compiled in your system.
If you do not have it yet, the easiest way to get it, is to enable the babblesim group
in your local west configuration, running west update, and building the simulator:

.. code-block:: console

   west config manifest.group-filter -- +babblesim
   west update
   cd ${ZEPHYR_BASE}/../tools/bsim
   make everything -j 8

.. note::

   If you need more BabbleSim components, or more up to date versions,
   you can check the `BabbleSim web page <https://BabbleSim.github.io>`_
   for instructions on how to
   `fetch <https://babblesim.github.io/fetching.html>`_ and
   `build <https://babblesim.github.io/building.html>`_ it.

You will now need to define two environment variables to point to your BabbleSim
installation, ``BSIM_OUT_PATH`` and ``BSIM_COMPONENTS_PATH``.
If you followed the previous steps, you can just do:

.. code-block:: console

   export BSIM_OUT_PATH=${ZEPHYR_BASE}/../tools/bsim
   export BSIM_COMPONENTS_PATH=${BSIM_OUT_PATH}/components/

.. note::

   You can add these two lines to your ``~/.zephyrrc`` file, or to your shell
   initialization script (``~/.bashrc``), so you won't need to rerun them
   manually for each new shell.

You're now ready to build applications targeting this board, for example:

.. zephyr-app-commands::
   :zephyr-app: samples/hello_world
   :host-os: unix
   :board: nrf52_bsim
   :goals: build
   :compact:

Then you can execute your application using:

.. code-block:: console

   $ ./build/zephyr/zephyr.exe -nosim
   # Press Ctrl+C to exit

Note that the executable is a BabbleSim executable. The ``-nosim`` command line
option indicates you want to run it detached from a BabbleSim simulation. This
is possible only while there is no radio activity. But is perfectly fine for
most Zephyr samples and tests.

When you want to run a simulation with radio activity you need to run also the
BableSim 2G4 (2.4GHz) physical layer simulation (phy).

For example, if you would like to run a simple case with 1 BLE ``central_hr``
sample application connecting to a BLE ``peripheral`` sample application:
Build the ``central_hr`` application targeting this board and copy the resulting
executable to the simulator bin folder with a sensible name:

.. zephyr-app-commands::
   :zephyr-app: samples/bluetooth/central_hr
   :host-os: unix
   :board: nrf52_bsim
   :goals: build
   :compact:

.. code-block:: console

   $ cp build/zephyr/zephyr.exe \
     ${BSIM_OUT_PATH}/bin/bs_nrf52_bsim_samples_bluetooth_central_hr

Do the same for the ``peripheral`` sample app:

.. zephyr-app-commands::
   :zephyr-app: samples/bluetooth/peripheral
   :host-os: unix
   :board: nrf52_bsim
   :goals: build
   :compact:

.. code-block:: console

   $ cp build/zephyr/zephyr.exe \
     ${BSIM_OUT_PATH}/bin/bs_nrf52_bsim_samples_bluetooth_peripheral

And then run them together with BabbleSim's 2G4 physical layer simulation:

.. code-block:: console

   cd ${BSIM_OUT_PATH}/bin/
   ./bs_nrf52_bsim_samples_bluetooth_peripheral -s=trial_sim -d=0 &
   ./bs_nrf52_bsim_samples_bluetooth_central_hr -s=trial_sim -d=1 &
   ./bs_2G4_phy_v1 -s=trial_sim -D=2 -sim_length=10e6 &

Where the ``-s`` command line option provides a string which uniquely identifies
this simulation; the ``-D`` option tells the Phy how many devices will be run
in this simulation; the ``-d`` option tells each device which is its device
number in the simulation; and the ``-sim_length`` option specifies the length
of the simulation in microseconds.
BabbleSim devices and Phy support many command line switches.
Run them with ``-help`` for more information.

You can find more information about how to run BabbleSim simulations in
`this BabbleSim example <https://babblesim.github.io/example_2g4.html>`_.


C library choice
****************

These nRF bsim boards use the `native simulator`_ at their core, so you can chose with which
C library you want to build your embedded code.
Check the :ref:`native simulator C library choice section<native_sim_Clib_choice>` for more info.


Debugging, coverage and address sanitizer
*****************************************

Just like with :ref:`native_sim<native_sim_debug>`, the resulting
executables are Linux native applications.
Therefore they can be debugged or instrumented with the same tools as any other
native application, like for example ``gdb`` or ``valgrind``.

The same
:ref:`code coverage analysis means from the POSIX arch<coverage_posix>`
are inherited in this board.
Similarly, the
:ref:`address and undefined behavior sanitizers can be used as in native_sim<native_sim_asan>`.


Note that BabbleSim will run fine if one or several of its components are
being run in a debugger or instrumented. For example, pausing a device in a
breakpoint will pause the whole simulation.

BabbleSim is fully deterministic by design and the results are not affected by
the host computing speed. All randomness is controlled by random seeds which can
be provided as command line options.


About time in BabbleSim
************************

Note that time in BabbleSim is simulated and decoupled from real time. Normally
simulated time will pass several orders of magnitude faster than real time,
only limited by your workstation compute power.
If for some reason you want to limit the speed of the simulation to real
time or a ratio of it, you can do so by connecting the `handbrake device`_
to the BabbleSim Phy.

.. _handbrake device:
   https://github.com/BabbleSim/base/tree/master/device_handbrake

Part 3

한국어 전문 번역

개요

nRF52833 SoC를 시뮬레이션하기 위한 Zephyr 대상 보드가 nrf52_bsim입니다.

BabbleSim으로 무선 활동을 시뮬레이션하고, POSIX 아키텍처와 native simulator로 개발 시스템에서 애플리케이션을 네이티브 실행합니다. 네이티브 코드의 성능과 호스트 도구를 이용한 쉬운 디버깅이 장점이지만 POSIX 아키텍처의 제한도 그대로 적용됩니다.

이 보드는 다음 nRF52 SoC 주변장치 모델을 포함합니다.

  • Radio
  • Timer
  • AAR(Accelerated Address Resolver)
  • AES CCM 및 AES ECB 암호화 하드웨어
  • CLOCK 제어
  • EGU(Event Generator Unit)
  • FICR(Factory Information Configuration Registers)
  • GPIO 및 GPIOTE
  • NVMC(Non-Volatile Memory Controller/Flash)
  • PPI(Programmable Peripheral Interconnect)
  • RNG(Random Number Generator)
  • RTC(Real Time Counter)
  • TEMP 온도 센서
  • UART 및 EasyDMA를 지원하는 UARTE
  • UICR(User Information Configuration Registers)

이 주변장치는 nRF52 DK 대상과 같은 드라이버를 사용합니다. 각 모델의 구현 상세도는 HW 모델 구현 상태에서 확인할 수 있습니다.

빌드와 실행

이 보드는 호스트의 32비트 C 라이브러리를 요구합니다. POSIX 아키텍처 의존성을 먼저 갖춰야 합니다.

또한 시스템에 BabbleSim을 컴파일해 두어야 합니다. 가장 쉬운 방법은 로컬 west 구성에서 babblesim 그룹을 활성화하고 업데이트한 뒤 simulator를 빌드하는 것입니다.

west config manifest.group-filter -- +babblesim
west update
cd ${ZEPHYR_BASE}/../tools/bsim
make everything -j 8

BabbleSim 설치 위치를 가리키는 환경 변수 BSIM_OUT_PATH와 BSIM_COMPONENTS_PATH를 설정합니다. 앞 절차를 따랐다면 다음과 같습니다.

export BSIM_OUT_PATH=${ZEPHYR_BASE}/../tools/bsim
export BSIM_COMPONENTS_PATH=${BSIM_OUT_PATH}/components/

매 shell에서 다시 설정하지 않으려면 두 줄을 ~/.zephyrrc 또는 ~/.bashrc에 추가할 수 있습니다.

이제 보드용 애플리케이션을 빌드할 수 있습니다.

west build -b nrf52_bsim samples/hello_world

무선 시뮬레이션에 연결하지 않고 실행하려면 다음 명령을 사용합니다.

$ ./build/zephyr/zephyr.exe -nosim
# 종료하려면 Ctrl+C

생성된 실행 파일은 BabbleSim 실행 파일입니다. -nosim은 BabbleSim 시뮬레이션에서 분리해 실행한다는 뜻입니다. 무선 활동이 없을 때만 가능하지만 대부분의 Zephyr sample과 test에는 충분합니다.

무선 활동을 포함한 시뮬레이션

무선 활동을 시뮬레이션하려면 BabbleSim 2G4(2.4GHz) 물리 계층 시뮬레이션(Phy)도 함께 실행해야 합니다.

예로 BLE central_hr 애플리케이션 하나가 BLE peripheral 애플리케이션 하나에 연결되는 구성을 만듭니다. 먼저 central을 빌드합니다.

west build -b nrf52_bsim samples/bluetooth/central_hr

결과 실행 파일을 simulator의 bin 폴더에 알아보기 쉬운 이름으로 복사합니다.

$ cp build/zephyr/zephyr.exe \
  ${BSIM_OUT_PATH}/bin/bs_nrf52_bsim_samples_bluetooth_central_hr

peripheral sample도 같은 방식으로 빌드합니다.

west build -b nrf52_bsim samples/bluetooth/peripheral

peripheral 실행 파일을 복사합니다.

$ cp build/zephyr/zephyr.exe \
  ${BSIM_OUT_PATH}/bin/bs_nrf52_bsim_samples_bluetooth_peripheral

두 장치와 BabbleSim 2G4 물리 계층을 함께 실행합니다.

cd ${BSIM_OUT_PATH}/bin/
./bs_nrf52_bsim_samples_bluetooth_peripheral -s=trial_sim -d=0 &
./bs_nrf52_bsim_samples_bluetooth_central_hr -s=trial_sim -d=1 &
./bs_2G4_phy_v1 -s=trial_sim -D=2 -sim_length=10e6 &
  • -s: 이 시뮬레이션을 고유하게 식별하는 문자열입니다.
  • -D: 시뮬레이션에서 실행할 장치 수를 Phy에 알립니다.
  • -d: 각 장치의 시뮬레이션 장치 번호입니다.
  • -sim_length: 시뮬레이션 길이를 마이크로초 단위로 지정합니다.

BabbleSim 장치와 Phy는 더 많은 명령행 옵션을 지원합니다. -help로 확인할 수 있으며 BabbleSim 2G4 예제에 실행 방법이 자세히 나와 있습니다.

C 라이브러리 선택

nRF bsim 보드는 native simulator를 핵심으로 사용하므로 임베디드 코드를 빌드할 C 라이브러리를 선택할 수 있습니다. 호스트 libc, minimal libc와 Picolibc의 차이는 native simulator C 라이브러리 선택 절차를 따릅니다.

디버깅·Coverage·Sanitizer

native_sim과 마찬가지로 결과 실행 파일은 Linux 네이티브 애플리케이션입니다. gdb, valgrind 같은 일반 네이티브 도구로 디버깅·계측할 수 있습니다.

POSIX 아키텍처의 code coverage 분석 기능을 그대로 사용하며, native_sim과 같은 방식으로 Address Sanitizer와 Undefined Behavior Sanitizer를 사용할 수 있습니다.

하나 이상의 BabbleSim 컴포넌트를 디버거에서 실행하거나 계측해도 정상 동작합니다. 예를 들어 한 장치를 breakpoint에서 멈추면 전체 시뮬레이션이 함께 멈춥니다.

BabbleSim은 설계상 완전히 결정론적이며 호스트 계산 속도가 결과에 영향을 주지 않습니다. 모든 난수성은 명령행 옵션으로 제공할 수 있는 random seed로 제어됩니다.

BabbleSim의 시간

BabbleSim 시간은 시뮬레이션되며 실시간과 분리됩니다. 보통 워크스테이션 계산 능력만 한계가 되어 시뮬레이션 시간이 실시간보다 몇 자릿수 빠르게 흐릅니다.

시뮬레이션 속도를 실시간 또는 그 비율로 제한해야 한다면 BabbleSim Phy에 handbrake device를 연결할 수 있습니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.