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 20.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 #. If using an Ubuntu version older than 22.04, it is necessary to add extra 77 repositories to meet the minimum required versions for the main 78 dependencies listed above. In that case, download, inspect and execute 79 the Kitware archive script to add the Kitware APT repository to your 80 sources list. 81 A detailed explanation of ``kitware-archive.sh`` can be found here 82 `kitware third-party apt repository <https://apt.kitware.com/>`_: 83 84 .. code-block:: bash 85 86 wget https://apt.kitware.com/kitware-archive.sh 87 sudo bash kitware-archive.sh 88 89 #. Use ``apt`` to install the required dependencies: 90 91 .. code-block:: bash 92 93 sudo apt install --no-install-recommends git cmake ninja-build gperf \ 94 ccache dfu-util device-tree-compiler wget \ 95 python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ 96 make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 97 98 #. Verify the versions of the main dependencies installed on your system by entering: 99 100 .. code-block:: bash 101 102 cmake --version 103 python3 --version 104 dtc --version 105 106 Check those against the versions in the table in the beginning of this section. 107 Refer to the :ref:`installation_linux` page for additional information on updating 108 the dependencies manually. 109 110 .. group-tab:: macOS 111 112 .. _install_dependencies_macos: 113 114 #. Install `Homebrew <https://brew.sh/>`_: 115 116 .. code-block:: bash 117 118 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 119 120 #. After the Homebrew installation script completes, follow the on-screen 121 instructions to add the Homebrew installation to the path. 122 123 * On macOS running on Apple Silicon, this is achieved with: 124 125 .. code-block:: bash 126 127 (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile 128 source ~/.zprofile 129 130 * On macOS running on Intel, use the command for Apple Silicon, but replace ``/opt/homebrew/`` with ``/usr/local/``. 131 132 #. Use ``brew`` to install the required dependencies: 133 134 .. code-block:: bash 135 136 brew install cmake ninja gperf python3 python-tk ccache qemu dtc libmagic wget openocd 137 138 #. Add the Homebrew Python folder to the path, in order to be able to 139 execute ``python`` and ``pip`` as well ``python3`` and ``pip3``. 140 141 .. code-block:: bash 142 143 (echo; echo 'export PATH="'$(brew --prefix)'/opt/python/libexec/bin:$PATH"') >> ~/.zprofile 144 source ~/.zprofile 145 146 .. group-tab:: Windows 147 148 .. note:: 149 150 Due to issues finding executables, the Zephyr Project doesn't 151 currently support application flashing using the `Windows Subsystem 152 for Linux (WSL) 153 <https://msdn.microsoft.com/en-us/commandline/wsl/install_guide>`_ 154 (WSL). 155 156 Therefore, we don't recommend using WSL when getting started. 157 158 These instructions must be run in a ``cmd.exe`` command prompt terminal window. 159 In modern version of Windows (10 and later) it is recommended to install the Windows Terminal 160 application from the Microsoft Store. The required commands differ on PowerShell. 161 162 These instructions rely on `Chocolatey`_. If Chocolatey isn't an option, 163 you can install dependencies from their respective websites and ensure 164 the command line tools are on your :envvar:`PATH` :ref:`environment 165 variable <env_vars>`. 166 167 |p| 168 169 .. _install_dependencies_windows: 170 171 #. `Install chocolatey`_. 172 173 #. Open a ``cmd.exe`` terminal window as **Administrator**. To do so, press the Windows key, 174 type ``cmd.exe``, right-click the :guilabel:`Command Prompt` search result, and choose 175 :guilabel:`Run as Administrator`. 176 177 #. Disable global confirmation to avoid having to confirm the 178 installation of individual programs: 179 180 .. code-block:: bat 181 182 choco feature enable -n allowGlobalConfirmation 183 184 #. Use ``choco`` to install the required dependencies: 185 186 .. code-block:: bat 187 188 choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' 189 choco install ninja gperf python311 git dtc-msys2 wget 7zip 190 191 .. warning:: 192 193 As of November 2024, Python 3.13 is not recommended for Zephyr development on Windows, 194 as some required Python dependencies may be difficult to install. 195 196 #. Close the terminal window. 197 198.. _Chocolatey: https://chocolatey.org/ 199.. _Install chocolatey: https://chocolatey.org/install 200 201.. _get_the_code: 202.. _clone-zephyr: 203.. _install_py_requirements: 204.. _gs_python_deps: 205 206Get Zephyr and install Python dependencies 207****************************************** 208 209Next, clone Zephyr and its :ref:`modules <modules>` into a new :ref:`west 210<west>` workspace named :file:`zephyrproject`. You'll also install Zephyr's 211additional Python dependencies in a `Python virtual environment`_. 212 213.. _Python virtual environment: https://docs.python.org/3/library/venv.html 214 215.. tabs:: 216 217 .. group-tab:: Ubuntu 218 219 #. Use ``apt`` to install Python ``venv`` package: 220 221 .. code-block:: bash 222 223 sudo apt install python3-venv 224 225 #. Create a new virtual environment: 226 227 .. code-block:: bash 228 229 python3 -m venv ~/zephyrproject/.venv 230 231 #. Activate the virtual environment: 232 233 .. code-block:: bash 234 235 source ~/zephyrproject/.venv/bin/activate 236 237 Once activated your shell will be prefixed with ``(.venv)``. The 238 virtual environment can be deactivated at any time by running 239 ``deactivate``. 240 241 .. note:: 242 243 Remember to activate the virtual environment every time you 244 start working. 245 246 #. Install west: 247 248 .. code-block:: bash 249 250 pip install west 251 252 #. Get the Zephyr source code: 253 254 .. code-block:: bash 255 256 west init ~/zephyrproject 257 cd ~/zephyrproject 258 west update 259 260 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 261 automatically load boilerplate code required for building Zephyr 262 applications. 263 264 .. code-block:: bash 265 266 west zephyr-export 267 268 #. The Zephyr west extension command, ``west packages`` can be used to install Python 269 dependencies. 270 271 .. code-block:: bash 272 273 west packages pip --install 274 275 .. group-tab:: macOS 276 277 #. Create a new virtual environment: 278 279 .. code-block:: bash 280 281 python3 -m venv ~/zephyrproject/.venv 282 283 #. Activate the virtual environment: 284 285 .. code-block:: bash 286 287 source ~/zephyrproject/.venv/bin/activate 288 289 Once activated your shell will be prefixed with ``(.venv)``. The 290 virtual environment can be deactivated at any time by running 291 ``deactivate``. 292 293 .. note:: 294 295 Remember to activate the virtual environment every time you 296 start working. 297 298 #. Install west: 299 300 .. code-block:: bash 301 302 pip install west 303 304 #. Get the Zephyr source code: 305 306 .. code-block:: bash 307 308 west init ~/zephyrproject 309 cd ~/zephyrproject 310 west update 311 312 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 313 automatically load boilerplate code required for building Zephyr 314 applications. 315 316 .. code-block:: bash 317 318 west zephyr-export 319 320 #. The Zephyr west extension command, ``west packages`` can be used to install Python 321 dependencies. 322 323 .. code-block:: bash 324 325 west packages pip --install 326 327 .. group-tab:: Windows 328 329 #. Open a ``cmd.exe`` terminal window **as a regular user** 330 331 #. Create a new virtual environment: 332 333 .. code-block:: bat 334 335 cd %HOMEPATH% 336 python -m venv zephyrproject\.venv 337 338 #. Activate the virtual environment: 339 340 .. code-block:: bat 341 342 zephyrproject\.venv\Scripts\activate.bat 343 344 Once activated your shell will be prefixed with ``(.venv)``. The 345 virtual environment can be deactivated at any time by running 346 ``deactivate``. 347 348 .. note:: 349 350 Remember to activate the virtual environment every time you 351 start working. 352 353 #. Install west: 354 355 .. code-block:: bat 356 357 pip install west 358 359 #. Get the Zephyr source code: 360 361 .. code-block:: bat 362 363 west init zephyrproject 364 cd zephyrproject 365 west update 366 367 #. Export a :ref:`Zephyr CMake package <cmake_pkg>`. This allows CMake to 368 automatically load boilerplate code required for building Zephyr 369 applications. 370 371 .. code-block:: bat 372 373 west zephyr-export 374 375 #. The Zephyr west extension command, ``west packages`` can be used to install Python 376 dependencies. 377 378 .. code-block:: bat 379 380 west packages pip --install 381 382Install the Zephyr SDK 383********************** 384 385The :ref:`Zephyr Software Development Kit (SDK) <toolchain_zephyr_sdk>` 386contains toolchains for each of Zephyr's supported architectures, which 387include a compiler, assembler, linker and other programs required to build 388Zephyr applications. 389 390For Linux, it also contains additional host tools, such as custom QEMU and OpenOCD builds 391that are used to emulate, flash and debug Zephyr applications. 392 393 394.. tabs:: 395 396 .. group-tab:: Ubuntu 397 398 Install the Zephyr SDK using the ``west sdk install``. 399 400 .. code-block:: bash 401 402 cd ~/zephyrproject/zephyr 403 west sdk install 404 405 .. tip:: 406 407 Using the command options, you can specify the SDK installation destination 408 and which architecture of toolchains to install. 409 See ``west sdk install --help`` for details. 410 411 .. group-tab:: macOS 412 413 Install the Zephyr SDK using the ``west sdk install``. 414 415 .. code-block:: bash 416 417 cd ~/zephyrproject/zephyr 418 west sdk install 419 420 .. tip:: 421 422 Using the command options, you can specify the SDK installation destination 423 and which architecture of toolchains to install. 424 See ``west sdk install --help`` for details. 425 426 .. group-tab:: Windows 427 428 Install the Zephyr SDK using the ``west sdk install``. 429 430 .. code-block:: bat 431 432 cd %HOMEPATH%\zephyrproject\zephyr 433 west sdk install 434 435 .. tip:: 436 437 Using the command options, you can specify the SDK installation destination 438 and which architecture of toolchains to install. 439 See ``west sdk install --help`` for details. 440 441.. note:: 442 443 If you want to install Zephyr SDK without using the ``west sdk`` command, 444 please see :ref:`toolchain_zephyr_sdk_install`. 445 446.. _getting_started_run_sample: 447 448Build the Blinky Sample 449*********************** 450 451.. note:: 452 453 :zephyr:code-sample:`blinky` is compatible with most, but not all, :ref:`boards`. If your board 454 does not meet Blinky's :ref:`blinky-sample-requirements`, then 455 :zephyr:code-sample:`hello_world` is a good alternative. 456 457 If you are unsure what name west uses for your board, ``west boards`` 458 can be used to obtain a list of all boards Zephyr supports. 459 460Build the :zephyr:code-sample:`blinky` with :ref:`west build <west-building>`, changing 461``<your-board-name>`` appropriately for your board: 462 463.. tabs:: 464 465 .. group-tab:: Ubuntu 466 467 .. code-block:: bash 468 469 cd ~/zephyrproject/zephyr 470 west build -p always -b <your-board-name> samples/basic/blinky 471 472 .. group-tab:: macOS 473 474 .. code-block:: bash 475 476 cd ~/zephyrproject/zephyr 477 west build -p always -b <your-board-name> samples/basic/blinky 478 479 .. group-tab:: Windows 480 481 .. code-block:: bat 482 483 cd %HOMEPATH%\zephyrproject\zephyr 484 west build -p always -b <your-board-name> samples\basic\blinky 485 486The ``-p always`` option forces a pristine build, and is recommended for new 487users. Users may also use the ``-p auto`` option, which will use 488heuristics to determine if a pristine build is required, such as when building 489another sample. 490 491.. note:: 492 493 A board may contain one or multiple SoCs, Also, each SoC may contain one or 494 more CPU clusters. 495 When building for such boards it is necessary to specify the SoC or CPU 496 cluster for which the sample must be built. 497 For example to build :zephyr:code-sample:`blinky` for the ``cpuapp`` core on 498 the :ref:`nRF5340DK <nrf5340dk_nrf5340>` the board must be provided as: 499 ``nrf5340dk/nrf5340/cpuapp``. See also :ref:`board_terminology` for more 500 details. 501 502Flash the Sample 503**************** 504 505Connect your board, usually via USB, and turn it on if there's a power switch. 506If in doubt about what to do, check your board's page in :ref:`boards`. 507 508Then flash the sample using :ref:`west flash <west-flashing>`: 509 510.. code-block:: shell 511 512 west flash 513 514.. note:: 515 516 You may need to install additional :ref:`host tools <flash-debug-host-tools>` 517 required by your board. The ``west flash`` command will print an error if any 518 required dependencies are missing. 519 520.. note:: 521 522 When using Linux, you may need to configure udev rules the first time 523 of using a debug probe. 524 Please also see :ref:`setting-udev-rules`. 525 526If you're using blinky, the LED will start to blink as shown in this figure: 527 528.. figure:: img/ReelBoard-Blinky.png 529 :width: 400px 530 :name: reelboard-blinky 531 532 Phytec :ref:`reel_board <reel_board>` running blinky 533 534Next Steps 535********** 536 537Here are some next steps for exploring Zephyr: 538 539* Try other :zephyr:code-sample-category:`samples` 540* Learn about :ref:`application` and the :ref:`west <west>` tool 541* Find out about west's :ref:`flashing and debugging <west-build-flash-debug>` 542 features, or more about :ref:`flashing_and_debugging` in general 543* Check out :ref:`beyond-GSG` for additional setup alternatives and ideas 544* Discover :ref:`project-resources` for getting help from the Zephyr 545 community 546 547.. _troubleshooting_installation: 548 549Troubleshooting Installation 550**************************** 551 552Here are some tips for fixing some issues related to the installation process. 553 554.. _toolchain_zephyr_sdk_update: 555 556Double Check the Zephyr SDK Variables When Updating 557=================================================== 558 559When updating Zephyr SDK, check whether the :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` 560or :envvar:`ZEPHYR_SDK_INSTALL_DIR` environment variables are already set. 561See :ref:`gs_toolchain_update` for more information. 562 563For more information about these environment variables in Zephyr, see :ref:`env_vars_important`. 564 565.. _help: 566 567Asking for Help 568*************** 569 570You can ask for help on a mailing list or on Discord. Please send bug reports and 571feature requests to GitHub. 572 573* **Mailing Lists**: users@lists.zephyrproject.org is usually the right list to 574 ask for help. `Search archives and sign up here`_. 575* **Discord**: You can join with this `Discord invite`_. 576* **GitHub**: Use `GitHub issues`_ for bugs and feature requests. 577 578How to Ask 579========== 580 581.. important:: 582 583 Please search this documentation and the mailing list archives first. Your 584 question may have an answer there. 585 586Don't just say "this isn't working" or ask "is this working?". Include as much 587detail as you can about: 588 589#. What you want to do 590#. What you tried (commands you typed, etc.) 591#. What happened (output of each command, etc.) 592 593Use Copy/Paste 594============== 595 596Please **copy/paste text** instead of taking a picture or a screenshot of it. 597Text includes source code, terminal commands, and their output. 598 599Doing this makes it easier for people to help you, and also helps other users 600search the archives. Unnecessary screenshots exclude vision impaired 601developers; some are major Zephyr contributors. `Accessibility`_ has been 602recognized as a basic human right by the United Nations. 603 604When copy/pasting more than 5 lines of computer text into Discord or Github, 605create a snippet using three backticks to delimit the snippet. 606 607.. _Search archives and sign up here: https://lists.zephyrproject.org/g/users 608.. _Discord invite: https://chat.zephyrproject.org 609.. _GitHub issues: https://github.com/zephyrproject-rtos/zephyr/issues 610.. _Accessibility: https://www.w3.org/standards/webdesign/accessibility 611