Commit 2caf720c authored by Guillaume Gautier's avatar Guillaume Gautier Committed by Carles Cufi
Browse files

samples: board: stm32 pm: add adc power management sample



Add a sample for STM32 ADC power management

Signed-off-by: default avatarGuillaume Gautier <guillaume.gautier-ext@st.com>
parent 479ba144
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(stm32_pm_adc)

target_sources(app PRIVATE src/main.c)
+42 −0
Original line number Diff line number Diff line
.. _stm32-pm-adc-sample:

STM32 PM ADC
############

Overview
********

This sample is a minimum application to demonstrate basic power management
behavior in a basic ADC set up in low power context.

.. _stm32-pm-adc-sample-requirements:

Requirements
************

The board should support enabling PM. For a STM32 based target, it means that
it should support a clock source alternative to Cortex Systick that can be used
in core sleep states, as LPTIM (:dtcompatible:`st,stm32-lptim`).

Building and Running
********************

Build and flash as follows, changing ``nucleo_wb55rg`` for your board:

.. zephyr-app-commands::
   :zephyr-app: samples/boards/stm32/power_mgmt/adc
   :board: nucleo_wb55rg
   :goals: build flash
   :compact:

After flashing, the console shows the ADC measurement in the form:
``ADC reading[0]:``
``- adc@50040000, channel 3: 1158 = 932 mV``

PM configurations
*****************

By default, :kconfig:option:`CONFIG_PM_DEVICE` and :kconfig:option:`CONFIG_PM_DEVICE_RUNTIME` are
enabled.
On STM32WB, we can observe a power consumption of about 25µA with both kconfig
enabled, 27.5µA without (each time with :kconfig:option:`CONFIG_PM` enabled).
+27 −0
Original line number Diff line number Diff line
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright (c) 2023 STMicroelectronics
 */

#include <zephyr/dt-bindings/adc/adc.h>

/ {
	zephyr,user {
		/* adjust channel number according to pinmux in board.dts */
		io-channels = <&adc1 1>;
	};
};

&adc1 {
	#address-cells = <1>;
	#size-cells = <0>;

	channel@1 {
		reg = <1>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
		zephyr,resolution = <12>;
	};
};
+26 −0
Original line number Diff line number Diff line
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright (c) 2023 STMicroelectronics
 */

/ {
	zephyr,user {
		/* adjust channel number according to pinmux in board.dts */
		io-channels = <&adc1 3>;
	};
};

&adc1 {
	pinctrl-0 = <&adc1_in3_pc2>;
	#address-cells = <1>;
	#size-cells = <0>;

	channel@3 {
		reg = <3>;
		zephyr,gain = "ADC_GAIN_1";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
		zephyr,resolution = <12>;
	};
};
+12 −0
Original line number Diff line number Diff line
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright (c) 2023 STMicroelectronics
 */

/ {
	zephyr,user {
		/* adjust channel number according to pinmux in board.dts */
		io-channels = <&adc4 8>;
	};
};
Loading