samples/boards: stm32: Add low power blinky sample
This sample demonstrates a low power blinky application. Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
3b6707f140
commit
c730603332
5 changed files with 110 additions and 0 deletions
7
samples/boards/stm32/power_mgmt/blinky/CMakeLists.txt
Normal file
7
samples/boards/stm32/power_mgmt/blinky/CMakeLists.txt
Normal file
|
@ -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)
|
42
samples/boards/stm32/power_mgmt/blinky/README.rst
Normal file
42
samples/boards/stm32/power_mgmt/blinky/README.rst
Normal file
|
@ -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 <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 <dt-guide>` alias. This is usually done in the
|
||||
:ref:`BOARD.dts file <devicetree-in-out-files>` or a :ref:`devicetree overlay
|
||||
<set-devicetree-overlays>`.
|
||||
|
||||
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.
|
15
samples/boards/stm32/power_mgmt/blinky/prj.conf
Normal file
15
samples/boards/stm32/power_mgmt/blinky/prj.conf
Normal file
|
@ -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
|
8
samples/boards/stm32/power_mgmt/blinky/sample.yaml
Normal file
8
samples/boards/stm32/power_mgmt/blinky/sample.yaml
Normal file
|
@ -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
|
38
samples/boards/stm32/power_mgmt/blinky/src/main.c
Normal file
38
samples/boards/stm32/power_mgmt/blinky/src/main.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Linaro Limited
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <devicetree.h>
|
||||
#include <drivers/gpio.h>
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue