Skip to content

Commit 3dabe03

Browse files
ABESTMnashif
authored andcommitted
samples: boards: stm32: Add example for STOP3 mode on STM32U5
Simple blinky example, but using STOP3 mode. When in STOP3 mode, GPIOs are not driven, but only pull-up or pull-down can be enabled based on value in PWR registers. Signed-off-by: Adam Berlinger <[email protected]>
1 parent 19b3940 commit 3dabe03

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

boards/st/nucleo_u575zi_q/nucleo_u575zi_q-common.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,13 @@ zephyr_udc0: &usbotg_fs {
199199
&vbat4 {
200200
status = "okay";
201201
};
202+
203+
&clk_lsi {
204+
status = "okay";
205+
};
206+
207+
stm32_lp_tick_source: &lptim1 {
208+
clocks = <&rcc STM32_CLOCK_BUS_APB3 0x00000800>,
209+
<&rcc STM32_SRC_LSI LPTIM1_SEL(1)>;
210+
status = "okay";
211+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(stm32_pm_stop3)
6+
7+
target_sources(app PRIVATE src/main.c)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _stm32-pm-stop3:
2+
3+
STM32 PM STOP3 mode
4+
###################
5+
6+
Overview
7+
********
8+
9+
This sample is a minimum application to demonstrate basic power management
10+
behavior in a basic blinking LED set up and STM32U5 STOP3 low power mode.
11+
12+
.. _stm32-pm-stop3-requirements:
13+
14+
Requirements
15+
************
16+
17+
At the moment, only ``nucleo_u575zi_q`` board is supported.
18+
The board shall have an RTC to use it during the standby mode as a replacement
19+
for LPTIM (which is disabled).
20+
21+
Building and Running
22+
********************
23+
24+
Build and flash examples as follows:
25+
26+
.. zephyr-app-commands::
27+
:zephyr-app: samples/boards/stm32/power_mgmt/stop3
28+
:board: nucleo_u575zi_q
29+
:goals: build flash
30+
:compact:
31+
32+
After flashing, the LED starts to blink.
33+
34+
PM configurations
35+
*****************
36+
37+
By default, :kconfig:option:`CONFIG_PM_DEVICE` and :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME`
38+
are enabled.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 STMicroelectronics
5+
*/
6+
7+
/ {
8+
chosen {
9+
st,lptim-stdby-timer = &rtc;
10+
};
11+
};
12+
13+
&cpu0 {
14+
cpu-power-states = <&stop0 &stop1 &stop2 &stop3>;
15+
};
16+
17+
&rtc {
18+
status = "okay";
19+
clocks = <&rcc STM32_CLOCK_BUS_APB3 0x00200000>,
20+
<&rcc STM32_SRC_LSI RTC_SEL(2)>;
21+
prescaler = <32768>;
22+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_PM=y
2+
CONFIG_PM_DEVICE=y
3+
CONFIG_PM_DEVICE_RUNTIME=y
4+
CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n
5+
CONFIG_ASSERT=y
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sample:
2+
name: STM32 STOP3 Power Management
3+
tests:
4+
sample.boards.stm32.power_mgmt.stop3:
5+
tags:
6+
- LED
7+
- power
8+
harness: console
9+
platform_allow: nucleo_u575zi_q
10+
harness_config:
11+
type: one_line
12+
regex:
13+
- "Device ready"
14+
extra_args: "CONFIG_DEBUG=y"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/devicetree.h>
10+
#include <zephyr/drivers/gpio.h>
11+
#include <zephyr/sys/printk.h>
12+
#include <stm32u5xx_ll_pwr.h>
13+
#include <gpio/gpio_stm32.h>
14+
15+
#define SLEEP_TIME_MS 2000
16+
17+
static const struct gpio_dt_spec led =
18+
GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
19+
20+
int main(void)
21+
{
22+
bool led_is_on = true;
23+
24+
/* Compute GPIO port to be passed to LL_PWR_EnableGPIOPullUp etc. */
25+
const struct gpio_stm32_config *cfg = led.port->config;
26+
uint32_t pwr_port = ((uint32_t)LL_PWR_GPIO_PORTA) + (cfg->port * 8);
27+
28+
__ASSERT_NO_MSG(gpio_is_ready_dt(&led));
29+
30+
printk("Device ready\n");
31+
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
32+
33+
/* Enable the pull-up/pull-down feature globally.
34+
* User can decide to not use this feature to further reduce power consumption
35+
*
36+
* This configuration is active only in STOP3 mode, so no need to disable it
37+
* during wake up
38+
*/
39+
LL_PWR_EnablePUPDConfig();
40+
41+
while (true) {
42+
gpio_pin_set(led.port, led.pin, (int)led_is_on);
43+
/* In STOP3, GPIOs are disabled. Only pull-up/pull-down can be enabled.
44+
* So we enable pull-up/pull-down based on LED status
45+
*/
46+
if (led_is_on) {
47+
LL_PWR_DisableGPIOPullDown(pwr_port, (1 << led.pin));
48+
LL_PWR_EnableGPIOPullUp(pwr_port, (1 << led.pin));
49+
} else {
50+
LL_PWR_DisableGPIOPullUp(pwr_port, (1 << led.pin));
51+
LL_PWR_EnableGPIOPullDown(pwr_port, (1 << led.pin));
52+
}
53+
54+
k_msleep(SLEEP_TIME_MS);
55+
led_is_on = !led_is_on;
56+
}
57+
return 0;
58+
}

0 commit comments

Comments
 (0)