Commit 816449c1 authored by Francois Ramu's avatar Francois Ramu Committed by Carles Cufi
Browse files

samples: sensor: new sample to demonstrate the Vbat monitoring



This new application is monitoring the Vbat in Volts
from the internal ADC.
Running on the nucleo_g071rb and nucle_wb55rg boards.
Vref is a property of the ADC.

Signed-off-by: default avatarFrancois Ramu <francois.ramu@st.com>
parent a3b42b55
Loading
Loading
Loading
Loading
+8 −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_vbat_sensor)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
+51 −0
Original line number Diff line number Diff line
.. _stm32_vbat_sensor:

STM32 VBat Sensor
#################

Overview
********

This sample reads the Vbat from the STM32 Internal
Sensor and displays the results.

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

In order to run this sample, make sure to enable ``stm32_vbat`` node in your
board DT file or with a board overlay in the samples/sensor/stm32_temp_sensor/boards :


.. code-block:: dts

    stm32_vbat: stm32vbat {
        compatible = "st,stm32-vbat";
        label = "VBAT";
        io-channels = <&adc1 14>;
        ratio = <3>;
        status = "okay";
    };


Enable the corresponding ADC, with the correct vref value (in mV)

.. code-block:: dts

    &adc1 {
	vref-mv = <3000>;
	status = "okay";
    };


.. zephyr-app-commands::
   :zephyr-app: samples/sensor/stm32_vbat_sensor
   :board: nucleo_g071rb
   :goals: build
   :compact:

Sample Output
=============

.. code-block:: console

Current Vbat voltage: 3.04 V
+17 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 STMicroelectronics
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Application overlay for creating vbat sensor device instance
 */

/ {
	stm-vbat {
		compatible = "st,stm32-vbat";
		ratio = <3>;
		io-channels = <&adc1 14>;
		status = "okay";
		label = "VBAT";
	};
};
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 STMicroelectronics
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Application overlay for creating vbat sensor device instance
 */

/ {
	stm-vbat {
		compatible = "st,stm32-vbat";
		ratio = <3>;
		io-channels = <&adc1 18>;
		status = "okay";
		label = "VBAT";
	};
};

&adc1 {
	has-vbat-channel;
	vref-mv = <3300>;
};
+5 −0
Original line number Diff line number Diff line
CONFIG_SENSOR=y
CONFIG_ADC=y
CONFIG_STM32_VBAT=y
CONFIG_PRINTK=y
CONFIG_CBPRINTF_FP_SUPPORT=y
Loading