README.rst
1.. zephyr:code-sample:: multi-thread-blinky
2 :name: Basic thread manipulation
3 :relevant-api: gpio_interface thread_apis
4
5 Spawn multiple threads that blink LEDs and print information to the console.
6
7Overview
8********
9
10This example demonstrates spawning multiple threads using
11:c:func:`K_THREAD_DEFINE`. It spawns three threads. Each thread is then defined
12at compile time using K_THREAD_DEFINE.
13
14The first two each control an LED. These LEDs, ``led0`` and ``led1``, have
15loop control and timing logic controlled by separate functions.
16
17- ``blink0()`` controls ``led0`` and has a 100ms sleep cycle
18- ``blink1()`` controls ``led1`` and has a 1000ms sleep cycle
19
20When either of these threads toggles its LED, it also pushes information into a
21:ref:`FIFO <fifos_v2>` identifying the thread/LED and how many times it has
22been toggled.
23
24The third thread uses :c:func:`printk` to print the information added to the
25FIFO to the device console.
26
27Requirements
28************
29
30The board must have two LEDs connected via GPIO pins. These are called "User
31LEDs" on many of Zephyr's :ref:`boards`. The LEDs must be configured using the
32``led0`` and ``led1`` :ref:`devicetree <dt-guide>` aliases, usually in the
33:ref:`BOARD.dts file <devicetree-in-out-files>`.
34
35You will see one of these errors if you try to build this sample for an
36unsupported board:
37
38.. code-block:: none
39
40 Unsupported board: led0 devicetree alias is not defined
41 Unsupported board: led1 devicetree alias is not defined
42
43Building
44********
45
46For example, to build this sample for :ref:`96b_carbon_board`:
47
48.. zephyr-app-commands::
49 :zephyr-app: samples/basic/threads
50 :board: 96b_carbon/stm32f401xe
51 :goals: build flash
52 :compact:
53
54Change ``96b_carbon/stm32f401xe`` appropriately for other supported boards.
55