samples: sensor: Add stm32_temp sample application

Demonstating usage of STM32 temperature sensor.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
diff --git a/samples/sensor/stm32_temp_sensor/CMakeLists.txt b/samples/sensor/stm32_temp_sensor/CMakeLists.txt
new file mode 100644
index 0000000..df28612
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/CMakeLists.txt
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: Apache-2.0
+
+cmake_minimum_required(VERSION 3.13.1)
+find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+project(stm32_temp_sensor)
+
+FILE(GLOB app_sources src/*.c)
+target_sources(app PRIVATE ${app_sources})
diff --git a/samples/sensor/stm32_temp_sensor/README.rst b/samples/sensor/stm32_temp_sensor/README.rst
new file mode 100644
index 0000000..f0541eb
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/README.rst
@@ -0,0 +1,31 @@
+.. _stm32_temp_sensor:
+
+STM32 Temperature Sensor
+########################
+
+Overview
+********
+
+This sample periodically reads temperature from the STM32 Internal
+Temperature Sensor and display the results.
+
+Building and Running
+********************
+
+In order to run this sample, make sure to enable ``stm32_temp`` node in your
+board DT file.
+
+.. zephyr-app-commands::
+   :zephyr-app: samples/sensor/stm32_temp_sensor
+   :board: nucleo_f103rb
+   :goals: build
+   :compact:
+
+Sample Output
+=============
+
+.. code-block:: console
+
+    Current temperature: 22.6 °C
+    Current temperature: 22.8 °C
+    Current temperature: 23.1 °C
diff --git a/samples/sensor/stm32_temp_sensor/boards/nucleo_f401re.overlay b/samples/sensor/stm32_temp_sensor/boards/nucleo_f401re.overlay
new file mode 100644
index 0000000..481423d
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/boards/nucleo_f401re.overlay
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2021 Eug Krashtan
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Application overlay for creating temperature sensor device instance
+ */
+
+/ {
+	stm-temp {
+		label = "DIE_TEMP";
+		compatible = "st,stm32-temp";
+		io-channels = <&adc1 16>;
+		status = "okay";
+	};
+};
diff --git a/samples/sensor/stm32_temp_sensor/boards/stm32f103_mini.overlay b/samples/sensor/stm32_temp_sensor/boards/stm32f103_mini.overlay
new file mode 100644
index 0000000..cac3849
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/boards/stm32f103_mini.overlay
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021 Eug Krashtan
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Application overlay for creating temperature sensor device instance
+ */
+
+/ {
+	stm-temp {
+		label = "DIE_TEMP";
+		compatible = "st,stm32-temp";
+		io-channels = <&adc1 16>;
+		avgslope = <43>;
+		v25 = <1430>;
+		ntc;
+		status = "okay";
+	};
+};
+
+&adc1 {
+	status = "okay";
+};
diff --git a/samples/sensor/stm32_temp_sensor/prj.conf b/samples/sensor/stm32_temp_sensor/prj.conf
new file mode 100644
index 0000000..64831c5
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/prj.conf
@@ -0,0 +1,5 @@
+CONFIG_SENSOR=y
+CONFIG_ADC=y
+CONFIG_STM32_TEMP=y
+CONFIG_PRINTK=y
+CONFIG_CBPRINTF_FP_SUPPORT=y
diff --git a/samples/sensor/stm32_temp_sensor/sample.yaml b/samples/sensor/stm32_temp_sensor/sample.yaml
new file mode 100644
index 0000000..a5bb736
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/sample.yaml
@@ -0,0 +1,9 @@
+sample:
+  description: Usage of STM32 temperature sensor
+  name: stm32_temp_sensor
+tests:
+  sample.sensor.stm32_temp_sensor:
+    depends_on: adc
+    tags: sensors
+    build_only: true
+    platform_allow: nucleo_f401re stm32f103_mini
diff --git a/samples/sensor/stm32_temp_sensor/src/main.c b/samples/sensor/stm32_temp_sensor/src/main.c
new file mode 100644
index 0000000..b287273
--- /dev/null
+++ b/samples/sensor/stm32_temp_sensor/src/main.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Eug Krashtan
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr.h>
+#include <device.h>
+#include <drivers/sensor.h>
+#include <sys/printk.h>
+
+
+void main(void)
+{
+	struct sensor_value val;
+	int rc;
+	const struct device *dev =
+		DEVICE_DT_GET(DT_INST(0, st_stm32_temp));
+
+	if (!device_is_ready(dev)) {
+		printk("Temperature sensor is not ready\n");
+		return;
+	}
+
+	printk("STM32 Die temperature sensor test\n");
+
+	while (1) {
+		k_sleep(K_MSEC(300));
+
+		/* fetch sensor samples */
+		rc = sensor_sample_fetch(dev);
+		if (rc) {
+			printk("Failed to fetch sample (%d)\n", rc);
+			continue;
+		}
+
+		rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP, &val);
+		if (rc) {
+			printk("Failed to get data (%d)\n", rc);
+			continue;
+		}
+
+		printk("Current temperature: %.1f °C\n",
+					sensor_value_to_double(&val));
+	}
+}