Part 1
요약·해설
Board 요구사항, build 오류, led0 alias와 gpio-leds node를 추가하는 방법을 설명합니다.
led0
gpio_dt_spec
Configure · Toggle
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
91EE7F4C1B86D9A3ED71ACD2A7D0A3B5BD43F9E16A9E93EC8CC7F33CBC66EF10
.. zephyr:code-sample:: blinky
:name: Blinky
:relevant-api: gpio_interface
Blink an LED forever using the GPIO API.
Overview
********
The Blinky sample blinks an LED forever using the :ref:`GPIO API <gpio_api>`.
The source code shows how to:
#. Get a pin specification from the :ref:`devicetree <dt-guide>` as a
:c:struct:`gpio_dt_spec`
#. Configure the GPIO pin as an output
#. Toggle the pin forever
See :zephyr:code-sample:`pwm-blinky` for a similar sample that uses the PWM API instead.
.. _blinky-sample-requirements:
Requirements
************
Your board must:
#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of
Zephyr's :ref:`boards`).
#. Have the LED configured using the ``led0`` devicetree alias.
Building and Running
********************
Build and flash Blinky as follows, changing ``reel_board`` for your board:
.. zephyr-app-commands::
:zephyr-app: samples/basic/blinky
:board: reel_board
:goals: build flash
:compact:
After flashing, the LED starts to blink and messages with the current LED state
are printed on the console. If a runtime error occurs, the sample exits without
printing to the console.
Build errors
************
You will see a build error at the source code line defining the ``struct
gpio_dt_spec led`` variable if you try to build Blinky for an unsupported
board.
On GCC-based toolchains, the error looks like this:
.. code-block:: none
error: '__device_dts_ord_DT_N_ALIAS_led_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
Adding board support
********************
To add support for your board, add something like this to your devicetree:
.. code-block:: DTS
/ {
aliases {
led0 = &myled0;
};
leds {
compatible = "gpio-leds";
myled0: led_0 {
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
};
};
};
The above sets your board's ``led0`` alias to use pin 13 on GPIO controller
``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when
the pin is set to its high state, and off when the pin is in its low state.
Tips:
- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs
in devicetree.
- If you're not sure what to do, check the devicetrees for supported boards which
use the same SoC as your target. See :ref:`get-devicetree-outputs` for details.
- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use
in devicetree.
- If the LED is built in to your board hardware, the alias should be defined in
your :ref:`BOARD.dts file <devicetree-in-out-files>`. Otherwise, you can
define one in a :ref:`devicetree overlay <set-devicetree-overlays>`.
Part 3
한국어 전문 번역
개요
Blinky sample은 GPIO API를 사용해 LED를 계속 깜박입니다.
Source code는 다음 방법을 보여줍니다.
- Devicetree에서 pin specification을
gpio_dt_spec구조체로 가져오기 - GPIO pin을 output으로 configuration하기
- Pin 상태를 계속 toggle하기
PWM API를 사용하는 비슷한 sample은 PWM Blinky를 참조하십시오.
요구사항
Board는 다음 조건을 충족해야 합니다.
- GPIO pin으로 연결된 LED가 있어야 합니다. 많은 Zephyr board에서는 이를 User LED라고 부릅니다.
- LED가
led0Devicetree alias로 configuration돼 있어야 합니다.
Build와 실행
다음과 같이 Blinky를 build하고 flash합니다. reel_board는 사용할 board 이름으로 바꾸십시오.
west build -b reel_board samples/basic/blinky
west flash
Flash가 끝나면 LED가 깜박이기 시작하고 현재 LED 상태를 나타내는 message가 console에 출력됩니다. Runtime error가 발생하면 sample은 console에 출력하지 않고 종료합니다.
Build 오류
지원하지 않는 board용으로 Blinky를 build하면 struct gpio_dt_spec led 변수를 정의한 source code 줄에서 build error가 발생합니다.
GCC 기반 toolchain에서는 다음과 같은 오류가 나타납니다.
error: '__device_dts_ord_DT_N_ALIAS_led_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
Board 지원 추가
Board를 지원하려면 다음과 비슷한 내용을 Devicetree에 추가합니다.
/ {
aliases {
led0 = &myled0;
};
leds {
compatible = "gpio-leds";
myled0: led_0 {
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
};
};
};
위 설정은 board의 led0 alias가 GPIO controller gpio0의 pin 13을 사용하게 합니다. GPIO_ACTIVE_HIGH pin flag를 사용하면 pin이 high일 때 LED가 켜지고 low일 때 꺼집니다.
참고사항:
- Devicetree에서 GPIO 기반 LED를 정의하는 자세한 방법은
gpio-ledsbinding을 참조하십시오. - 어떻게 작성할지 확실하지 않다면 target과 같은 SoC를 사용하는 지원 board의 Devicetree를 확인하십시오. Devicetree output 확인 문서도 참고할 수 있습니다.
- Devicetree에서 사용할 수 있는 flag는
include/zephyr/dt-bindings/gpio/gpio.h를 참조하십시오. - LED가 board hardware에 내장돼 있다면 alias는
BOARD.dtsfile에 정의해야 합니다. 외부 LED라면 Devicetree overlay에 정의할 수 있습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.