1.. _flash-debug-host-tools:
2
3Flash & Debug Host Tools
4########################
5
6This guide describes the software tools you can run on your host workstation to
7flash and debug Zephyr applications.
8
9Zephyr's west tool has built-in support for all of these in its ``flash``,
10``debug``, ``debugserver``, and ``attach`` commands, provided your board
11hardware supports them and your Zephyr board directory's :file:`board.cmake`
12file declares that support properly. See :ref:`west-build-flash-debug` for
13more information on these commands.
14
15.. _atmel_sam_ba_bootloader:
16
17SAM Boot Assistant (SAM-BA)
18***************************
19
20Atmel SAM Boot Assistant (Atmel SAM-BA) allows In-System Programming (ISP)
21from USB or UART host without any external programming interface.  Zephyr
22allows users to develop and program boards with SAM-BA support using
23:ref:`west <west-flashing>`.  Zephyr supports devices with/without ROM
24bootloader and both extensions from Arduino and Adafruit. Full support was
25introduced in Zephyr SDK 0.12.0.
26
27The typical command to flash the board is:
28
29.. code-block:: console
30
31	west flash [ -r bossac ] [ -p /dev/ttyX ] [ --erase ]
32
33.. note::
34
35    By default, flashing with bossac will only erase the flash pages containing
36    the flashed application, leaving other pages untouched. Should you wish to
37    erase the entire flash of the target when flashing, pass the ``--erase``
38    parameter when flashing.
39
40Flash configuration for devices:
41
42.. tabs::
43
44    .. tab:: With ROM bootloader
45
46        These devices don't need any special configuration.  After building your
47        application, just run ``west flash`` to flash the board.
48
49    .. tab:: Without ROM bootloader
50
51        For these devices, the user should:
52
53        1. Define flash partitions required to accommodate the bootloader and
54           application image; see :ref:`flash_map_api` for details.
55        2. Have board :file:`.defconfig` file with the
56           :kconfig:option:`CONFIG_USE_DT_CODE_PARTITION` Kconfig option set to ``y`` to
57           instruct the build system to use these partitions for code relocation.
58           This option can also be set in ``prj.conf`` or any other Kconfig fragment.
59        3. Build and flash the SAM-BA bootloader on the device.
60
61    .. tab:: With compatible SAM-BA bootloader
62
63        For these devices, the user should:
64
65        1. Define flash partitions required to accommodate the bootloader and
66           application image; see :ref:`flash_map_api` for details.
67        2. Have board :file:`.defconfig` file with the
68           :kconfig:option:`CONFIG_BOOTLOADER_BOSSA` Kconfig option set to ``y``.  This will
69           automatically select the :kconfig:option:`CONFIG_USE_DT_CODE_PARTITION` Kconfig
70           option which instruct the build system to use these partitions for code
71           relocation.  The board :file:`.defconfig` file should have
72           :kconfig:option:`CONFIG_BOOTLOADER_BOSSA_ARDUINO` ,
73           :kconfig:option:`CONFIG_BOOTLOADER_BOSSA_ADAFRUIT_UF2` or the
74           :kconfig:option:`CONFIG_BOOTLOADER_BOSSA_LEGACY` Kconfig option set to ``y``
75           to select the right compatible SAM-BA bootloader mode.
76           These options can also be set in ``prj.conf`` or any other Kconfig fragment.
77        3. Build and flash the SAM-BA bootloader on the device.
78
79.. note::
80
81    The :kconfig:option:`CONFIG_BOOTLOADER_BOSSA_LEGACY` Kconfig option should be used
82    as last resource.  Try configure first with Devices without ROM bootloader.
83
84
85Typical flash layout and configuration
86--------------------------------------
87
88For bootloaders that reside on flash, the devicetree partition layout is
89mandatory.  For devices that have a ROM bootloader, they are mandatory when
90the application uses a storage or other non-application partition.  In this
91special case, the boot partition should be omitted and code_partition should
92start from offset 0.  It is necessary to define the partitions with sizes that
93avoid overlaps, always.
94
95A typical flash layout for devices without a ROM bootloader is:
96
97.. code-block:: devicetree
98
99	/ {
100		chosen {
101			zephyr,code-partition = &code_partition;
102		};
103	};
104
105	&flash0 {
106		partitions {
107			compatible = "fixed-partitions";
108			#address-cells = <1>;
109			#size-cells = <1>;
110
111			boot_partition: partition@0 {
112				label = "sam-ba";
113				reg = <0x00000000 0x2000>;
114				read-only;
115			};
116
117			code_partition: partition@2000 {
118				label = "code";
119				reg = <0x2000 0x3a000>;
120				read-only;
121			};
122
123			/*
124			* The final 16 KiB is reserved for the application.
125			* Storage partition will be used by FCB/LittleFS/NVS
126			* if enabled.
127			*/
128			storage_partition: partition@3c000 {
129				label = "storage";
130				reg = <0x0003c000 0x00004000>;
131			};
132		};
133	};
134
135A typical flash layout for devices with a ROM bootloader and storage
136partition is:
137
138.. code-block:: devicetree
139
140	/ {
141		chosen {
142			zephyr,code-partition = &code_partition;
143		};
144	};
145
146	&flash0 {
147		partitions {
148			compatible = "fixed-partitions";
149			#address-cells = <1>;
150			#size-cells = <1>;
151
152			code_partition: partition@0 {
153				label = "code";
154				reg = <0x0 0xF0000>;
155				read-only;
156			};
157
158			/*
159			* The final 64 KiB is reserved for the application.
160			* Storage partition will be used by FCB/LittleFS/NVS
161			* if enabled.
162			*/
163			storage_partition: partition@F0000 {
164				label = "storage";
165				reg = <0x000F0000 0x00100000>;
166			};
167		};
168	};
169
170
171Enabling SAM-BA runner
172----------------------
173
174In order to instruct Zephyr west tool to use the SAM-BA bootloader the
175:file:`board.cmake` file must have
176``include(${ZEPHYR_BASE}/boards/common/bossac.board.cmake)`` entry.  Note that
177Zephyr tool accept more entries to define multiple runners.  By default, the
178first one will be selected when using ``west flash`` command.  The remaining
179options are available passing the runner option, for instance
180``west flash -r bossac``.
181
182
183More implementation details can be found in the :ref:`boards` documentation.
184As a quick reference, see these three board documentation pages:
185
186  - :zephyr:board:`sam4e_xpro` (ROM bootloader)
187  - :zephyr:board:`adafruit_feather_m0_basic_proto` (Adafruit UF2 bootloader)
188  - :ref:`arduino_nano_33_iot` (Arduino bootloader)
189  - :ref:`arduino_nano_33_ble` (Arduino legacy bootloader)
190
191Enabling BOSSAC on Windows Native [Experimental]
192------------------------------------------------
193
194Zephyr SDK´s bossac is currently supported on Linux and macOS only. Windows support
195can be achieved by using the bossac version from `BOSSA official releases`_.
196After installing using default options, the :file:`bossac.exe` must be added to
197Windows PATH. A specific bossac executable can be used by passing the
198``--bossac`` option, as follows:
199
200.. code-block:: console
201
202    west flash -r bossac --bossac="C:\Program Files (x86)\BOSSA\bossac.exe" --bossac-port="COMx"
203
204.. note::
205
206   WSL is not currently supported.
207
208
209.. _linkserver-debug-host-tools:
210
211LinkServer Debug  Host Tools
212****************************
213
214Linkserver is a utility for launching and managing GDB servers for NXP debug probes,
215which also provides a command-line target flash programming capabilities.
216Linkserver can be used with the `NXP MCUXpresso for Visual Studio Code`_ implementation,
217with custom debug configurations based on GNU tools or as part of a headless solution
218for continuous integration and test. LinkServer can be used with MCU-Link, LPC-Link2,
219LPC11U35-based and OpenSDA based standalone or on-board debug probes from NXP.
220
221NXP recommends installing LinkServer by using NXP's `MCUXpresso Installer`_.
222This method will also install the tools supporting the debug probes below,
223including NXP's MCU-Link and LPCScrypt tools.
224
225LinkServer is compatible with the following debug probes:
226
227- :ref:`lpclink2-cmsis-onboard-debug-probe`
228- :ref:`mcu-link-cmsis-onboard-debug-probe`
229- :ref:`opensda-daplink-onboard-debug-probe`
230
231To use LinkServer with West commands, the install folder should be added to the
232:envvar:`PATH` :ref:`environment variable <env_vars>`.  The default installation
233path to add is:
234
235.. tabs::
236
237   .. group-tab:: Linux
238
239      .. code-block:: console
240
241         /usr/local/LinkServer
242
243   .. group-tab:: Windows
244
245      .. code-block:: console
246
247         c:\nxp\LinkServer_<version>
248
249Supported west commands:
250
2511. flash
252#. debug
253#. debugserver
254#. attach
255
256Notes:
257
258
2591. Probes can be listed with LinkServer:
260
261.. code-block:: console
262
263   LinkServer probes
264
2652. With multiple debug probes attached to the host, use the
266LinkServer west runner   ``--probe`` option to pass the probe index.
267
268.. code-block:: console
269
270   west flash --runner=linkserver --probe=3
271
2723. Device-specific settings can be overridden with the west runner for LinkServer with
273   the option '--override'. May be used multiple times. The format is dictated
274   by LinkServer, e.g.:
275
276.. code-block:: console
277
278   west flash --runner=linkserver --override /device/memory/5/flash-driver=MIMXRT500_SFDP_MXIC_OSPI_S.cfx
279
2804. LinkServer does not install an implicit breakpoint at the reset handler. If
281   you would like to single step from the start of their application, you
282   will need to add a breakpoint at ``main`` or the reset handler manually.
283
284.. _jlink-debug-host-tools:
285
286J-Link Debug Host Tools
287***********************
288
289Segger provides a suite of debug host tools for Linux, macOS, and Windows
290operating systems:
291
292- J-Link GDB Server: GDB remote debugging
293- J-Link Commander: Command-line control and flash programming
294- RTT Viewer: RTT terminal input and output
295- SystemView: Real-time event visualization and recording
296
297These debug host tools are compatible with the following debug probes:
298
299- :ref:`lpclink2-jlink-onboard-debug-probe`
300- :ref:`opensda-jlink-onboard-debug-probe`
301- :ref:`mcu-link-jlink-onboard-debug-probe`
302- :ref:`jlink-external-debug-probe`
303- :ref:`stlink-v21-onboard-debug-probe`
304
305Check if your SoC is listed in `J-Link Supported Devices`_.
306
307Download and install the `J-Link Software and Documentation Pack`_ to get the
308J-Link GDB Server and Commander, and to install the associated USB device
309drivers. RTT Viewer and SystemView can be downloaded separately, but are not
310required.
311
312Note that the J-Link GDB server does not yet support Zephyr RTOS-awareness.
313
314.. _openocd-debug-host-tools:
315
316OpenOCD Debug Host Tools
317************************
318
319OpenOCD is a community open source project that provides GDB remote debugging
320and flash programming support for a wide range of SoCs. A fork that adds Zephyr
321RTOS-awareness is included in the Zephyr SDK; otherwise see `Getting OpenOCD`_
322for options to download OpenOCD from official repositories.
323
324These debug host tools are compatible with the following debug probes:
325
326- :ref:`opensda-daplink-onboard-debug-probe`
327- :ref:`jlink-external-debug-probe`
328- :ref:`stlink-v21-onboard-debug-probe`
329
330Check if your SoC is listed in `OpenOCD Supported Devices`_.
331
332.. note:: On Linux, openocd is available though the `Zephyr SDK
333   <https://github.com/zephyrproject-rtos/sdk-ng/releases>`_.
334   Windows users should use the following steps to install
335   openocd:
336
337   - Download openocd for Windows from here: `OpenOCD Windows`_
338   - Copy bin and share dirs to ``C:\Program Files\OpenOCD\``
339   - Add ``C:\Program Files\OpenOCD\bin`` to 'PATH' environment variable
340
341.. _pyocd-debug-host-tools:
342
343pyOCD Debug Host Tools
344**********************
345
346pyOCD is an open source project from Arm that provides GDB remote debugging and
347flash programming support for Arm Cortex-M SoCs. It is distributed on PyPi and
348installed when you complete the :ref:`gs_python_deps` step in the Getting
349Started Guide. pyOCD includes support for Zephyr RTOS-awareness.
350
351These debug host tools are compatible with the following debug probes:
352
353- :ref:`lpclink2-cmsis-onboard-debug-probe`
354- :ref:`mcu-link-cmsis-onboard-debug-probe`
355- :ref:`opensda-daplink-onboard-debug-probe`
356- :ref:`stlink-v21-onboard-debug-probe`
357
358Check if your SoC is listed in `pyOCD Supported Devices`_.
359
360.. _lauterbach-trace32-debug-host-tools:
361
362Lauterbach TRACE32 Debug Host Tools
363***********************************
364
365`Lauterbach TRACE32`_ is a product line of microprocessor development tools,
366debuggers and real-time tracer with support for JTAG, SWD, NEXUS or ETM over
367multiple core architectures, including Arm Cortex-A/-R/-M, RISC-V, Xtensa, etc.
368Zephyr allows users to develop and program boards with Lauterbach TRACE32
369support using :ref:`west <west-flashing>`.
370
371The runner consists of a wrapper around TRACE32 software, and allows a Zephyr
372board to execute a custom start-up script (Practice Script) for the different
373commands supported, including the ability to pass extra arguments from CMake.
374Is up to the board using this runner to define the actions performed on each
375command.
376
377Install Lauterbach TRACE32 Software
378-----------------------------------
379
380Download Lauterbach TRACE32 software from the `Lauterbach TRACE32 download website`_
381(registration required) and follow the installation steps described in
382`Lauterbach TRACE32 Installation Guide`_.
383
384Flashing and Debugging
385----------------------
386
387Set the :ref:`environment variable <env_vars>` :envvar:`T32_DIR` to the TRACE32
388system directory. Then execute ``west flash`` or ``west debug`` commands to
389flash or debug the Zephyr application as detailed in :ref:`west-build-flash-debug`.
390The ``debug`` command launches TRACE32 GUI to allow debug the Zephyr
391application, while the ``flash`` command hides the GUI and perform all
392operations in the background.
393
394By default, the ``t32`` runner will launch TRACE32 using the default
395configuration file named ``config.t32`` located in the TRACE32 system
396directory. To use a different configuration file, supply the argument
397``--config CONFIG`` to the runner, for example:
398
399.. code-block:: console
400
401	west flash --config myconfig.t32
402
403For more options, run ``west flash --context -r t32`` to print the usage.
404
405Zephyr RTOS Awareness
406---------------------
407
408To enable Zephyr RTOS awareness follow the steps described in
409`Lauterbach TRACE32 Zephyr OS Awareness Manual`_.
410
411.. _nxp-s32-debug-host-tools:
412
413NXP S32 Debug Probe Host Tools
414******************************
415
416:ref:`nxp-s32-debug-probe` is designed to work in conjunction with
417`NXP S32 Design Studio for S32 Platform`_.
418
419Download (registration required) NXP S32 Design Studio for S32 Platform and
420follow the `S32 Design Studio for S32 Platform Installation User Guide`_ to get
421the necessary debug host tools and associated USB device drivers.
422
423Note that Zephyr RTOS-awareness support for the NXP S32 GDB server depends on
424the target device. Consult the product release notes for more information.
425
426Supported west commands:
427
4281. debug
429#. debugserver
430#. attach
431
432Basic usage
433-----------
434
435Before starting, add NXP S32 Design Studio installation directory to the system
436:ref:`PATH environment variable <env_vars>`. Alternatively, it can be passed to
437the runner on each invocation via ``--s32ds-path`` as shown below:
438
439.. tabs::
440
441   .. group-tab:: Linux
442
443      .. code-block:: console
444
445         west debug --s32ds-path=/opt/NXP/S32DS.3.5
446
447   .. group-tab:: Windows
448
449      .. code-block:: console
450
451         west debug --s32ds-path=C:\NXP\S32DS.3.5
452
453If multiple S32 debug probes are connected to the host via USB, the runner will
454ask the user to select one via command line prompt before continuing. The
455connection string for the probe can be also specified when invoking the runner
456via ``--dev-id=<connection-string>``. Consult NXP S32 debug probe user manual
457for details on how to construct the connection string. For example, if using a
458probe with serial ID ``00:04:9f:00:ca:fe``:
459
460.. code-block:: console
461
462   west debug --dev-id='s32dbg:00:04:9f:00:ca:fe'
463
464It is possible to pass extra options to the debug host tools via ``--tool-opt``.
465When executing ``debug`` or ``attach`` commands, the tool options will be passed
466to the GDB client only. When executing ``debugserver``, the tool options will be
467passed to the GDB server. For example, to load a Zephyr application to SRAM and
468afterwards detach the debug session:
469
470.. code-block:: console
471
472   west debug --tool-opt='--batch'
473
474probe-rs Debug Host Tools
475*************************
476
477probe-rs is an open-source embedded toolkit written in Rust. It provides
478out-of-the-box support for a variety of debug probes, including CMSIS-DAP,
479ST-Link, SEGGER J-Link, FTDI and built-in USB-JTAG interface on ESP32 devices.
480
481Check `probe-rs Installation`_ for more setup details.
482
483Check if your SoC is listed in `probe-rs Supported Devices`_.
484
485.. _stm32cubeprog-flash-host-tools:
486
487STM32CubeProgrammer Flash Host Tools
488************************************
489
490STMicroelectronics provides `STM32CubeProgrammer`_ (STM32CubeProg) as an official programming tool
491for STM32 boards on Linux |reg|, macOS |reg|, and Windows |reg| operating systems.
492
493It provides an easy-to-use and efficient environment for reading, writing, and verifying device memory
494through both the debug interface (JTAG and SWD) and the bootloader interface (UART and USB DFU, I2C, SPI, and CAN).
495
496It offers a wide range of features to program STM32 internal memories (such as flash, RAM, and OTP)
497as well as external memories.
498
499It also allows option programming and upload, programming content verification, and programming automation
500through scripting.
501
502It is delivered in GUI (graphical user interface) and CLI (command-line interface) versions.
503
504It is compatible with the following debug probes:
505
506- :ref:`stlink-v21-onboard-debug-probe`
507- :ref:`jlink-external-debug-probe`
508- Standalone `ST-LINK-V2`_, `ST-LINK-V3`_, and `STLINK-V3PWR`_ probes
509
510Install STM32CubeProgrammer
511---------------------------
512
513The easiest way to get `STM32CubeProgrammer`_ is to download it from STMicroelectronics website.
514A valid email address is needed to receive the downloading link.
515
516Alternatively, it can be installed as part of `STM32CubeCLT`_ all-in-one multi-OS command-line toolset
517which also includes GDB debugger client and server.
518
519If you have STM32CubeIDE installed on your system, then STM32CubeProg is already present.
520
521Basic usage
522-----------
523
524`STM32CubeProgrammer`_ is setup as the default west runner for all active STM32 boards supported by Zephyr.
525It can be used through the ``west flash`` command to flash Zephyr applications.
526
527.. code-block:: console
528
529   west flash --runner stm32cubeprogrammer
530
531For advanced usage via the GUI or CLI, check out the `STM32CubeProgrammer User Manual`_.
532
533.. _J-Link Software and Documentation Pack:
534   https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack
535
536.. _J-Link Supported Devices:
537   https://www.segger.com/downloads/supported-devices.php
538
539.. _Getting OpenOCD:
540   https://openocd.org/pages/getting-openocd.html
541
542.. _OpenOCD Supported Devices:
543   https://github.com/zephyrproject-rtos/openocd/tree/latest/tcl/target
544
545.. _pyOCD Supported Devices:
546   https://github.com/pyocd/pyOCD/tree/main/pyocd/target/builtin
547
548.. _OpenOCD Windows:
549    http://gnutoolchains.com/arm-eabi/openocd/
550
551.. _Lauterbach TRACE32:
552    https://www.lauterbach.com/
553
554.. _Lauterbach TRACE32 download website:
555   http://www.lauterbach.com/download_trace32.html
556
557.. _Lauterbach TRACE32 Installation Guide:
558   https://www2.lauterbach.com/pdf/installation.pdf
559
560.. _Lauterbach TRACE32 Zephyr OS Awareness Manual:
561	https://www2.lauterbach.com/pdf/rtos_zephyr.pdf
562
563.. _BOSSA official releases:
564	https://github.com/shumatech/BOSSA/releases
565
566.. _NXP MCUXpresso for Visual Studio Code:
567	https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-for-visual-studio-code:MCUXPRESSO-VSC
568
569.. _MCUXpresso Installer:
570	https://github.com/nxp-mcuxpresso/vscode-for-mcux/wiki/Dependency-Installation
571
572.. _NXP S32 Design Studio for S32 Platform:
573   https://www.nxp.com/design/software/development-software/s32-design-studio-ide/s32-design-studio-for-s32-platform:S32DS-S32PLATFORM
574
575.. _S32 Design Studio for S32 Platform Installation User Guide:
576   https://www.nxp.com/webapp/Download?colCode=S32DSIG
577
578.. _probe-rs Installation:
579   https://probe.rs/docs/getting-started/installation/
580
581.. _probe-rs Supported Devices:
582   https://probe.rs/targets/
583
584.. _STM32CubeProgrammer:
585   https://www.st.com/en/development-tools/stm32cubeprog.html
586
587.. _STM32CubeCLT:
588   https://www.st.com/en/development-tools/stm32cubeclt.html
589
590.. _STM32CubeProgrammer User Manual:
591   https://www.st.com/resource/en/user_manual/um2237-stm32cubeprogrammer-software-description-stmicroelectronics.pdf
592
593.. _ST-LINK-V2:
594   https://www.st.com/en/development-tools/st-link-v2.html
595
596.. _ST-LINK-V3:
597   https://www.st.com/en/development-tools/stlink-v3set.html
598
599.. _STLINK-V3PWR:
600   https://www.st.com/en/development-tools/stlink-v3pwr.html
601