develop/flash_debug/nordic_segger.html · develop/flash_debug/nordic_segger.rst 공식 원문 ↗

Zephyr 3.7.0 · Develop · Nordic SEGGER

Nordic nRF5x Segger J-Link

Nordic development kit의 on-board J-Link를 설치하고 flash·serial·RTT·visual debug에 사용하는 방법입니다.

Official pathdevelop/flash_debug/nordic_segger.html
Source filedevelop/flash_debug/nordic_segger.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

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

Part 1

요약·해설

J-Link·nrfjprog 설치와 flash 순서, Linux serial 권한·ModemManager 우회, Mass Storage disable, RTT console과 Ozone 설정을 설명합니다.

Flash

nrfjprog · Erase · Program

Serial

CDC ACM · MSD · udev

Debug

RTT · Ozone · J-Link

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 B21C147A8E42CDB7197E731FDEBA1F3E8A069194F8E1773DCB19666DA7D0BCAB
:orphan:

.. _nordic_segger:

Nordic nRF5x Segger J-Link
##########################

Overview
********

All Nordic nRF5x Development Kits, Preview Development Kits and Dongles are equipped
with a Debug IC (Atmel ATSAM3U2C) which provides the following functionality:

* Segger J-Link firmware and desktop tools
* SWD debug for the nRF5x IC
* Mass Storage device for drag-and-drop image flashing
* USB CDC ACM Serial Port bridged to the nRF5x UART peripheral
* Segger RTT Console
* Segger Ozone Debugger

Segger J-Link Software Installation
***********************************

To install the J-Link Software and documentation pack, follow the steps below:

#. Download the appropriate package from the `J-Link Software and documentation pack`_ website
#. Depending on your platform, install the package or run the installer
#. When connecting a J-Link-enabled board such as an nRF5x DK, PDK or dongle, a
   drive corresponding to a USB Mass Storage device as well as a serial port should come up

nRF5x Command-Line Tools Installation
*************************************

The nRF5x command-line Tools allow you to control your nRF5x device from the command line,
including resetting it, erasing or programming the flash memory and more.

To install them, visit `nRF5x Command-Line Tools`_ and select your operating
system.

After installing, make sure that ``nrfjprog`` is somewhere in your executable path
to be able to invoke it from anywhere.

.. _nordic_segger_flashing:

Flashing
********

To program the flash with a compiled Zephyr image after having followed the instructions
to install the Segger J-Link Software and the nRF5x Command-Line Tools, follow the steps below:

* Connect the micro-USB cable to the nRF5x board and to your computer
* Erase the flash memory in the nRF5x IC:

.. code-block:: console

   nrfjprog --eraseall -f nrf5<x>

Where ``<x>`` is either 1 for nRF51-based boards or 2 for nRF52-based boards

* Flash the Zephyr image from the sample folder of your choice:

.. code-block:: console

   nrfjprog --program outdir/<board>/zephyr.hex -f nrf5<x>

Where: ``<board>`` is the board name you used in the BOARD directive when building (for example nrf52dk/nrf52832)
and ``<x>`` is either 1 for nRF51-based boards or 2 for nRF52-based boards

* Reset and start Zephyr:

.. code-block:: console

   nrfjprog --reset -f nrf5<x>

Where ``<x>`` is either 1 for nRF51-based boards or 2 for nRF52-based boards

USB CDC ACM Serial Port Setup
*****************************

**Important note**: An issue with Segger J-Link firmware on the nRF5x boards might cause
data loss and/or corruption on the USB CDC ACM Serial Port on some machines.
To work around this disable the Mass Storage Device on your board as described in :ref:`nordic_segger_msd`.

Windows
=======

The serial port will appear as ``COMxx``. Simply check the "Ports (COM & LPT)" section
in the Device Manager.

GNU/Linux
=========

The serial port will appear as ``/dev/ttyACMx``. By default the port is not accessible to all users.
Type the command below to add your user to the dialout group to give it access to the serial port.
Note that re-login is required for this to take effect.

.. code-block:: bash

   sudo usermod -a -G dialout `whoami`

Recent versions of `ModemManager send AT commands to TTY-like devices`_; this
includes Nordic development kits. This will prevent you from using the serial
port for a few seconds, and can make your application misbehave if it reads
data from the UART. Before running your application, you might want to
temporarily disable ModemManager by running these commands:

.. code-block:: bash

   systemctl stop ModemManager.service
   systemctl disable ModemManager.service

You can also `blacklist Segger devices by editing udev rules`_ so ModemManager
ignores them, by running:

.. code-block:: bash

   sudo sh -c 'echo "ATTRS{idVendor}==\"1366\", ENV{ID_MM_DEVICE_IGNORE}=\"1\" " \
     >> /etc/udev/rules.d/99-segger-modemmanager-blacklist.rules'
   sudo service udev restart

A fix for this is expected in ModemManager 1.8 and new firmware for the Segger IMCUs.

Apple macOS (OS X)
==================

The serial port will appear as ``/dev/tty.usbmodemXXXX``.

.. _nordic_segger_msd:

Disabling the Mass Storage Device functionality
***********************************************

Due to a known issue in Segger's J-Link firmware, depending on your operating system
and version you might experience data corruption or drops if you use the USB CDC
ACM Serial Port with packets larger than 64 bytes.
This has been observed on both GNU/Linux and macOS (OS X).

To avoid this, you can simply disable the Mass Storage Device by opening:

* On GNU/Linux or macOS (OS X) JLinkExe from a terminal
* On Microsoft Windows the "JLink Commander" application

And then typing the following:

.. code-block:: bat

   MSDDisable

And finally unplugging and replugging the board. The Mass Storage Device should
not appear anymore and you should now be able to send long packets over the virtual Serial Port.
Further information from Segger can be found in the `Segger SAM3U Wiki`_.

RTT Console
***********

Segger's J-Link supports `Real-Time Tracing (RTT)`_, a technology that allows a terminal
connection (both input and output) to be established between the target (nRF5x board)
and the development computer for logging and input. Zephyr supports RTT on nRF5x targets,
which can be very useful if the UART (through USB CDC ACM) is already being used for
a purpose different than logging (such as HCI traffic in the hci_uart application).
To use RTT, you will first need to enable it by adding the following lines in your ``.conf`` file:

.. code-block:: cfg

   CONFIG_USE_SEGGER_RTT=y
   CONFIG_RTT_CONSOLE=y

.. warning::

   There is also a ``HAS_SEGGER_RTT`` symbol that indicates that the platform
   supports SEGGER J-Link RTT. This symbol is set automatically by the SoC
   Kconfig files. Do not confuse it with ``USE_SEGGER_RTT``.

   ``USE_SEGGER_RTT`` depends on ``HAS_SEGGER_RTT``.

If you get no RTT output you might need to disable other consoles which conflict
with the RTT one if they are enabled by default in the particular sample or
application you are running. For example, to disable the UART console,
add this to your ``.conf`` file:

.. code-block:: cfg

   CONFIG_UART_CONSOLE=n

Once compiled and flashed with RTT enabled, you will be able to display RTT console
messages by doing the following:

Windows
=======

* Open the "J-Link RTT Viewer" application
* Select the following options:

  * Connection: USB
  * Target Device: Select your IC from the list
  * Target Interface and Speed: SWD, 4000 KHz
  * RTT Control Block: Auto Detection

GNU/Linux and macOS (OS X)
==========================

* Open ``JLinkRTTLogger`` from a terminal
* Select the following options:

  * Device Name: Use the fully qualified device name for your IC
  * Target Interface: SWD
  * Interface Speed: 4000 KHz
  * RTT Control Block address: auto-detection
  * RTT Channel name or index: 0
  * Output file: filename or ``/dev/stdout`` to display on the terminal directly

Python viewer
=============

A Python RTT viewer tool can be found in the `pyrtt-viewer`_ GitHub repository.

Segger Ozone
************

Segger J-Link is compatible with `Segger Ozone`_, a visual debugger that can be obtained here:

* `Segger Ozone Download`_

Once downloaded you can install it and configure it like so:

* Target Device: Select your IC from the list
* Target Interface: SWD
* Target Interface Speed: 4 MHz
* Host Interface: USB

Once configured, you can then use the File->Open menu to open the ``zephyr.elf``
file that you can find in your build folder.

References
**********

.. target-notes::

.. _nRF5x Command-Line Tools: https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools

.. _Segger SAM3U Wiki: https://wiki.segger.com/index.php?title=J-Link-OB_SAM3U
.. _Real-Time Tracing (RTT): https://www.segger.com/jlink-rtt.html
.. _pyrtt-viewer: https://github.com/thomasstenersen/pyrtt-viewer
.. _Segger Ozone: https://www.segger.com/ozone.html
.. _Segger Ozone Download: https://www.segger.com/downloads/jlink#Ozone

.. _ModemManager send AT commands to TTY-like devices: https://bugs.freedesktop.org/show_bug.cgi?id=85007
.. _blacklist Segger devices by editing udev rules: http://www.at91.com/linux4sam/bin/view/Linux4SAM/SoftwareTools#Device_or_resource_busy_dev_ttyA

.. _J-Link Software and documentation pack: https://www.segger.com/jlink-software.html

Part 3

한국어 전문 번역

Nordic nRF5x Segger J-Link

개요

모든 Nordic nRF5x Development Kit, Preview Development Kit, Dongle에는 다음 기능을 제공하는 Debug IC(Atmel ATSAM3U2C)가 장착되어 있습니다.

  • Segger J-Link firmware와 desktop tool
  • nRF5x IC용 SWD debug
  • Image drag-and-drop flashing용 Mass Storage device
  • nRF5x UART peripheral에 bridge된 USB CDC ACM Serial Port
  • Segger RTT Console
  • Segger Ozone Debugger

Segger J-Link software 설치

J-Link Software and Documentation Pack 설치 절차:

  1. J-Link Software and Documentation Pack website에서 platform에 맞는 package를 내려받습니다.
  2. Platform에 따라 package를 설치하거나 installer를 실행합니다.
  3. nRF5x DK·PDK·dongle 같은 J-Link 지원 board를 연결하면 USB Mass Storage device에 해당하는 drive와 serial port가 나타나야 합니다.

nRF5x command-line tool 설치

nRF5x command-line tool을 사용하면 command line에서 nRF5x device reset, flash memory erase·program 등을 제어할 수 있습니다.

nRF5x Command-Line Tools에서 운영체제를 선택해 설치합니다.

설치 후 어느 위치에서든 호출할 수 있도록 nrfjprog가 executable PATH에 있는지 확인합니다.

Flashing

Segger J-Link Software와 nRF5x Command-Line Tools를 설치한 뒤 compile된 Zephyr image를 flash에 program하는 절차:

  • Micro-USB cable을 nRF5x board와 computer에 연결합니다.
  • nRF5x IC의 flash memory를 지웁니다.
    nrfjprog --eraseall -f nrf5<x>

    <x>는 nRF51 기반 board이면 1, nRF52 기반 board이면 2입니다.

  • 선택한 sample folder의 Zephyr image를 flash합니다.
    nrfjprog --program outdir/<board>/zephyr.hex -f nrf5<x>

    <board>는 build할 때 BOARD directive에 사용한 board name(예: nrf52dk/nrf52832)이고 <x>는 nRF51이면 1, nRF52이면 2입니다.

  • Zephyr를 reset하고 시작합니다.
    nrfjprog --reset -f nrf5<x>

    <x>는 nRF51이면 1, nRF52이면 2입니다.

USB CDC ACM serial port 설정

Windows

Serial port는 COMxx로 나타납니다. Device Manager의 Ports (COM & LPT) 항목에서 확인하십시오.

GNU/Linux

Serial port는 /dev/ttyACMx로 나타납니다. 기본적으로 모든 사용자가 접근할 수 없으므로 다음 command로 사용자를 dialout group에 추가합니다. 적용하려면 다시 login해야 합니다.

sudo usermod -a -G dialout `whoami`

최근 ModemManager가 TTY 형태 device에 AT command를 전송하며 Nordic development kit도 대상입니다. 이 때문에 몇 초 동안 serial port를 사용할 수 없고 application이 UART data를 읽는 경우 오동작할 수 있습니다. Application을 실행하기 전에 다음 command로 ModemManager를 일시적으로 중지·disable할 수 있습니다.

systemctl stop ModemManager.service
systemctl disable ModemManager.service

udev rule을 편집해 Segger device를 blacklist하여 ModemManager가 무시하게 할 수도 있습니다.

sudo sh -c 'echo "ATTRS{idVendor}==\"1366\", ENV{ID_MM_DEVICE_IGNORE}=\"1\" " \
  >> /etc/udev/rules.d/99-segger-modemmanager-blacklist.rules'
sudo service udev restart

이 문제의 수정은 ModemManager 1.8과 새로운 Segger IMCU firmware에 포함될 것으로 예상됩니다.

Apple macOS(OS X)

Serial port는 /dev/tty.usbmodemXXXX로 나타납니다.

Mass Storage Device 기능 disable

Segger J-Link firmware의 알려진 문제 때문에 운영체제와 version에 따라 USB CDC ACM Serial Port에서 64byte보다 큰 packet을 사용할 때 data 손상·drop이 발생할 수 있습니다. GNU/Linux와 macOS(OS X) 모두에서 관찰되었습니다.

이를 피하려면 다음 application을 엽니다.

  • GNU/Linux 또는 macOS(OS X): terminal에서 JLinkExe
  • Microsoft Windows: JLink Commander application

다음을 입력합니다.

MSDDisable

Board를 분리했다가 다시 연결합니다. 이제 Mass Storage Device가 나타나지 않고 virtual Serial Port로 긴 packet을 보낼 수 있어야 합니다. 자세한 내용은 Segger SAM3U Wiki를 참고하십시오.

RTT Console

Segger J-Link는 target(nRF5x board)과 개발 computer 사이에 logging·input용 양방향 terminal 연결을 만드는 Real-Time Tracing(RTT)을 지원합니다. Zephyr도 nRF5x target에서 RTT를 지원합니다. UART(USB CDC ACM)가 hci_uart application의 HCI traffic처럼 logging 이외 용도로 이미 사용될 때 특히 유용합니다.

.conf file에 다음을 추가해 RTT를 enable합니다.

CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

RTT output이 없다면 실행 중인 sample 또는 application에서 기본 enable된 다른 console이 RTT와 충돌할 수 있습니다. 예를 들어 UART console을 disable하려면 .conf에 다음을 추가합니다.

CONFIG_UART_CONSOLE=n

RTT를 enable해 compile·flash한 뒤 운영체제에 맞게 console message를 표시합니다.

Windows

  • J-Link RTT Viewer application을 엽니다.
  • 다음 option을 선택합니다.
    • Connection: USB
    • Target Device: 목록에서 사용 IC 선택
    • Target Interface and Speed: SWD, 4000 KHz
    • RTT Control Block: Auto Detection

GNU/Linux와 macOS(OS X)

  • Terminal에서 JLinkRTTLogger를 엽니다.
  • 다음 option을 선택합니다.
    • Device Name: IC의 fully qualified device name
    • Target Interface: SWD
    • Interface Speed: 4000 KHz
    • RTT Control Block address: auto-detection
    • RTT Channel name or index: 0
    • Output file: filename 또는 terminal에 직접 표시하려면 /dev/stdout

Python viewer

Python RTT viewer는 pyrtt-viewer GitHub repository에서 구할 수 있습니다.

Segger Ozone

Segger J-Link는 Segger Ozone visual debugger와 호환됩니다.

  • Segger Ozone Download에서 내려받습니다.
  • 설치 후 다음과 같이 구성합니다.
    • Target Device: 목록에서 사용 IC 선택
    • Target Interface: SWD
    • Target Interface Speed: 4 MHz
    • Host Interface: USB

구성이 끝나면 File->Open menu에서 build folder의 zephyr.elf file을 엽니다.

참고 자료

이 페이지에서 사용한 제품·도구·문제 추적 자료는 본문 링크에서 각 공식 또는 upstream page로 연결됩니다.

Source

출처

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