66Overview
77********
88
9- Blinky is a simple application which blinks an LED forever using the :ref: `GPIO
10- API <gpio_api>`. The source code shows how to configure GPIO pins as outputs,
11- then turn them on and off.
9+ The Blinky sample blinks an LED forever using the :ref: `GPIO API <gpio_api >`.
1210
13- See :ref: `pwm-blinky-sample ` for a sample which uses the PWM API to blink an
14- LED.
11+ The source code shows how to:
12+
13+ #. Get a pin specification from the :ref: `devicetree <dt-guide >` as a
14+ :c:struct: `gpio_dt_spec `
15+ #. Configure the GPIO pin as an output
16+ #. Toggle the pin forever
17+
18+ See :ref: `pwm-blinky-sample ` for a similar sample that uses the PWM API instead.
1519
1620.. _blinky-sample-requirements :
1721
1822Requirements
1923************
2024
21- You will see this error if you try to build Blinky for an unsupported board:
22-
23- .. code-block :: none
24-
25- Unsupported board: led0 devicetree alias is not defined
25+ Your board must:
2626
27- The board must have an LED connected via a GPIO pin. These are called "User
28- LEDs" on many of Zephyr's :ref: `boards `. The LED must be configured using the
29- ``led0 `` :ref: `devicetree <dt-guide >` alias. This is usually done in the
30- :ref: `BOARD.dts file <devicetree-in-out-files >` or a :ref: `devicetree overlay
31- <set-devicetree-overlays>`.
27+ #. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of
28+ Zephyr's :ref: `boards `).
29+ #. Have the LED configured using the ``led0 `` devicetree alias.
3230
3331Building and Running
3432********************
@@ -41,4 +39,57 @@ Build and flash Blinky as follows, changing ``reel_board`` for your board:
4139 :goals: build flash
4240 :compact:
4341
44- After flashing, the LED starts to blink. Blinky does not print to the console.
42+ After flashing, the LED starts to blink. If a runtime error occurs, the sample
43+ exits without printing to the console.
44+
45+ Build errors
46+ ************
47+
48+ You will see a build error at the source code line defining the ``struct
49+ gpio_dt_spec led `` variable if you try to build Blinky for an unsupported
50+ board.
51+
52+ On GCC-based toolchains, the error looks like this:
53+
54+ .. code-block :: none
55+
56+ error: '__device_dts_ord_DT_N_ALIAS_led_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
57+
58+ Adding board support
59+ ********************
60+
61+ To add support for your board, add something like this to your devicetree:
62+
63+ .. code-block :: DTS
64+
65+ / {
66+ aliases {
67+ led0 = &myled0;
68+ };
69+
70+ leds {
71+ compatible = "gpio-leds";
72+ myled0: led_0 {
73+ gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
74+ };
75+ };
76+ };
77+
78+ The above sets your board's ``led0 `` alias to use pin 13 on GPIO controller
79+ ``gpio0 ``. The pin flags :c:macro: `GPIO_ACTIVE_HIGH ` mean the LED is on when
80+ the pin is set to its high state, and off when the pin is in its low state.
81+
82+ Tips:
83+
84+ - See :dtcompatible: `gpio-leds ` for more information on defining GPIO-based LEDs
85+ in devicetree.
86+
87+ - If you're not sure what to do, check the devicetrees for supported boards which
88+ use the same SoC as your target. See :ref: `get-devicetree-outputs ` for details.
89+
90+ - See :zephyr_file: `include/dt-bindings/gpio/gpio.h ` for the flags you can use
91+ in devicetree.
92+
93+ - If the LED is built in to your board hardware, the alias should be defined in
94+ your :ref: `BOARD.dts file <devicetree-in-out-files >`. Otherwise, you can
95+ define one in a :ref: `devicetree overlay <set-devicetree-overlays >`.
0 commit comments