1.. _getting_started: 2 3Getting Started Guide 4##################### 5 6Follow this guide to: 7 8- Set up a command-line Zephyr development environment on Ubuntu, macOS, or 9 Windows (instructions for other Linux distributions are discussed in 10 :ref:`installation_linux`) 11- Get the source code 12- Build, flash, and run a sample application 13 14.. _host_setup: 15 16Select and Update OS 17******************** 18 19Click the operating system you are using. 20 21.. tabs:: 22 23 .. group-tab:: Ubuntu 24 25 This guide covers Ubuntu version 22.04 LTS and later. 26 If you are using a different Linux distribution see :ref:`installation_linux`. 27 28 .. code-block:: bash 29 30 sudo apt update 31 sudo apt upgrade 32 33 .. group-tab:: macOS 34 35 On macOS Mojave or later, select *System Preferences* > 36 *Software Update*. Click *Update Now* if necessary. 37 38 On other versions, see `this Apple support topic 39 <https://support.apple.com/en-us/HT201541>`_. 40 41 .. group-tab:: Windows 42 43 Select *Start* > *Settings* > *Update & Security* > *Windows Update*. 44 Click *Check for updates* and install any that are available. 45 46.. _install-required-tools: 47 48Install dependencies 49******************** 50 51Next, you'll install some host dependencies using your package manager. 52 53The current minimum required version for the main dependencies are: 54 55.. list-table:: 56 :header-rows: 1 57 58 * - Tool 59 - Min. Version 60 61 * - `CMake <https://cmake.org/>`_ 62 - 3.20.5 63 64 * - `Python <https://www.python.org/>`_ 65 - 3.10 66 67 * - `Devicetree compiler <https://www.devicetree.org/>`_ 68 - 1.4.6 69 70.. tabs:: 71 72 .. group-tab:: Ubuntu 73 74 .. _install_dependencies_ubuntu: 75 76 #. Use ``apt`` to install the required dependencies: 77 78 .. code-block:: bash 79 80 sudo apt install --no-install-recommends git cmake ninja-build gperf \ 81 ccache dfu-util device-tree-compiler wget python3-dev python3-venv python3-tk \ 82 xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 83 84 .. note:: 85 86 Due to the unavailability of ``gcc-multilib`` and ``g++-multilib`` on AArch64 87 (ARM64) systems, you may need to omit them from the list of packages to install. 88 89 #. Verify the versions of the main dependencies installed on your system by entering: 90 91 .. code-block:: bash 92 93 cmake --version 94 python3 --version 95 dtc --version 96 97 Check those against the versions in the table in the beginning of this section. 98 Refer to the :ref:`installation_linux` page for additional information on updating 99 the dependencies manually. 100 101 .. group-tab:: macOS 102 103 .. _install_dependencies_macos: 104 105 #. Install `Homebrew <https://brew.sh/>`_: 106 107 .. code-block:: bash 108 109 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 110 111 #. After the Homebrew installation script completes, follow the on-screen 112 instructions to add the Homebrew installation to the path. 113 114 * On macOS running on Apple Silicon, this is achieved with: 115 116 .. code-block:: bash 117 118 (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile 119 source ~/.zprofile 120 121 * On macOS running on Intel, use the command for Apple Silicon, but replace ``/opt/homebrew/`` with ``/usr/local/``. 122 123 #. Use ``brew`` to install the required dependencies: 124 125 .. code-block:: bash 126 127 brew install cmake ninja gperf python3 python-tk ccache qemu dtc libmagic wget openocd 128 129 #. Add the Homebrew Python folder to the path, in order to be able to 130 execute ``python`` and ``pip`` as well ``python3`` and ``pip3``. 131 132 .. code-block:: bash 133 134 (echo; echo 'export PATH="'$(brew --prefix)'/opt/python/libexec/bin:$PATH"') >> ~/.zprofile 135 source ~/.zprofile 136 137 .. group-tab:: Windows 138 139 .. note:: 140 141 Due to issues finding executables, the Zephyr Project doesn't 142 currently support application flashing using the `Windows Subsystem 143 for Linux (WSL) 144 <https://msdn.microsoft.com/en-us/commandline/wsl/install_guide>`_ 145 (WSL). 146 147 Therefore, we don't recommend using WSL when getting started. 148 149 In modern version of Windows (10 and later) it is recommended to install the Windows Terminal 150 application from the Microsoft Store. Instructions are provided for a ``cmd.exe`` or 151 PowerShell command prompts. 152 153 These instructions rely on Windows' official package manager, `winget`_. 154 If using winget isn't an option, you can install dependencies from their 155 respective websites and ensure the command line tools are on your 156 :envvar:`PATH` :ref:`environment variable <env_vars>`. 157 158 |p| 159 160 .. _install_dependencies_windows: 161 162 #. In modern Windows versions, winget is already pre-installed by default. 163 You can verify that this is the case by typing ``winget`` in a terminal 164 window. If that fails, you can then `install winget`_. 165 166 #. Open a Command Prompt (``cmd.exe``) or PowerShell terminal window. 167 To do so, press the Windows key, type ``cmd.exe`` or PowerShell and 168 click on the result. 169 170 #. Use ``winget`` to install the required dependencies: 171 172 .. code-block:: bat 173 174 winget install Kitware.CMake Ninja-build.Ninja oss-winget.gperf Python.Python.3.12 Git.Git oss-winget.dtc wget 7zip.7zip 175 176 #. Close the terminal window. 177 178 .. note:: 179 180 You may need to add the 7zip installation folder to your ``PATH``. 181 182 183.. _winget: https://learn.microsoft.com/en-us/windows/package-manager/ 184.. _install winget: https://aka.ms/getwinget 185 186.. _get_the_code: 187.. _clone-zephyr: 188.. _install_py_requirements: 189.. _gs_python_deps: 190 191Get Zephyr and install Python dependencies 192****************************************** 193 194Next, clone Zephyr and its :ref:`modules <modules>` into a new :ref:`west 195<west>` workspace. In the following instructions the name :file:`zephyrproject` 196is used for the workspace, however in practice its name and location can be freely 197chosen. You'll also install Zephyr's additional Python dependencies in a 198`Python virtual environment`_. 199 200.. _Python virtual environment: https://docs.python.org/3/library/venv.html 201 202.. tabs:: 203 204 .. group-tab:: Ubuntu 205 206 #. Create a new virtual environment: 207 208 .. code-block:: bash 209 210 python3 -m venv ~/zephyrproject/.venv 211 212 #. Activate the virtual environment: 213 214 .. code-block:: bash 215 216 source ~/zephyrproject/.venv/bin/activate 217 218 Once activated your shell will be prefixed with ``(.venv)``. The 219 virtual environment can be deactivated at any time by running 220 ``deactivate``. 221 222 .. note:: 223 224 Remember to activate the virtual environment every time you 225 start working. 226 227 #. Install west: 228 229 .. code-block:: bash 230 231 pip install west 232 233 #. Get the Zephyr source code: 234 235 .. only:: not release 236 237 .. code-block:: bash 238 239 west init ~/zephyrproject 240 cd ~/zephyrproject 241 west update 242 243 .. only:: release 244 245 .. We need to use a parsed-literal here because substitutions do not work in code 246 blocks. This means users can't copy-paste these lines as easily as other blocks but 247 should be good enough still :) 248 249 .. parsed-literal:: 250 251 west init ~/zephyrproject --mr v |zephyr-version-ltrim| 252 cd ~/zephyrproject 253 west update 254 255 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 256 automatically load boilerplate code required for building Zephyr 257 applications. 258 259 .. code-block:: bash 260 261 west zephyr-export 262 263 #. Install Python dependencies using ``west packages``. 264 265 .. code-block:: bash 266 267 west packages pip --install 268 269 .. note:: 270 271 This could downgrade or upgrade west itself. 272 273 .. group-tab:: macOS 274 275 #. Create a new virtual environment: 276 277 .. code-block:: bash 278 279 python3 -m venv ~/zephyrproject/.venv 280 281 #. Activate the virtual environment: 282 283 .. code-block:: bash 284 285 source ~/zephyrproject/.venv/bin/activate 286 287 Once activated your shell will be prefixed with ``(.venv)``. The 288 virtual environment can be deactivated at any time by running 289 ``deactivate``. 290 291 .. note:: 292 293 Remember to activate the virtual environment every time you 294 start working. 295 296 #. Install west: 297 298 .. code-block:: bash 299 300 pip install west 301 302 #. Get the Zephyr source code: 303 304 .. code-block:: bash 305 306 west init ~/zephyrproject 307 cd ~/zephyrproject 308 west update 309 310 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 311 automatically load boilerplate code required for building Zephyr 312 applications. 313 314 .. code-block:: bash 315 316 west zephyr-export 317 318 #. Install Python dependencies using ``west packages``. 319 320 .. code-block:: bash 321 322 west packages pip --install 323 324 .. note:: 325 326 This could downgrade or upgrade west itself. 327 328 .. group-tab:: Windows 329 330 #. Open a ``cmd.exe`` or PowerShell terminal window **as a regular user** 331 332 #. Create a new virtual environment: 333 334 .. tabs:: 335 336 .. code-tab:: bat 337 338 cd %HOMEPATH% 339 python -m venv zephyrproject\.venv 340 341 .. code-tab:: powershell 342 343 cd $Env:HOMEPATH 344 python -m venv zephyrproject\.venv 345 346 #. Activate the virtual environment: 347 348 .. note:: 349 350 Python's virtual environment activation in PowerShell requires 351 running a script itself, which needs to be allowed. 352 353 .. code-block:: powershell 354 355 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 356 357 .. tabs:: 358 359 .. code-tab:: bat 360 361 zephyrproject\.venv\Scripts\activate.bat 362 363 .. code-tab:: powershell 364 365 zephyrproject\.venv\Scripts\Activate.ps1 366 367 Once activated your shell will be prefixed with ``(.venv)``. The 368 virtual environment can be deactivated at any time by running 369 ``deactivate``. 370 371 .. note:: 372 373 Remember to activate the virtual environment every time you 374 start working. 375 376 #. Install west: 377 378 .. code-block:: bat 379 380 pip install west 381 382 #. Get the Zephyr source code: 383 384 .. code-block:: bat 385 386 west init zephyrproject 387 cd zephyrproject 388 west update 389 390 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 391 automatically load boilerplate code required for building Zephyr 392 applications. 393 394 .. code-block:: bat 395 396 west zephyr-export 397 398 #. Install Python dependencies using ``west packages``. 399 400 .. tabs:: 401 402 .. code-tab:: bat 403 404 cmd /c scripts\utils\west-packages-pip-install.cmd 405 406 .. code-tab:: powershell 407 408 python -m pip install @((west packages pip) -split ' ') 409 410 .. note:: 411 412 This could downgrade or upgrade west itself. 413 414Install the Zephyr SDK 415********************** 416 417The :ref:`Zephyr Software Development Kit (SDK) <toolchain_zephyr_sdk>` 418contains toolchains for each of Zephyr's supported architectures, which 419include a compiler, assembler, linker and other programs required to build 420Zephyr applications. 421 422For Linux, it also contains additional host tools, such as custom QEMU and OpenOCD builds 423that are used to emulate, flash and debug Zephyr applications. 424 425 426.. tabs:: 427 428 .. group-tab:: Ubuntu 429 430 Install the Zephyr SDK using the ``west sdk install``. 431 432 .. code-block:: bash 433 434 cd ~/zephyrproject/zephyr 435 west sdk install 436 437 .. tip:: 438 439 Using the command options, you can specify the SDK installation destination 440 and which architecture of toolchains to install. 441 See ``west sdk install --help`` for details. 442 443 .. group-tab:: macOS 444 445 Install the Zephyr SDK using the ``west sdk install``. 446 447 .. code-block:: bash 448 449 cd ~/zephyrproject/zephyr 450 west sdk install 451 452 .. tip:: 453 454 Using the command options, you can specify the SDK installation destination 455 and which architecture of toolchains to install. 456 See ``west sdk install --help`` for details. 457 458 .. group-tab:: Windows 459 460 Install the Zephyr SDK using the ``west sdk install``. 461 462 .. tabs:: 463 464 .. code-tab:: bat 465 466 cd %HOMEPATH%\zephyrproject\zephyr 467 west sdk install 468 469 .. code-tab:: powershell 470 471 cd $Env:HOMEPATH\zephyrproject\zephyr 472 west sdk install 473 474 .. tip:: 475 476 Using the command options, you can specify the SDK installation destination 477 and which architecture of toolchains to install. 478 See ``west sdk install --help`` for details. 479 480.. note:: 481 482 If you want to install Zephyr SDK without using the ``west sdk`` command, 483 please see :ref:`toolchain_zephyr_sdk_install`. 484 485.. _getting_started_run_sample: 486 487Build the Blinky Sample 488*********************** 489 490.. note:: 491 492 :zephyr:code-sample:`blinky` is compatible with most, but not all, :ref:`boards`. If your board 493 does not meet Blinky's :ref:`blinky-sample-requirements`, then 494 :zephyr:code-sample:`hello_world` is a good alternative. 495 496 If you are unsure what name west uses for your board, ``west boards`` 497 can be used to obtain a list of all boards Zephyr supports. 498 499Build the :zephyr:code-sample:`blinky` with :ref:`west build <west-building>`, changing 500``<your-board-name>`` appropriately for your board: 501 502.. tabs:: 503 504 .. group-tab:: Ubuntu 505 506 .. code-block:: bash 507 508 cd ~/zephyrproject/zephyr 509 west build -p always -b <your-board-name> samples/basic/blinky 510 511 .. group-tab:: macOS 512 513 .. code-block:: bash 514 515 cd ~/zephyrproject/zephyr 516 west build -p always -b <your-board-name> samples/basic/blinky 517 518 .. group-tab:: Windows 519 520 .. tabs:: 521 522 .. code-tab:: bat 523 524 cd %HOMEPATH%\zephyrproject\zephyr 525 west build -p always -b <your-board-name> samples\basic\blinky 526 527 .. code-tab:: powershell 528 529 cd $Env:HOMEPATH\zephyrproject\zephyr 530 west build -p always -b <your-board-name> samples\basic\blinky 531 532The ``-p always`` option forces a pristine build, and is recommended for new 533users. Users may also use the ``-p auto`` option, which will use 534heuristics to determine if a pristine build is required, such as when building 535another sample. 536 537.. note:: 538 539 A board may contain one or multiple SoCs, Also, each SoC may contain one or 540 more CPU clusters. 541 When building for such boards it is necessary to specify the SoC or CPU 542 cluster for which the sample must be built. 543 For example to build :zephyr:code-sample:`blinky` for the ``cpuapp`` core on 544 the :zephyr:board:`nrf5340dk` the board must be provided as: 545 ``nrf5340dk/nrf5340/cpuapp``. See also :ref:`board_terminology` for more 546 details. 547 548Flash the Sample 549**************** 550 551Connect your board, usually via USB, and turn it on if there's a power switch. 552If in doubt about what to do, check your board's page in :ref:`boards`. 553 554Then flash the sample using :ref:`west flash <west-flashing>`: 555 556.. code-block:: shell 557 558 west flash 559 560.. note:: 561 562 You may need to install additional :ref:`host tools <flash-debug-host-tools>` 563 required by your board. The ``west flash`` command will print an error if any 564 required dependencies are missing. 565 566.. note:: 567 568 When using Linux, you may need to configure udev rules the first time 569 of using a debug probe. 570 Please also see :ref:`setting-udev-rules`. 571 572If you're using blinky, the LED will start to blink as shown in this figure: 573 574.. figure:: img/ReelBoard-Blinky.webp 575 :width: 400px 576 :name: reelboard-blinky 577 578 Phytec :ref:`reel_board <reel_board>` running blinky 579 580Next Steps 581********** 582 583Here are some next steps for exploring Zephyr: 584 585* Try other :zephyr:code-sample-category:`samples` 586* Learn about :ref:`application` and the :ref:`west <west>` tool 587* Find out about west's :ref:`flashing and debugging <west-build-flash-debug>` 588 features, or more about :ref:`flashing_and_debugging` in general 589* Check out :ref:`beyond-GSG` for additional setup alternatives and ideas 590* Discover :ref:`project-resources` for getting help from the Zephyr 591 community 592 593.. _troubleshooting_installation: 594 595Troubleshooting Installation 596**************************** 597 598Here are some tips for fixing some issues related to the installation process. 599 600.. _toolchain_zephyr_sdk_update: 601 602Double Check the Zephyr SDK Variables When Updating 603=================================================== 604 605When updating Zephyr SDK, check whether the :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` 606or :envvar:`ZEPHYR_SDK_INSTALL_DIR` environment variables are already set. 607See :ref:`gs_toolchain_update` for more information. 608 609For more information about these environment variables in Zephyr, see :ref:`env_vars_important`. 610 611.. _help: 612 613Asking for Help 614*************** 615 616You can ask for help on a mailing list or on Discord. Please send bug reports and 617feature requests to GitHub. 618 619* **Mailing Lists**: users@lists.zephyrproject.org is usually the right list to 620 ask for help. `Search archives and sign up here`_. 621* **Discord**: You can join with this `Discord invite`_. 622* **GitHub**: Use `GitHub issues`_ for bugs and feature requests. 623 624How to Ask 625========== 626 627.. important:: 628 629 Please search this documentation and the mailing list archives first. Your 630 question may have an answer there. 631 632Don't just say "this isn't working" or ask "is this working?". Include as much 633detail as you can about: 634 635#. What you want to do 636#. What you tried (commands you typed, etc.) 637#. What happened (output of each command, etc.) 638 639Use Copy/Paste 640============== 641 642Please **copy/paste text** instead of taking a picture or a screenshot of it. 643Text includes source code, terminal commands, and their output. 644 645Doing this makes it easier for people to help you, and also helps other users 646search the archives. Unnecessary screenshots exclude vision impaired 647developers; some are major Zephyr contributors. `Accessibility`_ has been 648recognized as a basic human right by the United Nations. 649 650When copy/pasting more than 5 lines of computer text into Discord or Github, 651create a snippet using three backticks to delimit the snippet. 652 653.. _Search archives and sign up here: https://lists.zephyrproject.org/g/users 654.. _Discord invite: https://chat.zephyrproject.org 655.. _GitHub issues: https://github.com/zephyrproject-rtos/zephyr/issues 656.. _Accessibility: https://www.w3.org/standards/webdesign/accessibility 657