blob: aded55deb879b258226f91a36a642b62e8099421 [file] [log] [blame]
Rodrigo Caballero4f976c22016-01-28 10:59:49 -06001.. _getting_started:
2
3Getting Started Guide
4#####################
5
Marti Bolivar0d811b92018-10-14 23:20:24 -06006Follow this guide to set up a :ref:`Zephyr <introducing_zephyr>` development
7environment on your system, and then build and run a sample application.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -05008
Marti Bolivar0d811b92018-10-14 23:20:24 -06009.. _host_setup:
David B. Kinder8b812942017-12-01 16:16:47 -080010
Marti Bolivar0d811b92018-10-14 23:20:24 -060011Set Up a Development System
12***************************
David B. Kinder8b812942017-12-01 16:16:47 -080013
Marti Bolivar0d811b92018-10-14 23:20:24 -060014Follow one of the following guides for your host operating system.
Rodrigo Caballero4f976c22016-01-28 10:59:49 -060015
16.. toctree::
17 :maxdepth: 1
18
Marti Bolivar0d811b92018-10-14 23:20:24 -060019 Linux <installation_linux.rst>
20 macOS <installation_mac.rst>
21 Windows <installation_win.rst>
Rodrigo Caballero4f976c22016-01-28 10:59:49 -060022
Marti Bolivar0d811b92018-10-14 23:20:24 -060023Clone the Zephyr Repository
24***************************
25
26To clone the Zephyr source code repository from GitHub:
27
28.. code-block:: console
29
30 git clone https://github.com/zephyrproject-rtos/zephyr
31
32.. warning::
33
34 Don't clone Zephyr to a directory with spaces anywhere in the path.
35 For example, on Windows, :file:`C:\\Users\\YourName\\zephyr` will
36 work, but :file:`C:\\Users\\Your Name\\zephyr` will cause cryptic
37 errors when you try to build an application.
38
39Install Python Dependencies
40***************************
41
42Next, install additional Python packages required by Zephyr in a shell or
43``cmd.exe`` prompt:
44
45.. code-block:: console
46
47 # Linux
Sebastian Bøee8420d92018-10-24 15:35:30 +020048 pip3 install --user -r zephyr/scripts/requirements.txt
Marti Bolivar0d811b92018-10-14 23:20:24 -060049
50 # macOS and Windows
51 pip3 install -r zephyr/scripts/requirements.txt
52
53Some notes on pip's ``--user`` option:
54
55- Installing with ``--user`` is the default behavior on Debian-based
56 distributions and is generally recommended on Linux to avoid conflicts with
57 Python packages installed using the system package manager.
58
David B. Kinder6871b922018-11-02 11:00:47 -070059- On Linux, verify the Python user install directory ``~/.local/bin`` is at the front of
60 your PATH environment variable, otherwise installed packages won't be
61 found.
62
Marti Bolivar0d811b92018-10-14 23:20:24 -060063- On macOS, Homebrew disables the ``--user`` flag\ [#homebrew_user]_.
64
65- On Windows using ``cmd.exe``, although it's possible to use the ``--user``
66 flag, it makes it harder for the command prompt to find executables installed
67 by pip.
68
David B. Kinder6871b922018-11-02 11:00:47 -070069
Marti Bolivar0d811b92018-10-14 23:20:24 -060070Set Up a Toolchain
71******************
72
73.. note::
74
75 On Linux, you can skip this step if you installed the :ref:`Zephyr SDK
76 <zephyr_sdk>`, which includes toolchains for all supported Zephyr
77 architectures.
78
79 If you want, you can use the SDK host tools (such as OpenOCD) with a
80 different toolchain by keeping the :envvar:`ZEPHYR_SDK_INSTALL_DIR`
81 environment variable set to the Zephyr SDK installation directory, while
82 setting :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` appropriately for a non-SDK
83 toolchain.
84
85Zephyr binaries are compiled using software called a *toolchain*. You need to
86*install* and *configure* a toolchain to develop Zephyr applications\
87[#tools_native_posix]_.
88
89Toolchains can be *installed* in different ways, including using installer
90programs, system package managers, or simply downloading a zip file or other
91archive and extracting the files somewhere on your computer. You *configure*
92the toolchain by setting the environment variable
93:envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to a recognized value, along with some
94additional variable(s) specific to that toolchain (usually, this is just one
95more variable which contains the path where you installed the toolchain on your
96file system).
97
98.. note::
99
100 In previous releases of Zephyr, the ``ZEPHYR_TOOLCHAIN_VARIANT`` variable
101 was called ``ZEPHYR_GCC_VARIANT``.
102
103The following toolchain installation options are available. The right choice
104for you depends on where you want to run Zephyr and any other requirements you
105may have. Check your :ref:`board-level documentation <boards>` if you are
106unsure about what choice to use.
107
108.. toctree::
109 :maxdepth: 2
110
111 toolchain_3rd_party_x_compilers.rst
112 toolchain_other_x_compilers.rst
113 toolchain_custom_cmake.rst
114
115
116To use the same toolchain in new sessions in the future you can make
117sure the variables are set persistently.
118
119On macOS and Linux, you can set the variables by putting the ``export`` lines
120setting environment variables in a file :file:`~/.zephyrrc`. On Windows, you
121can put the ``set`` lines in :file:`%userprofile%\\zephyrrc.cmd`. These files
122are used to modify your environment when you run ``zephyr-env.sh`` (Linux,
123macOS) and ``zephyr-env.cmd`` (Windows), which you will learn about in the next
124step.
Rodrigo Caballero4f976c22016-01-28 10:59:49 -0600125
Marti Bolivar2e3ecd82017-11-02 12:43:43 -0400126.. _getting_started_run_sample:
127
Marti Bolivar0d811b92018-10-14 23:20:24 -0600128Build and Run an Application
129****************************
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500130
Marti Bolivar0d811b92018-10-14 23:20:24 -0600131Next, build a sample Zephyr application. You can then flash and run it on real
132hardware using any supported host system. Depending on your operating system,
133you can also run it in emulation with QEMU or as a native POSIX application.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500134
Marti Bolivar0d811b92018-10-14 23:20:24 -0600135.. _getting_started_cmake:
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500136
Marti Bolivar0d811b92018-10-14 23:20:24 -0600137A Brief Note on the Zephyr Build System
138=======================================
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500139
Marti Bolivar0d811b92018-10-14 23:20:24 -0600140The Zephyr build system uses `CMake`_. CMake creates build systems in different
141formats, called `generators`_. Zephyr supports the following generators:
142
143 * ``Unix Makefiles``: Supported on UNIX-like platforms (Linux, macOS).
144 * ``Ninja``: Supported on all platforms.
145
146This documentation and Zephyr's continuous integration system mainly use
147``Ninja``, but you should be able to use any supported generator to build
148Zephyr applications.
149
150Build the Application
151=====================
152
153Follow these steps to build the :ref:`hello_world` sample application provided
154with Zephyr.
155
156Zephyr applications have to be configured and built to run on some hardware
157configuration, which is called a "board"\ [#board_misnomer]_. These steps show
158how to build the Hello World application for the :ref:`arduino_101` board. You
159can build for a different board by changing ``arduino_101`` to another
160supported value. See :ref:`boards` for more information, or run ``ninja usage``
161from the build directory (once you've run ``cmake``) to get a list.
162
163.. note::
164
165 If you want to re-use your existing build directory to build for another
166 board, you must delete that directory's contents first by running ``ninja
167 pristine``.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500168
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500169#. Navigate to the main project directory:
170
171 .. code-block:: console
172
Carles Cufi72046a82018-01-17 17:32:31 +0100173 cd zephyr
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500174
Marti Bolivarc6c15012018-05-31 15:50:46 -0400175#. Set up your build environment:
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500176
177 .. code-block:: console
178
Carles Cufi72046a82018-01-17 17:32:31 +0100179 # On Linux/macOS
180 source zephyr-env.sh
181 # On Windows
Carles Cufi980c0cf2018-02-12 14:33:59 +0100182 zephyr-env.cmd
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500183
Marti Bolivar0d811b92018-10-14 23:20:24 -0600184#. Build the Hello World sample for the ``arduino_101``:
185
186 .. Note: we don't use :zephyr-app: here because we just told the user to cd
187 to ZEPHYR_BASE, so it's not necessary for clarity and would clutter the
188 instructions a bit.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500189
Carles Cufifa0030a2017-11-09 13:19:27 +0100190 .. zephyr-app-commands::
Marti Bolivar0d811b92018-10-14 23:20:24 -0600191 :app: samples/hello_world
Carles Cufifa0030a2017-11-09 13:19:27 +0100192 :board: arduino_101
Carles Cufifa0030a2017-11-09 13:19:27 +0100193 :goals: build
Anas Nashif602a1432017-10-31 08:35:24 -0400194
Carles Cufi72046a82018-01-17 17:32:31 +0100195 On Linux/macOS you can also build with ``make`` instead of ``ninja``:
196
197 .. zephyr-app-commands::
Marti Bolivar0d811b92018-10-14 23:20:24 -0600198 :app: samples/hello_world
Carles Cufi72046a82018-01-17 17:32:31 +0100199 :generator: make
200 :host-os: unix
201 :board: arduino_101
Carles Cufi72046a82018-01-17 17:32:31 +0100202 :goals: build
203
Marti Bolivar0d811b92018-10-14 23:20:24 -0600204The main build products are in :file:`zephyr/samples/hello_world/build/zephyr`.
205The final application binary in ELF format is named :file:`zephyr.elf` by
206default. Other binary formats and byproducts such as disassembly and map files
207will be present depending on the target and build system configuration.
Anas Nashif602a1432017-10-31 08:35:24 -0400208
Marti Bolivar0d811b92018-10-14 23:20:24 -0600209Other sample projects demonstrating Zephyr's features are located in
210:file:`zephyr/samples` and are documented in :ref:`samples-and-demos`.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500211
Marti Bolivar0d811b92018-10-14 23:20:24 -0600212Run the Application by Flashing to Another Board
213================================================
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500214
Marti Bolivar0d811b92018-10-14 23:20:24 -0600215Most "real hardware" boards supported by Zephyr can be flashed by running
216``ninja flash`` from the build directory. However, this may require
217board-specific tool installation and configuration to work properly.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500218
Marti Bolivar0d811b92018-10-14 23:20:24 -0600219See :ref:`application_run` in the Application Development Primer and the
220documentation provided with your board at :ref:`boards` for additional details
221if you get an error.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500222
Marti Bolivar0d811b92018-10-14 23:20:24 -0600223Run the Application in QEMU
224===========================
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500225
Marti Bolivar0d811b92018-10-14 23:20:24 -0600226On Linux and macOS, you can run Zephyr applications in emulation on your host
227system using QEMU when targeting either the X86 or ARM Cortex-M3 architectures.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500228
Marti Bolivar0d811b92018-10-14 23:20:24 -0600229To build and run Hello World using the x86 emulation board configuration
230(``qemu_x86``), type:
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500231
Carles Cufi72046a82018-01-17 17:32:31 +0100232.. zephyr-app-commands::
233 :zephyr-app: samples/hello_world
234 :host-os: unix
235 :board: qemu_x86
236 :goals: build run
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500237
Marti Bolivar0d811b92018-10-14 23:20:24 -0600238To exit, type :kbd:`Ctrl-a`, then :kbd:`x`.
Sven Dowideit46f530e2017-11-17 15:20:24 +1000239
Marti Bolivar0d811b92018-10-14 23:20:24 -0600240Use the ``qemu_cortex_m3`` board configuration to run on an emulated Arm
241Cortex-M3.
Anas Nashifd0c5eaf2016-02-13 07:41:34 -0500242
Anas Nashif6b555982017-12-21 08:14:19 -0500243Running a Sample Application natively (POSIX OS)
244================================================
245
Marti Bolivar0d811b92018-10-14 23:20:24 -0600246Finally, it is also possible to compile some samples to run as native processes
247on a POSIX OS. This is currently only tested on Linux hosts.
Anas Nashif6b555982017-12-21 08:14:19 -0500248
Marti Bolivar0d811b92018-10-14 23:20:24 -0600249On 64 bit host operating systems, you will also need a 32 bit C library
250installed. See the :ref:`native_posix` section on host dependencies for more
251information.
252
253To compile and run Hello World in this way, type:
Anas Nashif6b555982017-12-21 08:14:19 -0500254
Carles Cufi72046a82018-01-17 17:32:31 +0100255.. zephyr-app-commands::
256 :zephyr-app: samples/hello_world
257 :host-os: unix
258 :board: native_posix
259 :goals: build
Anas Nashif6b555982017-12-21 08:14:19 -0500260
261and then:
262
263.. code-block:: console
264
Carles Cufi72046a82018-01-17 17:32:31 +0100265 ninja run
David B. Kinder9af44d82018-05-10 14:29:12 -0700266
Anas Nashif6b555982017-12-21 08:14:19 -0500267 # or just:
Carles Cufi72046a82018-01-17 17:32:31 +0100268 zephyr/zephyr.exe
Anas Nashif6b555982017-12-21 08:14:19 -0500269 # Press Ctrl+C to exit
270
David B. Kinder9af44d82018-05-10 14:29:12 -0700271You can run ``zephyr/zephyr.exe --help`` to get a list of available
272options. See the :ref:`native_posix` document for more information.
273
Marti Bolivar0d811b92018-10-14 23:20:24 -0600274This executable can be instrumented using standard tools, such as gdb or
275valgrind.
Carles Cufi72046a82018-01-17 17:32:31 +0100276
Marti Bolivar0d811b92018-10-14 23:20:24 -0600277.. rubric:: Footnotes
278
279.. [#homebrew_user]
280
281 For details, see
282 https://docs.brew.sh/Homebrew-and-Python#note-on-pip-install---user.
283
284.. [#tools_native_posix]
285
286 Usually, the toolchain is a cross-compiler and related tools which are
287 different than the host compilers and other programs available for
288 developing software to run natively on your operating system.
289
290 One exception is when building Zephyr as a host binary to run on a POSIX
291 operating system. In this case, you still need to set up a toolchain, but it
292 will provide host compilers instead of cross compilers. For details on this
293 option, see :ref:`native_posix`.
294
295.. [#board_misnomer]
296
297 This has become something of a misnomer over time. While the target can be,
298 and often is, a microprocessor running on its own dedicated hardware
299 board, Zephyr also supports using QEMU to run targets built for other
300 architectures in emulation, targets which produce native host system
301 binaries that implement Zephyr's driver interfaces with POSIX APIs, and even
302 running different Zephyr-based binaries on CPU cores of differing
303 architectures on the same physical chip. Each of these hardware
304 configurations is called a "board," even though that doesn't always make
305 perfect sense in context.
306
Carles Cufi72046a82018-01-17 17:32:31 +0100307.. _CMake: https://cmake.org
Marti Bolivar0d811b92018-10-14 23:20:24 -0600308.. _generators: https://cmake.org/cmake/help/v3.8/manual/cmake-generators.7.html