Skip to content

Commit cbd033a

Browse files
kywwilson11xiaoxiang781216
authored andcommitted
arch/arm/stm32h5: Initial Driver for STM32H5 Digital Temperature Sensor (DTS)
- Committing initial code for DTS. Missing ISR. Works for PCLK1. Cannot get to work for LSE. - Pushing everything. Working with LSE now. - Many fixes. Fixed interrupt setting. Added data structures. - Changed interrupt handling. Removed FARs. Added Kconfig options for selecting interrupts. - Updated info and formatting. - Formatting fixes. - Formatting. - Changed iten to regval. - Removed Triggger - Formatting fixes per Pull request. - Changed private_types to have stm32_ prefix. Used depends on for DTS Kconfig Menu. Fixed formatting per PR. - Fixed spacing of function prototypes. - Fixed indent on line - Added documentation for STM32H5 and Nucleo-H563ZI regarding DTS. Also added GPDMA support to STM32H5 documentation (previous PR). Made stm32_dts.c more modular. stm32_dts_activate is now much more readable. Added comments/descriptions to private functions. Lastly, added a nucleo-h563zi:dts configuration.
1 parent b5ef087 commit cbd033a

File tree

15 files changed

+904
-18
lines changed

15 files changed

+904
-18
lines changed

Documentation/platforms/arm/stm32h5/boards/nucleo-h563zi/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ usbnsh:
145145

146146
This configuration provides a basic NuttShell through the USB User interface.
147147

148+
dts:
149+
--------
150+
151+
This configuration configures the digital temperature sensor (DTS)
152+
at /dev/uorb/sensor_temp0 and provides the test application
153+
sensortest. E.g. sensortest -n 10 temp0
154+
148155
References
149156
===========
150157

Documentation/platforms/arm/stm32h5/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Peripheral Support Notes
3535
========== ======= =====
3636
ADC Yes
3737
ETH Yes
38+
DTS Yes Software trigger only.
3839
FLASH Yes Hardware defines only.
3940
FDCAN Yes
41+
GPDMA Yes
4042
GPIO Yes
4143
I2C Yes
4244
ICACHE Yes
@@ -59,11 +61,9 @@ DBG No
5961
DCACHE No
6062
DCMI No
6163
DLYB No
62-
DTS No
6364
EXTI No
6465
FMAC No
6566
FSMC No
66-
GPDMA No
6767
GTZC No
6868
HASH No
6969
I3C No

arch/arm/src/stm32h5/Kconfig

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ config STM32H5_DMA2
359359
select STM32H5_DMA
360360
select ARCH_DMA
361361

362+
config STM32H5_DTS
363+
bool "DTS"
364+
default n
365+
---help---
366+
Enable support for the on‑die digital temperature sensor (DTS)
367+
built into STM32H5 devices. When enabled, the driver will register
368+
a `/dev/sensor_tempX` device using the common NuttX sensor framework.
369+
362370
config STM32H5_ETHMAC
363371
bool "Ethernet MAC"
364372
default n
@@ -625,6 +633,107 @@ config STM32H5_USBFS
625633

626634
endmenu # STM32H5 Peripheral Selection
627635

636+
menu "DTS Configuration"
637+
depends on STM32H5_DTS
638+
639+
config STM32H5_DTS_REFCLK_LSE
640+
bool "Use LSE (32.768 kHz crystal) as DTS reference clock"
641+
default n
642+
---help---
643+
Select the low‑speed external (LSE) oscillator as the reference clock
644+
for the DTS. When enabled, DTS_CFGR1.REFCLK_SEL=1 and the driver will
645+
measure FM(T) pulses over N LSE cycles.
646+
647+
If disabled, the DTS will use the APB‑bus clock (PCLK) as the reference
648+
(REFCLK_SEL=0) and you must supply a valid HSREF_CLK_DIV to keep the
649+
calibration prescaler ≤ 1 MHz.
650+
651+
config STM32H5_DTS_SMP_TIME
652+
int "DTS sampling time (TS1_SMP_TIME[3:0])"
653+
default 1
654+
range 1 15
655+
---help---
656+
Number of reference‑clock cycles (PCLK or LSE) counted per
657+
DTS measurement. Valid range 1 (1 cycle) through 15 (15 cycles).
658+
659+
config STM32H5_DTS_TRIGGER
660+
int "DTS hardware trigger source (TS1_INTRIG_SEL[3:0])"
661+
default 0
662+
---help---
663+
If non‑zero, DTS will start measurements on the rising edge of
664+
the selected hardware line. Values match RM0481 Table 275:
665+
0=Software Trigger, 1=LPTIM1_CH1, 
666+
2=LPTIM2_CH1, 3=LPTIM3_CH1, 4=EXTI13, 5-15 are reserved.
667+
668+
config STM32H5_DTS_LOW_THRESHOLD
669+
int "DTS low‑threshold (°C)"
670+
default 0
671+
---help---
672+
The temperature (in whole °C) below which the DTS window comparator will
673+
assert the low‑threshold flag (TS1_ITLF). To disable, set equal to 0.
674+
675+
config STM32H5_DTS_HIGH_THRESHOLD
676+
int "DTS high‑threshold (°C)"
677+
default 100
678+
---help---
679+
The temperature (in whole °C) above which the DTS window comparator will
680+
assert the high‑threshold flag (TS1_ITHF). Must be >= LOW_THRESHOLD.
681+
682+
config STM32H5_DTS_ITEN_ITEF
683+
bool "Enable DTS end‑of‑measurement interrupt (TS1_ITEF)"
684+
default y
685+
---help---
686+
Enable the synchronous “end of measurement” interrupt for the
687+
digital temperature sensor. When set, the driver will attach
688+
and unmask TS1_ITEF and will call your ISR on every fresh sample.
689+
690+
config STM32H5_DTS_ITEN_ITLF
691+
bool "Enable DTS low‑threshold interrupt (TS1_ITLF)"
692+
default n
693+
---help---
694+
Enable the synchronous “low threshold crossed” interrupt for the
695+
digital temperature sensor. When set, the driver will unmask
696+
TS1_ITLF so you can get notified whenever the measured value
697+
drops below your programmed low‑threshold.
698+
699+
config STM32H5_DTS_ITEN_ITHF
700+
bool "Enable DTS high‑threshold interrupt (TS1_ITHF)"
701+
default n
702+
---help---
703+
Enable the synchronous “high threshold crossed” interrupt for the
704+
digital temperature sensor. When set, the driver will unmask
705+
TS1_ITHF so you can get notified whenever the measured value
706+
exceeds your programmed high‑threshold.
707+
708+
config STM32H5_DTS_AITEN_AITEF
709+
bool "Enable DTS asynchronous end‑of‑measurement interrupt (TS1_AITEF)"
710+
depends on STM32H5_DTS_REFCLK_LSE
711+
default n
712+
---help---
713+
Enable the asynchronous end‑of‑measurement interrupt. This will
714+
set TS1_AITEEN in DTS_ITENR and cause an _asynchronous_ wakeup
715+
event when a conversion completes (in Stop/Sleep modes).
716+
717+
config STM32H5_DTS_AITEN_AITLF
718+
bool "Enable DTS asynchronous low‑threshold interrupt (TS1_AITLF)"
719+
depends on STM32H5_DTS_REFCLK_LSE
720+
default n
721+
---help---
722+
Enable the asynchronous low‑threshold comparator interrupt. This
723+
will set TS1_AITLEN in DTS_ITENR and generate a wakeup event
724+
when the measurement drops below your low threshold.
725+
726+
config STM32H5_DTS_AITEN_AITHF
727+
bool "Enable DTS asynchronous high‑threshold interrupt (TS1_AITHF)"
728+
depends on STM32H5_DTS_REFCLK_LSE
729+
default n
730+
---help---
731+
Enable the asynchronous high‑threshold comparator interrupt. This
732+
will set TS1_AITHEN in DTS_ITENR and generate a wakeup event
733+
when the measurement exceeds your high threshold.
734+
735+
endmenu # DTS Configuration
736+
628737
config STM32H5_FLASH_PREFETCH
629738
bool "Enable FLASH Pre-fetch"
630739
default y

arch/arm/src/stm32h5/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ ifeq ($(CONFIG_STM32H5_DMA),y)
9292
CHIP_CSRCS += stm32_dma.c
9393
endif
9494

95+
ifeq ($(CONFIG_STM32H5_DTS),y)
96+
CHIP_CSRCS += stm32_dts.c
97+
endif
98+
9599
# Required chip type specific files
96100

97101
ifeq ($(CONFIG_STM32H5_STM32H5XXXX),y)

arch/arm/src/stm32h5/hardware/stm32_dts.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
# define DTS_CFGR1_TS1_INTRIG_SEL_LPTIM2_CH1 (0x2 << DTS_CFGR1_TS1_INTRIG_SEL_SHIFT)
7272
# define DTS_CFGR1_TS1_INTRIG_SEL_LPTIM3_CH1 (0x3 << DTS_CFGR1_TS1_INTRIG_SEL_SHIFT)
7373
# define DTS_CFGR1_TS1_INTRIG_SEL_EXTI13 (0x4 << DTS_CFGR1_TS1_INTRIG_SEL_SHIFT)
74+
#define DTS_CFGR1_TS1_INTRIG(n) \
75+
(((n) << DTS_CFGR1_TS1_INTRIG_SEL_SHIFT) & DTS_CFGR1_TS1_INTRIG_SEL_MASK)
7476

7577
#define DTS_CFGR1_TS1_SMP_TIME_SHIFT (16) /* Bits 16-19: Sampling time */
7678
#define DTS_CFGR1_TS1_SMP_TIME_MASK (0xf << DTS_CFGR1_TS1_SMP_TIME_SHIFT)
@@ -86,26 +88,26 @@
8688
/* Temperature sensor T0 value register 1 */
8789

8890
#define DTS_T0VALR1_TS1_FMT0_SHIFT (0) /* Engineering value for frequency at T0 */
89-
#define DTS_T0VALR1_TS1_FMT0_MASK (0xff << DTS_T0VALR1_TS1_FMT0_SHIFT)
91+
#define DTS_T0VALR1_TS1_FMT0_MASK (0xffff << DTS_T0VALR1_TS1_FMT0_SHIFT)
9092
#define DTS_T0VALR1_TS1_T0_SHIFT (16) /* Engineering value of T0 */
9193
#define DTS_T0VALR1_TS1_T0_MASK (0b11 << DTS_T0VALR1_TS1_T0_SHIFT)
9294

9395
/* Temperature sensor ramp value register */
9496

9597
#define DTS_RAMPVALR_TS1_RAMP_COEFF_SHIFT (0) /* Engineering value of ramp coefficient */
96-
#define DTS_RAMPVALR_TS1_RAMP_COEFF_MASK (0xff << DTS_RAMPVALR_TS1_RAMP_COEFF_SHIFT)
98+
#define DTS_RAMPVALR_TS1_RAMP_COEFF_MASK (0xffff << DTS_RAMPVALR_TS1_RAMP_COEFF_SHIFT)
9799

98100
/* Temperature sensor interrupt threshold register 1 */
99101

100102
#define DTS_ITR1_TS1_LITTHD_SHIFT (0) /* High interrupt threshold */
101-
#define DTS_ITR1_TS1_LITTHD_MASK (0xff << DTS_ITR1_TS1_LITTHD_SHIFT)
103+
#define DTS_ITR1_TS1_LITTHD_MASK (0xffff << DTS_ITR1_TS1_LITTHD_SHIFT)
102104
#define DTS_ITR1_TS1_HITTHD_SHIFT (16) /* Low interrupt threshold */
103-
#define DTS_ITR1_TS1_HITTHD_MASK (0xff << DTS_ITR1_TS1_HITTHD_SHIFT)
105+
#define DTS_ITR1_TS1_HITTHD_MASK (0xffff << DTS_ITR1_TS1_HITTHD_SHIFT)
104106

105107
/* Temperature sensor data register */
106108

107109
#define DTS_DR_TS1_MFREQ_SHIFT (0)
108-
#define DTS_DR_TS1_MFREQ_MASK (0xff << DTS_DR_TS1_MFREQ_SHIFT)
110+
#define DTS_DR_TS1_MFREQ_MASK (0xffff << DTS_DR_TS1_MFREQ_SHIFT)
109111

110112
/* Temperature sensor status register */
111113

@@ -134,6 +136,7 @@
134136
#define DTS_ICIFR_CAITEF (1 << 4) /* Asynchronous interrupt clear flag: end of measurement */
135137
#define DTS_ICIFR_CAITLF (1 << 5) /* Asynchronous interrupt clear flag: low threshold */
136138
#define DTS_ICIFR_CAITHF (1 << 6) /* Asynchronous interrupt clear flag: high threshold */
139+
#define DTS_ICIFR_ALL (0x77) /* All interrupts */
137140

138141
/* Temperature sensor option register */
139142

arch/arm/src/stm32h5/hardware/stm32h5xxx_rcc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@
264264
# define RCC_CFGR2_HPRE_SYSCLKd256 (14 << RCC_CFGR2_HPRE_SHIFT) /* 1110: SYSCLK divided by 256 */
265265
# define RCC_CFGR2_HPRE_SYSCLKd512 (15 << RCC_CFGR2_HPRE_SHIFT) /* 1111: SYSCLK divided by 512 */
266266

267-
#define RCC_CFGR2_PPRE1_SHIFT (0) /* Bits 6-4: PPRE1 Prescaler */
267+
#define RCC_CFGR2_PPRE1_SHIFT (4) /* Bits 6-4: PPRE1 Prescaler */
268268
#define RCC_CFGR2_PPRE1_MASK (0x7 << RCC_CFGR2_PPRE1_SHIFT)
269269
# define RCC_CFGR2_PPRE1_HCLK1 (0 << RCC_CFGR2_PPRE1_SHIFT) /* 0xx: HCLK1 not divided */
270-
# define RCC_CFGR2_PPRE1_HCLK1d2 (4 << RCC_CFGR2_PPRE1_SHIFT) /* 1000: HCLK1 divided by 2 */
271-
# define RCC_CFGR2_PPRE1_HCLK1d4 (5 << RCC_CFGR2_PPRE1_SHIFT) /* 1001: HCLK1 divided by 4 */
272-
# define RCC_CFGR2_PPRE1_HCLK1d8 (6 << RCC_CFGR2_PPRE1_SHIFT) /* 1010: HCLK1 divided by 8 */
273-
# define RCC_CFGR2_PPRE1_HCLK1d16 (7 << RCC_CFGR2_PPRE1_SHIFT) /* 1011: HCLK1 divided by 16 */
270+
# define RCC_CFGR2_PPRE1_HCLK1d2 (4 << RCC_CFGR2_PPRE1_SHIFT) /* 100: HCLK1 divided by 2 */
271+
# define RCC_CFGR2_PPRE1_HCLK1d4 (5 << RCC_CFGR2_PPRE1_SHIFT) /* 101: HCLK1 divided by 4 */
272+
# define RCC_CFGR2_PPRE1_HCLK1d8 (6 << RCC_CFGR2_PPRE1_SHIFT) /* 110: HCLK1 divided by 8 */
273+
# define RCC_CFGR2_PPRE1_HCLK1d16 (7 << RCC_CFGR2_PPRE1_SHIFT) /* 111: HCLK1 divided by 16 */
274274

275275
#define RCC_CFGR2_PPRE2_SHIFT (8) /* Bits 10-8: PPRE2 Prescaler */
276276
#define RCC_CFGR2_PPRE2_MASK (0x7 << RCC_CFGR2_PPRE2_SHIFT)

arch/arm/src/stm32h5/stm32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "chip.h"
4040
#include "stm32_adc.h"
4141
#include "stm32_dbgmcu.h"
42+
#include "stm32_dts.h"
4243
#include "stm32_flash.h"
4344
#include "stm32_gpio.h"
4445
#include "stm32_i2c.h"

0 commit comments

Comments
 (0)