1.. zephyr:code-sample:: stm32_pm_blinky
2   :name: Blinky with power management
3
4   Blink an LED using the GPIO API in a low-power context on STM32
5
6Overview
7********
8
9This sample is a minimum application to demonstrate basic power management
10behavior in a basic blinking LED set up using the :ref:`GPIO API <gpio_api>` in
11low power context.
12Note that lptim instance selected for the low power timer is named **&stm32_lp_tick_source**
13When setting a prescaler to decrease the lptimer input clock frequency, the system can sleep
14for a longer  timeout value and the CONFIG_SYS_CLOCK_TICKS_PER_SEC is adjusted.
15For example, when clocking the  low power Timer with LSE clock at 32768Hz and adding a
16prescaler of <32>, then the kernel sleep period can reach 65536 * 32/32768 = 64 seconds
17CONFIG_SYS_CLOCK_TICKS_PER_SEC is set to 1024.
18
19.. _stm32-pm-blinky-sample-requirements:
20
21Requirements
22************
23
24The board should support enabling PM. For a STM32 based target, it means that
25it should support a clock source alternative to Cortex Systick that can be used
26in core sleep states, as LPTIM (:dtcompatible:`st,stm32-lptim`).
27
28Building and Running
29********************
30
31Build and flash Blinky as follows, changing ``stm32l562e_dk`` for your board:
32
33.. zephyr-app-commands::
34   :zephyr-app: samples/boards/st/power_mgmt/blinky
35   :board: stm32l562e_dk
36   :goals: build flash
37   :compact:
38
39After flashing, the LED starts to blink with a fixed period (SLEEP_TIME_MS).
40When st,prescaler lptim property is defined, longer period (up to 64 seconds)
41of low power can be tested.
42
43.. warning::
44   Debugging this sample may require enabling :kconfig:option:`CONFIG_DEBUG` ``=y``.
45   That will enable the :kconfig:option:`CONFIG_STM32_ENABLE_DEBUG_SLEEP_STOP`
46   and prevent the system to go to low power mode.
47   When enabled, entry in low-power modes will not disable power in the power domains
48   that should be powered off, ensuring that the debug logic remains always
49   available. However, low-power modes will no longer reduce the system's
50   power consumption in this configuration, which is the opposite of what
51   this sample is attempting to demonstrate.
52
53PM configurations
54*****************
55
56By default, :kconfig:option:`CONFIG_PM_DEVICE` and :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME` are
57enabled, but user can also deactivate one or the other to see each configuration
58in play.
59