diff --git a/samples/boards/stm32/power_mgmt/blinky/CMakeLists.txt b/samples/boards/stm32/power_mgmt/blinky/CMakeLists.txt new file mode 100644 index 00000000000..31f7d4fa9d8 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/blinky/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(stm32_pm_blinky) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/stm32/power_mgmt/blinky/README.rst b/samples/boards/stm32/power_mgmt/blinky/README.rst new file mode 100644 index 00000000000..0bf60c75bcd --- /dev/null +++ b/samples/boards/stm32/power_mgmt/blinky/README.rst @@ -0,0 +1,42 @@ +.. _stm32-pm-blinky-sample: + +Blinky +###### + +Overview +******** + +Blinky is a simple application which blinks an LED forever using the :ref:`GPIO +API ` in low power context. + +.. _stm32-pm-blinky-sample-requirements: + +Requirements +************ + +You will see this error if you try to build Blinky for an unsupported board: + +.. code-block:: none + + Unsupported board: led0 devicetree alias is not defined + +The board must have an LED connected via a GPIO pin. These are called "User +LEDs" on many of Zephyr's :ref:`boards`. The LED must be configured using the +``led0`` :ref:`devicetree ` alias. This is usually done in the +:ref:`BOARD.dts file ` or a :ref:`devicetree overlay +`. + +The board should support enabling PM. + +Building and Running +******************** + +Build and flash Blinky as follows, changing ``nucleo_l476rg`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: nucleo_l476rg + :goals: build flash + :compact: + +After flashing, the LED starts to blink. Blinky does not print to the console. diff --git a/samples/boards/stm32/power_mgmt/blinky/prj.conf b/samples/boards/stm32/power_mgmt/blinky/prj.conf new file mode 100644 index 00000000000..a9c79070b58 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/blinky/prj.conf @@ -0,0 +1,15 @@ +CONFIG_GPIO=y + +CONFIG_PM=y +CONFIG_PM_DEVICE=y +CONFIG_PM_DEVICE_RUNTIME=y + +# Disable debug to enter core low power states +# Warning: requires to erase the device for next flashing actions +CONFIG_DEBUG=y + + +# FIXME: Early console not supported due to uart init postponed +CONFIG_BOOT_BANNER=n +# Disable serial to ease debug +CONFIG_SERIAL=n diff --git a/samples/boards/stm32/power_mgmt/blinky/sample.yaml b/samples/boards/stm32/power_mgmt/blinky/sample.yaml new file mode 100644 index 00000000000..d1608dcc89d --- /dev/null +++ b/samples/boards/stm32/power_mgmt/blinky/sample.yaml @@ -0,0 +1,8 @@ +sample: + name: STM32 GPIO Power Management +tests: + sample.boards.stm32.power_mgmt.blinky: + tags: LED power + filter: dt_compat_enabled("zephyr,power-state") and + dt_enabled_alias_with_parent_compat("led0", "gpio-leds") + depends_on: gpio diff --git a/samples/boards/stm32/power_mgmt/blinky/src/main.c b/samples/boards/stm32/power_mgmt/blinky/src/main.c new file mode 100644 index 00000000000..2fcc64dce65 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/blinky/src/main.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + + +#define SLEEP_TIME_MS 2000 + +static const struct gpio_dt_spec led = + GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios); + +void main(void) +{ + bool led_is_on = true; + + __ASSERT_NO_MSG(device_is_ready(led.port)); + + while (true) { + gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + gpio_pin_set(led.port, led.pin, (int)led_is_on); + if (led_is_on == false) { + /* Release resource to release device clock */ + gpio_pin_configure(led.port, led.pin, GPIO_DISCONNECTED); + } + k_msleep(SLEEP_TIME_MS); + if (led_is_on == true) { + /* Release resource to release device clock */ + gpio_pin_configure(led.port, led.pin, GPIO_DISCONNECTED); + } + led_is_on = !led_is_on; + } +}