This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9f7602e55e9a446eb6e7d3e445378ca4c9815935
Author: raiden00pl <[email protected]>
AuthorDate: Mon Nov 2 19:24:34 2026 +0100

    arch/arm/stm32: Add the M33/M55 RTC driver.
    
    STM32N6 had no RTC driver.  Its RTC has the ICSR/SR/SCR register layout
    and keeps the backup registers in the TAMP peripheral, so the existing
    M3/M4 drivers do not fit.
    
    - Add common/stm32/stm32_rtcc_m33m55_v1.c: calendar, sub-seconds,
      alarm A/B and periodic wakeup, selected by
      STM32_HAVE_IP_RTCC_M33M55_V1.
    - Add the register maps hardware/stm32_rtcc_m33m55_v1.h and
      hardware/stm32_tamp.h.
    - STM32N6 selects the driver and the RCC starts the LSE.
    - STM32N6570-DK registers /dev/rtc0, clocked from the LSE.
    
    Assisted-by: Claude:claude-fable-5-1
    Signed-off-by: raiden00pl <[email protected]>
---
 Documentation/guides/chip-specific/stm32_ports.rst |    1 +
 .../arm/stm32n6/boards/stm32n6570-dk/index.rst     |   12 +-
 Documentation/platforms/arm/stm32n6/index.rst      |    3 +-
 arch/arm/src/common/stm32/CMakeLists.txt           |    7 +
 arch/arm/src/common/stm32/Kconfig.have             |    3 +
 arch/arm/src/common/stm32/Make.defs                |    7 +
 arch/arm/src/common/stm32/hardware/stm32_rtcc.h    |    5 +-
 .../common/stm32/hardware/stm32_rtcc_m33m55_v1.h   |  358 +++++
 arch/arm/src/common/stm32/hardware/stm32_tamp.h    |  324 +++++
 arch/arm/src/common/stm32/stm32_alarm.h            |    3 +-
 arch/arm/src/common/stm32/stm32_rtc.h              |   17 +-
 arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c   | 1489 ++++++++++++++++++++
 arch/arm/src/stm32n6/Kconfig                       |    4 +
 arch/arm/src/stm32n6/stm32_rcc.h                   |   20 +
 arch/arm/src/stm32n6/stm32n6xx_rcc.c               |   56 +-
 .../stm32n6/stm32n6570-dk/configs/nsh/defconfig    |    7 +
 .../arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c  |   13 +
 17 files changed, 2321 insertions(+), 8 deletions(-)

diff --git a/Documentation/guides/chip-specific/stm32_ports.rst 
b/Documentation/guides/chip-specific/stm32_ports.rst
index 3454411271a..a6ddd595fa8 100644
--- a/Documentation/guides/chip-specific/stm32_ports.rst
+++ b/Documentation/guides/chip-specific/stm32_ports.rst
@@ -782,6 +782,7 @@ LPTIM         v2            
arch/arm/src/common/stm32/stm32_lptim.c
 PWR           n6            arch/arm/src/stm32n6/stm32_pwr.c
 RCC           n6            arch/arm/src/stm32n6/stm32n6xx_rcc.c
 RNG           v1            arch/arm/src/common/stm32/stm32_rng_v1.c
+RTC           M33M55 v1     arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
 SPI/I2S       to be done    not supported
 TIM           v3            arch/arm/src/common/stm32/stm32_tim.c
 USART/LPUART  v4            arch/arm/src/stm32n6/stm32_serial.c
diff --git a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst 
b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
index 1bd8065e63e..c022c2ae5f0 100644
--- a/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
+++ b/Documentation/platforms/arm/stm32n6/boards/stm32n6570-dk/index.rst
@@ -114,6 +114,15 @@ TAMP  PE0   Button B4, EXTI0, high when pressed
 The LEDs are available through ``/dev/userleds`` and the buttons through
 ``/dev/buttons`` in the nsh configuration.
 
+RTC
+===
+
+The RTC runs from the 32.768 kHz LSE crystal and is registered as
+``/dev/rtc0`` with two alarms.  Set the time with ``date -s`` and test the
+alarms with the ``alarm`` example, e.g. ``alarm 5`` or ``alarm -a 1 5``.
+The time survives a reset; without a backup battery it is lost on power
+off.
+
 Clocking
 ========
 
@@ -134,4 +143,5 @@ Configurations
 nsh
 ---
 
-NuttShell with the user LEDs, the USER1 button and GPDMA1 enabled.
+NuttShell with the user LEDs, the USER1 button, GPDMA1 and the RTC
+enabled.
diff --git a/Documentation/platforms/arm/stm32n6/index.rst 
b/Documentation/platforms/arm/stm32n6/index.rst
index f73864cc2d8..2d331c82f03 100644
--- a/Documentation/platforms/arm/stm32n6/index.rst
+++ b/Documentation/platforms/arm/stm32n6/index.rst
@@ -32,6 +32,8 @@ PWR         Yes      Supply configuration, VOS, I/O supply 
validity.
 RCC         Yes      HSI/HSE, PLL1-4, IC1-20, bus prescalers and kernel
                      clock selection from board.h.
 RNG         Yes      Through the common driver.
+RTC         Yes      Calendar, sub-seconds, Alarm A/B and wakeup timer
+                     through the common RTC driver.
 USART       Yes      USART1 only.
 
 ADC         No
@@ -45,7 +47,6 @@ LPTIM       No
 LTDC        No
 MPU         No
 NPU         No
-RTC         No
 SAI         No
 SDMMC       No
 SPI         No
diff --git a/arch/arm/src/common/stm32/CMakeLists.txt 
b/arch/arm/src/common/stm32/CMakeLists.txt
index b13b71ae527..183ced7cf1b 100644
--- a/arch/arm/src/common/stm32/CMakeLists.txt
+++ b/arch/arm/src/common/stm32/CMakeLists.txt
@@ -80,6 +80,13 @@ if(CONFIG_STM32_RNG AND CONFIG_STM32_HAVE_IP_RNG_V1)
   list(APPEND SRCS stm32_rng_v1.c)
 endif()
 
+if(CONFIG_STM32_RTC AND CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)
+  list(APPEND SRCS stm32_rtcc_m33m55_v1.c)
+  if(CONFIG_RTC_DRIVER)
+    list(APPEND SRCS stm32_rtc_m3m4_v1_lowerhalf.c)
+  endif()
+endif()
+
 if(CONFIG_STM32_COMMON_M33)
   list(APPEND SRCS stm32_allocateheap_m33_v1.c stm32_irq_m33_v1.c
        stm32_start_m33_v1.c)
diff --git a/arch/arm/src/common/stm32/Kconfig.have 
b/arch/arm/src/common/stm32/Kconfig.have
index a3c4d960937..fcd5fe5578a 100644
--- a/arch/arm/src/common/stm32/Kconfig.have
+++ b/arch/arm/src/common/stm32/Kconfig.have
@@ -727,6 +727,9 @@ config STM32_HAVE_IP_RTCC_M3M4_F4
 config STM32_HAVE_IP_RTC_M3M4_V1
        bool
 
+config STM32_HAVE_IP_RTCC_M33M55_V1
+       bool
+
 config STM32_HAVE_RTC_SUBSECONDS
        bool
        select ARCH_HAVE_RTC_SUBSECONDS
diff --git a/arch/arm/src/common/stm32/Make.defs 
b/arch/arm/src/common/stm32/Make.defs
index fd9758a7840..c6147a9184f 100644
--- a/arch/arm/src/common/stm32/Make.defs
+++ b/arch/arm/src/common/stm32/Make.defs
@@ -91,6 +91,13 @@ ifeq ($(CONFIG_STM32_RNG)$(CONFIG_STM32_HAVE_IP_RNG_V1),yy)
 CHIP_CSRCS += stm32_rng_v1.c
 endif
 
+ifeq ($(CONFIG_STM32_RTC)$(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1),yy)
+CHIP_CSRCS += stm32_rtcc_m33m55_v1.c
+ifeq ($(CONFIG_RTC_DRIVER),y)
+CHIP_CSRCS += stm32_rtc_m3m4_v1_lowerhalf.c
+endif
+endif
+
 ifeq ($(CONFIG_STM32_COMMON_M33),y)
 CHIP_CSRCS += stm32_allocateheap_m33_v1.c
 CHIP_CSRCS += stm32_irq_m33_v1.c
diff --git a/arch/arm/src/common/stm32/hardware/stm32_rtcc.h 
b/arch/arm/src/common/stm32/hardware/stm32_rtcc.h
index 7431435f80f..b2eb17658ea 100644
--- a/arch/arm/src/common/stm32/hardware/stm32_rtcc.h
+++ b/arch/arm/src/common/stm32/hardware/stm32_rtcc.h
@@ -30,7 +30,8 @@
 #if (defined(CONFIG_STM32_HAVE_IP_RTCC_M0_V1) + \
      defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_V1) + \
      defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_L1) + \
-     defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_F4)) > 1
+     defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_F4) + \
+     defined(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)) > 1
 #  error Only one STM32 RTCC IP version must be selected
 #endif
 
@@ -40,6 +41,8 @@
       defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_L1) || \
       defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_F4)
 #  include "hardware/stm32_rtcc_v1.h"
+#elif defined(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)
+#  include "hardware/stm32_rtcc_m33m55_v1.h"
 #else
 #  error "Unsupported STM32 RTCC"
 #endif
diff --git a/arch/arm/src/common/stm32/hardware/stm32_rtcc_m33m55_v1.h 
b/arch/arm/src/common/stm32/hardware/stm32_rtcc_m33m55_v1.h
new file mode 100644
index 00000000000..544e31ad5c6
--- /dev/null
+++ b/arch/arm/src/common/stm32/hardware/stm32_rtcc_m33m55_v1.h
@@ -0,0 +1,358 @@
+/****************************************************************************
+ * arch/arm/src/common/stm32/hardware/stm32_rtcc_m33m55_v1.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_RTCC_M33M55_V1_H
+#define __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_RTCC_M33M55_V1_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register Offsets *********************************************************/
+
+#define STM32_RTC_TR_OFFSET       0x0000    /* RTC time register */
+#define STM32_RTC_DR_OFFSET       0x0004    /* RTC date register */
+#define STM32_RTC_SSR_OFFSET      0x0008    /* RTC sub second register */
+#define STM32_RTC_ICSR_OFFSET     0x000c    /* RTC init control and status 
register */
+#define STM32_RTC_PRER_OFFSET     0x0010    /* RTC prescaler register */
+#define STM32_RTC_WUTR_OFFSET     0x0014    /* RTC wakeup timer register */
+#define STM32_RTC_CR_OFFSET       0x0018    /* RTC control register */
+#define STM32_RTC_PRIVCFGR_OFFSET 0x001c    /* RTC privilege mode control 
register */
+#define STM32_RTC_SECCFGR_OFFSET  0x0020    /* RTC secure mode control 
register */
+#define STM32_RTC_WPR_OFFSET      0x0024    /* RTC write protection register */
+#define STM32_RTC_CALR_OFFSET     0x0028    /* RTC calibration register */
+#define STM32_RTC_SHIFTR_OFFSET   0x002c    /* RTC shift control register */
+#define STM32_RTC_TSTR_OFFSET     0x0030    /* RTC timestamp time register */
+#define STM32_RTC_TSDR_OFFSET     0x0034    /* RTC timestamp date register */
+#define STM32_RTC_TSSSR_OFFSET    0x0038    /* RTC timestamp sub second 
register */
+#define STM32_RTC_ALRMAR_OFFSET   0x0040    /* RTC alarm A register */
+#define STM32_RTC_ALRMASSR_OFFSET 0x0044    /* RTC alarm A sub second register 
*/
+#define STM32_RTC_ALRMBR_OFFSET   0x0048    /* RTC alarm B register */
+#define STM32_RTC_ALRMBSSR_OFFSET 0x004c    /* RTC alarm B sub second register 
*/
+#define STM32_RTC_SR_OFFSET       0x0050    /* RTC status register */
+#define STM32_RTC_MISR_OFFSET     0x0054    /* RTC masked interrupt status 
register */
+#define STM32_RTC_SMISR_OFFSET    0x0058    /* RTC secure masked interrupt 
status reg */
+#define STM32_RTC_SCR_OFFSET      0x005c    /* RTC status clear register */
+#define STM32_RTC_ALRABINR_OFFSET 0x0070    /* RTC alarm A binary mode 
register */
+#define STM32_RTC_ALRBBINR_OFFSET 0x0074    /* RTC alarm B binary mode 
register */
+
+/* Register Addresses *******************************************************/
+
+#define STM32_RTC_TR              (STM32_RTC_BASE + STM32_RTC_TR_OFFSET)
+#define STM32_RTC_DR              (STM32_RTC_BASE + STM32_RTC_DR_OFFSET)
+#define STM32_RTC_SSR             (STM32_RTC_BASE + STM32_RTC_SSR_OFFSET)
+#define STM32_RTC_ICSR            (STM32_RTC_BASE + STM32_RTC_ICSR_OFFSET)
+#define STM32_RTC_PRER            (STM32_RTC_BASE + STM32_RTC_PRER_OFFSET)
+#define STM32_RTC_WUTR            (STM32_RTC_BASE + STM32_RTC_WUTR_OFFSET)
+#define STM32_RTC_CR              (STM32_RTC_BASE + STM32_RTC_CR_OFFSET)
+#define STM32_RTC_PRIVCFGR        (STM32_RTC_BASE + STM32_RTC_PRIVCFGR_OFFSET)
+#define STM32_RTC_SECCFGR         (STM32_RTC_BASE + STM32_RTC_SECCFGR_OFFSET)
+#define STM32_RTC_WPR             (STM32_RTC_BASE + STM32_RTC_WPR_OFFSET)
+#define STM32_RTC_CALR            (STM32_RTC_BASE + STM32_RTC_CALR_OFFSET)
+#define STM32_RTC_SHIFTR          (STM32_RTC_BASE + STM32_RTC_SHIFTR_OFFSET)
+#define STM32_RTC_TSTR            (STM32_RTC_BASE + STM32_RTC_TSTR_OFFSET)
+#define STM32_RTC_TSDR            (STM32_RTC_BASE + STM32_RTC_TSDR_OFFSET)
+#define STM32_RTC_TSSSR           (STM32_RTC_BASE + STM32_RTC_TSSSR_OFFSET)
+#define STM32_RTC_ALRMAR          (STM32_RTC_BASE + STM32_RTC_ALRMAR_OFFSET)
+#define STM32_RTC_ALRMASSR        (STM32_RTC_BASE + STM32_RTC_ALRMASSR_OFFSET)
+#define STM32_RTC_ALRMBR          (STM32_RTC_BASE + STM32_RTC_ALRMBR_OFFSET)
+#define STM32_RTC_ALRMBSSR        (STM32_RTC_BASE + STM32_RTC_ALRMBSSR_OFFSET)
+#define STM32_RTC_SR              (STM32_RTC_BASE + STM32_RTC_SR_OFFSET)
+#define STM32_RTC_MISR            (STM32_RTC_BASE + STM32_RTC_MISR_OFFSET)
+#define STM32_RTC_SMISR           (STM32_RTC_BASE + STM32_RTC_SMISR_OFFSET)
+#define STM32_RTC_SCR             (STM32_RTC_BASE + STM32_RTC_SCR_OFFSET)
+#define STM32_RTC_ALRABINR        (STM32_RTC_BASE + STM32_RTC_ALRABINR_OFFSET)
+#define STM32_RTC_ALRBBINR        (STM32_RTC_BASE + STM32_RTC_ALRBBINR_OFFSET)
+
+/* Register Bitfield Definitions ********************************************/
+
+/* RTC time register */
+
+#define RTC_TR_SU_SHIFT           (0)       /* Bits 0-3: Second units in BCD 
format */
+#define RTC_TR_SU_MASK            (15 << RTC_TR_SU_SHIFT)
+#define RTC_TR_ST_SHIFT           (4)       /* Bits 4-6: Second tens in BCD 
format */
+#define RTC_TR_ST_MASK            (7 << RTC_TR_ST_SHIFT)
+#define RTC_TR_MNU_SHIFT          (8)       /* Bits 8-11: Minute units in BCD 
format */
+#define RTC_TR_MNU_MASK           (15 << RTC_TR_MNU_SHIFT)
+#define RTC_TR_MNT_SHIFT          (12)      /* Bits 12-14: Minute tens in BCD 
format */
+#define RTC_TR_MNT_MASK           (7 << RTC_TR_MNT_SHIFT)
+#define RTC_TR_HU_SHIFT           (16)      /* Bits 16-19: Hour units in BCD 
format */
+#define RTC_TR_HU_MASK            (15 << RTC_TR_HU_SHIFT)
+#define RTC_TR_HT_SHIFT           (20)      /* Bits 20-21: Hour tens in BCD 
format */
+#define RTC_TR_HT_MASK            (3 << RTC_TR_HT_SHIFT)
+#define RTC_TR_PM                 (1 << 22) /* Bit 22: AM/PM notation */
+#define RTC_TR_RESERVED_BITS      (0xff808080)
+
+/* RTC date register */
+
+#define RTC_DR_DU_SHIFT           (0)       /* Bits 0-3: Date units in BCD 
format */
+#define RTC_DR_DU_MASK            (15 << RTC_DR_DU_SHIFT)
+#define RTC_DR_DT_SHIFT           (4)       /* Bits 4-5: Date tens in BCD 
format */
+#define RTC_DR_DT_MASK            (3 << RTC_DR_DT_SHIFT)
+#define RTC_DR_MU_SHIFT           (8)       /* Bits 8-11: Month units in BCD 
format */
+#define RTC_DR_MU_MASK            (15 << RTC_DR_MU_SHIFT)
+#define RTC_DR_MT                 (1 << 12) /* Bit 12: Month tens in BCD 
format */
+#define RTC_DR_WDU_SHIFT          (13)      /* Bits 13-15: Week day units */
+#define RTC_DR_WDU_MASK           (7 << RTC_DR_WDU_SHIFT)
+#define RTC_DR_YU_SHIFT           (16)      /* Bits 16-19: Year units in BCD 
format */
+#define RTC_DR_YU_MASK            (15 << RTC_DR_YU_SHIFT)
+#define RTC_DR_YT_SHIFT           (20)      /* Bits 20-23: Year tens in BCD 
format */
+#define RTC_DR_YT_MASK            (15 << RTC_DR_YT_SHIFT)
+#define RTC_DR_RESERVED_BITS      (0xff0000c0)
+
+/* RTC sub second register */
+
+#define RTC_SSR_SS_SHIFT          (0)       /* Bits 0-31: Sub second value */
+#define RTC_SSR_SS_MASK           (0xffffffff << RTC_SSR_SS_SHIFT)
+
+/* RTC init control and status register */
+
+#define RTC_ICSR_WUTWF            (1 << 2)  /* Bit 2: Wakeup timer write flag 
*/
+#define RTC_ICSR_SHPF             (1 << 3)  /* Bit 3: Shift operation pending 
*/
+#define RTC_ICSR_INITS            (1 << 4)  /* Bit 4: Initialization status 
flag */
+#define RTC_ICSR_RSF              (1 << 5)  /* Bit 5: Registers 
synchronization flag */
+#define RTC_ICSR_INITF            (1 << 6)  /* Bit 6: Initialization flag */
+#define RTC_ICSR_INIT             (1 << 7)  /* Bit 7: Initialization mode */
+#define RTC_ICSR_BIN_SHIFT        (8)       /* Bits 8-9: Binary mode */
+#define RTC_ICSR_BIN_MASK         (3 << RTC_ICSR_BIN_SHIFT)
+#  define RTC_ICSR_BIN_BCD        (0 << RTC_ICSR_BIN_SHIFT) /* Free running 
BCD calendar mode */
+#  define RTC_ICSR_BIN_BINARY     (1 << RTC_ICSR_BIN_SHIFT) /* Free running 
binary mode */
+#  define RTC_ICSR_BIN_MIXED      (2 << RTC_ICSR_BIN_SHIFT) /* BCD calendar 
and binary mode */
+
+#define RTC_ICSR_BCDU_SHIFT       (10)      /* Bits 10-12: BCD update, 1 s 
increment period */
+#define RTC_ICSR_BCDU_MASK        (7 << RTC_ICSR_BCDU_SHIFT)
+#define RTC_ICSR_RECALPF          (1 << 16) /* Bit 16: Recalibration pending 
flag */
+
+/* RTC prescaler register */
+
+#define RTC_PRER_PREDIV_S_SHIFT   (0)       /* Bits 0-14: Synchronous 
prescaler factor */
+#define RTC_PRER_PREDIV_S_MASK    (0x7fff << RTC_PRER_PREDIV_S_SHIFT)
+#define RTC_PRER_PREDIV_A_SHIFT   (16)      /* Bits 16-22: Asynchronous 
prescaler factor */
+#define RTC_PRER_PREDIV_A_MASK    (0x7f << RTC_PRER_PREDIV_A_SHIFT)
+
+/* RTC wakeup timer register */
+
+#define RTC_WUTR_WUT_SHIFT        (0)       /* Bits 0-15: Wakeup auto-reload 
value */
+#define RTC_WUTR_WUT_MASK         (0xffff << RTC_WUTR_WUT_SHIFT)
+#define RTC_WUTR_WUTOCLR_SHIFT    (16)      /* Bits 16-31: Wakeup auto-reload 
output clear value */
+#define RTC_WUTR_WUTOCLR_MASK     (0xffff << RTC_WUTR_WUTOCLR_SHIFT)
+
+/* RTC control register */
+
+#define RTC_CR_WUCKSEL_SHIFT      (0)       /* Bits 0-2: Wakeup clock 
selection */
+#define RTC_CR_WUCKSEL_MASK       (7 << RTC_CR_WUCKSEL_SHIFT)
+#  define RTC_CR_WUCKSEL_RTCDIV16  (0 << RTC_CR_WUCKSEL_SHIFT) /* 000: RTC/16 
clock */
+#  define RTC_CR_WUCKSEL_RTCDIV8   (1 << RTC_CR_WUCKSEL_SHIFT) /* 001: RTC/8 
clock */
+#  define RTC_CR_WUCKSEL_RTCDIV4   (2 << RTC_CR_WUCKSEL_SHIFT) /* 010: RTC/4 
clock */
+#  define RTC_CR_WUCKSEL_RTCDIV2   (3 << RTC_CR_WUCKSEL_SHIFT) /* 011: RTC/2 
clock */
+#  define RTC_CR_WUCKSEL_CKSPRE    (4 << RTC_CR_WUCKSEL_SHIFT) /* 10x: ck_spre 
clock */
+#  define RTC_CR_WUCKSEL_CKSPREADD (6 << RTC_CR_WUCKSEL_SHIFT) /* 11x: 
ck_spre, 2^16 added to WUT */
+
+#define RTC_CR_TSEDGE             (1 << 3)  /* Bit 3: Timestamp event active 
edge */
+#define RTC_CR_REFCKON            (1 << 4)  /* Bit 4: Reference clock 
detection enable */
+#define RTC_CR_BYPSHAD            (1 << 5)  /* Bit 5: Bypass the shadow 
registers */
+#define RTC_CR_FMT                (1 << 6)  /* Bit 6: Hour format */
+#define RTC_CR_SSRUIE             (1 << 7)  /* Bit 7: SSR underflow interrupt 
enable */
+#define RTC_CR_ALRAE              (1 << 8)  /* Bit 8: Alarm A enable */
+#define RTC_CR_ALRBE              (1 << 9)  /* Bit 9: Alarm B enable */
+#define RTC_CR_WUTE               (1 << 10) /* Bit 10: Wakeup timer enable */
+#define RTC_CR_TSE                (1 << 11) /* Bit 11: Timestamp enable */
+#define RTC_CR_ALRAIE             (1 << 12) /* Bit 12: Alarm A interrupt 
enable */
+#define RTC_CR_ALRBIE             (1 << 13) /* Bit 13: Alarm B interrupt 
enable */
+#define RTC_CR_WUTIE              (1 << 14) /* Bit 14: Wakeup timer interrupt 
enable */
+#define RTC_CR_TSIE               (1 << 15) /* Bit 15: Timestamp interrupt 
enable */
+#define RTC_CR_ADD1H              (1 << 16) /* Bit 16: Add 1 hour (summer time 
change) */
+#define RTC_CR_SUB1H              (1 << 17) /* Bit 17: Subtract 1 hour (winter 
time change) */
+#define RTC_CR_BKP                (1 << 18) /* Bit 18: Backup */
+#define RTC_CR_COSEL              (1 << 19) /* Bit 19: Calibration output 
selection */
+#define RTC_CR_POL                (1 << 20) /* Bit 20: Output polarity */
+#define RTC_CR_OSEL_SHIFT         (21)      /* Bits 21-22: Output selection */
+#define RTC_CR_OSEL_MASK          (3 << RTC_CR_OSEL_SHIFT)
+#  define RTC_CR_OSEL_DISABLED    (0 << RTC_CR_OSEL_SHIFT) /* 00: Output 
disabled */
+#  define RTC_CR_OSEL_ALRMA       (1 << RTC_CR_OSEL_SHIFT) /* 01: Alarm A 
output enabled */
+#  define RTC_CR_OSEL_ALRMB       (2 << RTC_CR_OSEL_SHIFT) /* 10: Alarm B 
output enabled */
+#  define RTC_CR_OSEL_WUT         (3 << RTC_CR_OSEL_SHIFT) /* 11: Wakeup 
output enabled */
+
+#define RTC_CR_COE                (1 << 23) /* Bit 23: Calibration output 
enable */
+#define RTC_CR_ITSE               (1 << 24) /* Bit 24: Timestamp on internal 
event enable */
+#define RTC_CR_TAMPTS             (1 << 25) /* Bit 25: Activate timestamp on 
tamper event */
+#define RTC_CR_TAMPOE             (1 << 26) /* Bit 26: Tamper detection output 
enable */
+#define RTC_CR_ALRAFCLR           (1 << 27) /* Bit 27: Alarm A flag automatic 
clear */
+#define RTC_CR_ALRBFCLR           (1 << 28) /* Bit 28: Alarm B flag automatic 
clear */
+#define RTC_CR_TAMPALRM_PU        (1 << 29) /* Bit 29: TAMPALRM pull-up enable 
*/
+#define RTC_CR_TAMPALRM_TYPE      (1 << 30) /* Bit 30: TAMPALRM output type */
+#define RTC_CR_OUT2EN             (1 << 31) /* Bit 31: RTC_OUT2 output enable 
*/
+
+/* RTC privilege mode control register */
+
+#define RTC_PRIVCFGR_ALRAPRIV     (1 << 0)  /* Bit 0: Alarm A privilege 
protection */
+#define RTC_PRIVCFGR_ALRBPRIV     (1 << 1)  /* Bit 1: Alarm B privilege 
protection */
+#define RTC_PRIVCFGR_WUTPRIV      (1 << 2)  /* Bit 2: Wakeup timer privilege 
protection */
+#define RTC_PRIVCFGR_TSPRIV       (1 << 3)  /* Bit 3: Timestamp privilege 
protection */
+#define RTC_PRIVCFGR_CALPRIV      (1 << 13) /* Bit 13: Shift, calibration, 
reference clock privilege protection */
+#define RTC_PRIVCFGR_INITPRIV     (1 << 14) /* Bit 14: Initialization 
privilege protection */
+#define RTC_PRIVCFGR_PRIV         (1 << 15) /* Bit 15: RTC global privilege 
protection */
+
+/* RTC secure mode control register */
+
+#define RTC_SECCFGR_ALRASEC       (1 << 0)  /* Bit 0: Alarm A protection */
+#define RTC_SECCFGR_ALRBSEC       (1 << 1)  /* Bit 1: Alarm B protection */
+#define RTC_SECCFGR_WUTSEC        (1 << 2)  /* Bit 2: Wakeup timer protection 
*/
+#define RTC_SECCFGR_TSSEC         (1 << 3)  /* Bit 3: Timestamp protection */
+#define RTC_SECCFGR_CALSEC        (1 << 13) /* Bit 13: Shift, calibration, 
reference clock protection */
+#define RTC_SECCFGR_INITSEC       (1 << 14) /* Bit 14: Initialization 
protection */
+#define RTC_SECCFGR_SEC           (1 << 15) /* Bit 15: RTC global protection */
+
+/* RTC write protection register */
+
+#define RTC_WPR_KEY_SHIFT         (0)       /* Bits 0-7: Write protection key 
*/
+#define RTC_WPR_KEY_MASK          (0xff << RTC_WPR_KEY_SHIFT)
+#  define RTC_WPR_KEY1            (0xca)    /* First unlock key */
+#  define RTC_WPR_KEY2            (0x53)    /* Second unlock key */
+
+/* RTC calibration register */
+
+#define RTC_CALR_CALM_SHIFT       (0)       /* Bits 0-8: Calibration minus */
+#define RTC_CALR_CALM_MASK        (0x1ff << RTC_CALR_CALM_SHIFT)
+#define RTC_CALR_LPCAL            (1 << 12) /* Bit 12: Calibration low-power 
mode */
+#define RTC_CALR_CALW16           (1 << 13) /* Bit 13: Use a 16-second 
calibration cycle */
+#define RTC_CALR_CALW8            (1 << 14) /* Bit 14: Use an 8-second 
calibration cycle */
+#define RTC_CALR_CALP             (1 << 15) /* Bit 15: Increase frequency of 
RTC by 488.5 ppm */
+
+/* RTC shift control register */
+
+#define RTC_SHIFTR_SUBFS_SHIFT    (0)       /* Bits 0-14: Subtract a fraction 
of a second */
+#define RTC_SHIFTR_SUBFS_MASK     (0x7fff << RTC_SHIFTR_SUBFS_SHIFT)
+#define RTC_SHIFTR_ADD1S          (1 << 31) /* Bit 31: Add one second */
+
+/* RTC timestamp time register */
+
+#define RTC_TSTR_SU_SHIFT         (0)       /* Bits 0-3: Second units in BCD 
format */
+#define RTC_TSTR_SU_MASK          (15 << RTC_TSTR_SU_SHIFT)
+#define RTC_TSTR_ST_SHIFT         (4)       /* Bits 4-6: Second tens in BCD 
format */
+#define RTC_TSTR_ST_MASK          (7 << RTC_TSTR_ST_SHIFT)
+#define RTC_TSTR_MNU_SHIFT        (8)       /* Bits 8-11: Minute units in BCD 
format */
+#define RTC_TSTR_MNU_MASK         (15 << RTC_TSTR_MNU_SHIFT)
+#define RTC_TSTR_MNT_SHIFT        (12)      /* Bits 12-14: Minute tens in BCD 
format */
+#define RTC_TSTR_MNT_MASK         (7 << RTC_TSTR_MNT_SHIFT)
+#define RTC_TSTR_HU_SHIFT         (16)      /* Bits 16-19: Hour units in BCD 
format */
+#define RTC_TSTR_HU_MASK          (15 << RTC_TSTR_HU_SHIFT)
+#define RTC_TSTR_HT_SHIFT         (20)      /* Bits 20-21: Hour tens in BCD 
format */
+#define RTC_TSTR_HT_MASK          (3 << RTC_TSTR_HT_SHIFT)
+#define RTC_TSTR_PM               (1 << 22) /* Bit 22: AM/PM notation */
+
+/* RTC timestamp date register */
+
+#define RTC_TSDR_DU_SHIFT         (0)       /* Bits 0-3: Date units in BCD 
format */
+#define RTC_TSDR_DU_MASK          (15 << RTC_TSDR_DU_SHIFT)
+#define RTC_TSDR_DT_SHIFT         (4)       /* Bits 4-5: Date tens in BCD 
format */
+#define RTC_TSDR_DT_MASK          (3 << RTC_TSDR_DT_SHIFT)
+#define RTC_TSDR_MU_SHIFT         (8)       /* Bits 8-11: Month units in BCD 
format */
+#define RTC_TSDR_MU_MASK          (15 << RTC_TSDR_MU_SHIFT)
+#define RTC_TSDR_MT               (1 << 12) /* Bit 12: Month tens in BCD 
format */
+#define RTC_TSDR_WDU_SHIFT        (13)      /* Bits 13-15: Week day units */
+#define RTC_TSDR_WDU_MASK         (7 << RTC_TSDR_WDU_SHIFT)
+
+/* RTC timestamp sub second register */
+
+#define RTC_TSSSR_SS_SHIFT        (0)       /* Bits 0-31: Sub second value */
+#define RTC_TSSSR_SS_MASK         (0xffffffff << RTC_TSSSR_SS_SHIFT)
+
+/* RTC alarm A/B registers */
+
+#define RTC_ALRMR_SU_SHIFT        (0)       /* Bits 0-3: Second units in BCD 
format */
+#define RTC_ALRMR_SU_MASK         (15 << RTC_ALRMR_SU_SHIFT)
+#define RTC_ALRMR_ST_SHIFT        (4)       /* Bits 4-6: Second tens in BCD 
format */
+#define RTC_ALRMR_ST_MASK         (7 << RTC_ALRMR_ST_SHIFT)
+#define RTC_ALRMR_MSK1            (1 << 7)  /* Bit 7: Alarm seconds mask */
+#define RTC_ALRMR_MNU_SHIFT       (8)       /* Bits 8-11: Minute units in BCD 
format */
+#define RTC_ALRMR_MNU_MASK        (15 << RTC_ALRMR_MNU_SHIFT)
+#define RTC_ALRMR_MNT_SHIFT       (12)      /* Bits 12-14: Minute tens in BCD 
format */
+#define RTC_ALRMR_MNT_MASK        (7 << RTC_ALRMR_MNT_SHIFT)
+#define RTC_ALRMR_MSK2            (1 << 15) /* Bit 15: Alarm minutes mask */
+#define RTC_ALRMR_HU_SHIFT        (16)      /* Bits 16-19: Hour units in BCD 
format */
+#define RTC_ALRMR_HU_MASK         (15 << RTC_ALRMR_HU_SHIFT)
+#define RTC_ALRMR_HT_SHIFT        (20)      /* Bits 20-21: Hour tens in BCD 
format */
+#define RTC_ALRMR_HT_MASK         (3 << RTC_ALRMR_HT_SHIFT)
+#define RTC_ALRMR_PM              (1 << 22) /* Bit 22: AM/PM notation */
+#define RTC_ALRMR_MSK3            (1 << 23) /* Bit 23: Alarm hours mask */
+#define RTC_ALRMR_DU_SHIFT        (24)      /* Bits 24-27: Date units or day 
in BCD format */
+#define RTC_ALRMR_DU_MASK         (15 << RTC_ALRMR_DU_SHIFT)
+#define RTC_ALRMR_DT_SHIFT        (28)      /* Bits 28-29: Date tens in BCD 
format */
+#define RTC_ALRMR_DT_MASK         (3 << RTC_ALRMR_DT_SHIFT)
+#define RTC_ALRMR_WDSEL           (1 << 30) /* Bit 30: Week day selection */
+#define RTC_ALRMR_MSK4            (1 << 31) /* Bit 31: Alarm date mask */
+
+/* RTC alarm A/B sub second registers */
+
+#define RTC_ALRMSSR_SS_SHIFT      (0)       /* Bits 0-14: Sub seconds value */
+#define RTC_ALRMSSR_SS_MASK       (0x7fff << RTC_ALRMSSR_SS_SHIFT)
+#define RTC_ALRMSSR_MASKSS_SHIFT  (24)      /* Bits 24-29: Mask the 
most-significant bits from this bit */
+#define RTC_ALRMSSR_MASKSS_MASK   (0x3f << RTC_ALRMSSR_MASKSS_SHIFT)
+#define RTC_ALRMSSR_SSCLR         (1 << 31) /* Bit 31: Clear sub-second binary 
register on reload */
+
+/* RTC status register */
+
+#define RTC_SR_ALRAF              (1 << 0)  /* Bit 0: Alarm A flag */
+#define RTC_SR_ALRBF              (1 << 1)  /* Bit 1: Alarm B flag */
+#define RTC_SR_WUTF               (1 << 2)  /* Bit 2: Wakeup timer flag */
+#define RTC_SR_TSF                (1 << 3)  /* Bit 3: Timestamp flag */
+#define RTC_SR_TSOVF              (1 << 4)  /* Bit 4: Timestamp overflow flag 
*/
+#define RTC_SR_ITSF               (1 << 5)  /* Bit 5: Internal timestamp flag 
*/
+#define RTC_SR_SSRUF              (1 << 6)  /* Bit 6: SSR underflow flag */
+
+/* RTC masked interrupt status register */
+
+#define RTC_MISR_ALRAMF           (1 << 0)  /* Bit 0: Alarm A masked flag */
+#define RTC_MISR_ALRBMF           (1 << 1)  /* Bit 1: Alarm B masked flag */
+#define RTC_MISR_WUTMF            (1 << 2)  /* Bit 2: Wakeup timer masked flag 
*/
+#define RTC_MISR_TSMF             (1 << 3)  /* Bit 3: Timestamp masked flag */
+#define RTC_MISR_TSOVMF           (1 << 4)  /* Bit 4: Timestamp overflow 
masked flag */
+#define RTC_MISR_ITSMF            (1 << 5)  /* Bit 5: Internal timestamp 
masked flag */
+#define RTC_MISR_SSRUMF           (1 << 6)  /* Bit 6: SSR underflow masked 
flag */
+
+/* RTC secure masked interrupt status register */
+
+#define RTC_SMISR_ALRAMF          (1 << 0)  /* Bit 0: Alarm A secure masked 
flag */
+#define RTC_SMISR_ALRBMF          (1 << 1)  /* Bit 1: Alarm B secure masked 
flag */
+#define RTC_SMISR_WUTMF           (1 << 2)  /* Bit 2: Wakeup timer secure 
masked flag */
+#define RTC_SMISR_TSMF            (1 << 3)  /* Bit 3: Timestamp secure masked 
flag */
+#define RTC_SMISR_TSOVMF          (1 << 4)  /* Bit 4: Timestamp overflow 
secure masked flag */
+#define RTC_SMISR_ITSMF           (1 << 5)  /* Bit 5: Internal timestamp 
secure masked flag */
+#define RTC_SMISR_SSRUMF          (1 << 6)  /* Bit 6: SSR underflow secure 
masked flag */
+
+/* RTC status clear register */
+
+#define RTC_SCR_CALRAF            (1 << 0)  /* Bit 0: Alarm A flag clear */
+#define RTC_SCR_CALRBF            (1 << 1)  /* Bit 1: Alarm B flag clear */
+#define RTC_SCR_CWUTF             (1 << 2)  /* Bit 2: Wakeup timer flag clear 
*/
+#define RTC_SCR_CTSF              (1 << 3)  /* Bit 3: Timestamp flag clear */
+#define RTC_SCR_CTSOVF            (1 << 4)  /* Bit 4: Timestamp overflow flag 
clear */
+#define RTC_SCR_CITSF             (1 << 5)  /* Bit 5: Internal timestamp flag 
clear */
+#define RTC_SCR_CSSRUF            (1 << 6)  /* Bit 6: SSR underflow flag clear 
*/
+
+/* RTC alarm A/B binary mode registers */
+
+#define RTC_ALRBINR_SS_SHIFT      (0)       /* Bits 0-31: Synchronous counter 
alarm value */
+#define RTC_ALRBINR_SS_MASK       (0xffffffff << RTC_ALRBINR_SS_SHIFT)
+
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_RTCC_M33M55_V1_H */
diff --git a/arch/arm/src/common/stm32/hardware/stm32_tamp.h 
b/arch/arm/src/common/stm32/hardware/stm32_tamp.h
new file mode 100644
index 00000000000..68936b7c0b0
--- /dev/null
+++ b/arch/arm/src/common/stm32/hardware/stm32_tamp.h
@@ -0,0 +1,324 @@
+/****************************************************************************
+ * arch/arm/src/common/stm32/hardware/stm32_tamp.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_TAMP_H
+#define __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_TAMP_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register Offsets *********************************************************/
+
+#define STM32_TAMP_CR1_OFFSET     0x0000    /* TAMP control register 1 */
+#define STM32_TAMP_CR2_OFFSET     0x0004    /* TAMP control register 2 */
+#define STM32_TAMP_CR3_OFFSET     0x0008    /* TAMP control register 3 */
+#define STM32_TAMP_FLTCR_OFFSET   0x000c    /* TAMP filter control register */
+#define STM32_TAMP_ATCR1_OFFSET   0x0010    /* TAMP active tamper control 
register 1 */
+#define STM32_TAMP_ATSEEDR_OFFSET 0x0014    /* TAMP active tamper seed 
register */
+#define STM32_TAMP_ATOR_OFFSET    0x0018    /* TAMP active tamper output 
register */
+#define STM32_TAMP_ATCR2_OFFSET   0x001c    /* TAMP active tamper control 
register 2 */
+#define STM32_TAMP_SECCFGR_OFFSET 0x0020    /* TAMP secure mode control 
register */
+#define STM32_TAMP_PRIVCFGR_OFFSET 0x0024   /* TAMP privilege mode control 
register */
+#define STM32_TAMP_IER_OFFSET     0x002c    /* TAMP interrupt enable register 
*/
+#define STM32_TAMP_SR_OFFSET      0x0030    /* TAMP status register */
+#define STM32_TAMP_MISR_OFFSET    0x0034    /* TAMP masked interrupt status 
register */
+#define STM32_TAMP_SMISR_OFFSET   0x0038    /* TAMP secure masked int. status 
register */
+#define STM32_TAMP_SCR_OFFSET     0x003c    /* TAMP status clear register */
+#define STM32_TAMP_COUNT1R_OFFSET 0x0040    /* TAMP monotonic counter 1 
register */
+#define STM32_TAMP_OR_OFFSET      0x0050    /* TAMP option register */
+#define STM32_TAMP_RPCFGR_OFFSET  0x0054    /* TAMP resource protection 
config. register */
+
+#define STM32_TAMP_BKPR_OFFSET(n) (0x0100 + ((n) << 2)) /* TAMP backup 
registers 0-31 */
+
+/* Register Addresses *******************************************************/
+
+#define STM32_TAMP_CR1            (STM32_TAMP_BASE + STM32_TAMP_CR1_OFFSET)
+#define STM32_TAMP_CR2            (STM32_TAMP_BASE + STM32_TAMP_CR2_OFFSET)
+#define STM32_TAMP_CR3            (STM32_TAMP_BASE + STM32_TAMP_CR3_OFFSET)
+#define STM32_TAMP_FLTCR          (STM32_TAMP_BASE + STM32_TAMP_FLTCR_OFFSET)
+#define STM32_TAMP_ATCR1          (STM32_TAMP_BASE + STM32_TAMP_ATCR1_OFFSET)
+#define STM32_TAMP_ATSEEDR        (STM32_TAMP_BASE + STM32_TAMP_ATSEEDR_OFFSET)
+#define STM32_TAMP_ATOR           (STM32_TAMP_BASE + STM32_TAMP_ATOR_OFFSET)
+#define STM32_TAMP_ATCR2          (STM32_TAMP_BASE + STM32_TAMP_ATCR2_OFFSET)
+#define STM32_TAMP_SECCFGR        (STM32_TAMP_BASE + STM32_TAMP_SECCFGR_OFFSET)
+#define STM32_TAMP_PRIVCFGR       (STM32_TAMP_BASE + 
STM32_TAMP_PRIVCFGR_OFFSET)
+#define STM32_TAMP_IER            (STM32_TAMP_BASE + STM32_TAMP_IER_OFFSET)
+#define STM32_TAMP_SR             (STM32_TAMP_BASE + STM32_TAMP_SR_OFFSET)
+#define STM32_TAMP_MISR           (STM32_TAMP_BASE + STM32_TAMP_MISR_OFFSET)
+#define STM32_TAMP_SMISR          (STM32_TAMP_BASE + STM32_TAMP_SMISR_OFFSET)
+#define STM32_TAMP_SCR            (STM32_TAMP_BASE + STM32_TAMP_SCR_OFFSET)
+#define STM32_TAMP_COUNT1R        (STM32_TAMP_BASE + STM32_TAMP_COUNT1R_OFFSET)
+#define STM32_TAMP_OR             (STM32_TAMP_BASE + STM32_TAMP_OR_OFFSET)
+#define STM32_TAMP_RPCFGR         (STM32_TAMP_BASE + STM32_TAMP_RPCFGR_OFFSET)
+#define STM32_TAMP_BKPR(n)        (STM32_TAMP_BASE + STM32_TAMP_BKPR_OFFSET(n))
+
+/* Register Bitfield Definitions ********************************************/
+
+/* TAMP control register 1 */
+
+#define TAMP_CR1_TAMP1E           (1 << 0)  /* Bit 0: Tamper 1 detection 
enable */
+#define TAMP_CR1_TAMP2E           (1 << 1)  /* Bit 1: Tamper 2 detection 
enable */
+#define TAMP_CR1_TAMP3E           (1 << 2)  /* Bit 2: Tamper 3 detection 
enable */
+#define TAMP_CR1_TAMP4E           (1 << 3)  /* Bit 3: Tamper 4 detection 
enable */
+#define TAMP_CR1_TAMP5E           (1 << 4)  /* Bit 4: Tamper 5 detection 
enable */
+#define TAMP_CR1_TAMP6E           (1 << 5)  /* Bit 5: Tamper 6 detection 
enable */
+#define TAMP_CR1_TAMP7E           (1 << 6)  /* Bit 6: Tamper 7 detection 
enable */
+#define TAMP_CR1_ITAMP1E          (1 << 16) /* Bit 16: Internal tamper 1 
enable */
+#define TAMP_CR1_ITAMP2E          (1 << 17) /* Bit 17: Internal tamper 2 
enable */
+#define TAMP_CR1_ITAMP3E          (1 << 18) /* Bit 18: Internal tamper 3 
enable */
+#define TAMP_CR1_ITAMP4E          (1 << 19) /* Bit 19: Internal tamper 4 
enable */
+#define TAMP_CR1_ITAMP5E          (1 << 20) /* Bit 20: Internal tamper 5 
enable */
+#define TAMP_CR1_ITAMP6E          (1 << 21) /* Bit 21: Internal tamper 6 
enable */
+#define TAMP_CR1_ITAMP7E          (1 << 22) /* Bit 22: Internal tamper 7 
enable */
+#define TAMP_CR1_ITAMP8E          (1 << 23) /* Bit 23: Internal tamper 8 
enable */
+#define TAMP_CR1_ITAMP9E          (1 << 24) /* Bit 24: Internal tamper 9 
enable */
+#define TAMP_CR1_ITAMP11E         (1 << 26) /* Bit 26: Internal tamper 11 
enable */
+
+/* TAMP control register 2 */
+
+#define TAMP_CR2_TAMP1POM         (1 << 0)  /* Bit 0: Tamper 1 potential mode 
*/
+#define TAMP_CR2_TAMP2POM         (1 << 1)  /* Bit 1: Tamper 2 potential mode 
*/
+#define TAMP_CR2_TAMP3POM         (1 << 2)  /* Bit 2: Tamper 3 potential mode 
*/
+#define TAMP_CR2_TAMP4POM         (1 << 3)  /* Bit 3: Tamper 4 potential mode 
*/
+#define TAMP_CR2_TAMP5POM         (1 << 4)  /* Bit 4: Tamper 5 potential mode 
*/
+#define TAMP_CR2_TAMP6POM         (1 << 5)  /* Bit 5: Tamper 6 potential mode 
*/
+#define TAMP_CR2_TAMP7POM         (1 << 6)  /* Bit 6: Tamper 7 potential mode 
*/
+#define TAMP_CR2_TAMP1MSK         (1 << 16) /* Bit 16: Tamper 1 mask */
+#define TAMP_CR2_TAMP2MSK         (1 << 17) /* Bit 17: Tamper 2 mask */
+#define TAMP_CR2_TAMP3MSK         (1 << 18) /* Bit 18: Tamper 3 mask */
+#define TAMP_CR2_BKBLOCK          (1 << 22) /* Bit 22: Backup registers and 
SRAMs access block */
+#define TAMP_CR2_BKERASE          (1 << 23) /* Bit 23: Backup registers and 
SRAMs erase */
+#define TAMP_CR2_TAMP1TRG         (1 << 24) /* Bit 24: Tamper 1 active level */
+#define TAMP_CR2_TAMP2TRG         (1 << 25) /* Bit 25: Tamper 2 active level */
+#define TAMP_CR2_TAMP3TRG         (1 << 26) /* Bit 26: Tamper 3 active level */
+#define TAMP_CR2_TAMP4TRG         (1 << 27) /* Bit 27: Tamper 4 active level */
+#define TAMP_CR2_TAMP5TRG         (1 << 28) /* Bit 28: Tamper 5 active level */
+#define TAMP_CR2_TAMP6TRG         (1 << 29) /* Bit 29: Tamper 6 active level */
+#define TAMP_CR2_TAMP7TRG         (1 << 30) /* Bit 30: Tamper 7 active level */
+
+/* TAMP control register 3 */
+
+#define TAMP_CR3_ITAMP1POM        (1 << 0)  /* Bit 0: Internal tamper 1 
potential mode */
+#define TAMP_CR3_ITAMP2POM        (1 << 1)  /* Bit 1: Internal tamper 2 
potential mode */
+#define TAMP_CR3_ITAMP3POM        (1 << 2)  /* Bit 2: Internal tamper 3 
potential mode */
+#define TAMP_CR3_ITAMP4POM        (1 << 3)  /* Bit 3: Internal tamper 4 
potential mode */
+#define TAMP_CR3_ITAMP5POM        (1 << 4)  /* Bit 4: Internal tamper 5 
potential mode */
+#define TAMP_CR3_ITAMP6POM        (1 << 5)  /* Bit 5: Internal tamper 6 
potential mode */
+#define TAMP_CR3_ITAMP7POM        (1 << 6)  /* Bit 6: Internal tamper 7 
potential mode */
+#define TAMP_CR3_ITAMP8POM        (1 << 7)  /* Bit 7: Internal tamper 8 
potential mode */
+#define TAMP_CR3_ITAMP9POM        (1 << 8)  /* Bit 8: Internal tamper 9 
potential mode */
+#define TAMP_CR3_ITAMP11POM       (1 << 10) /* Bit 10: Internal tamper 11 
potential mode */
+
+/* TAMP filter control register */
+
+#define TAMP_FLTCR_TAMPFREQ_SHIFT (0)       /* Bits 0-2: Tamper sampling 
frequency */
+#define TAMP_FLTCR_TAMPFREQ_MASK  (7 << TAMP_FLTCR_TAMPFREQ_SHIFT)
+#define TAMP_FLTCR_TAMPFLT_SHIFT  (3)       /* Bits 3-4: Tamper filter count */
+#define TAMP_FLTCR_TAMPFLT_MASK   (3 << TAMP_FLTCR_TAMPFLT_SHIFT)
+#define TAMP_FLTCR_TAMPPRCH_SHIFT (5)       /* Bits 5-6: Tamper precharge 
duration */
+#define TAMP_FLTCR_TAMPPRCH_MASK  (3 << TAMP_FLTCR_TAMPPRCH_SHIFT)
+#define TAMP_FLTCR_TAMPPUDIS      (1 << 7)  /* Bit 7: Tamper pull-up disable */
+
+/* TAMP active tamper control register 1 */
+
+#define TAMP_ATCR1_TAMP1AM        (1 << 0)  /* Bit 0: Tamper 1 active mode */
+#define TAMP_ATCR1_TAMP2AM        (1 << 1)  /* Bit 1: Tamper 2 active mode */
+#define TAMP_ATCR1_TAMP3AM        (1 << 2)  /* Bit 2: Tamper 3 active mode */
+#define TAMP_ATCR1_TAMP4AM        (1 << 3)  /* Bit 3: Tamper 4 active mode */
+#define TAMP_ATCR1_TAMP5AM        (1 << 4)  /* Bit 4: Tamper 5 active mode */
+#define TAMP_ATCR1_TAMP6AM        (1 << 5)  /* Bit 5: Tamper 6 active mode */
+#define TAMP_ATCR1_TAMP7AM        (1 << 6)  /* Bit 6: Tamper 7 active mode */
+#define TAMP_ATCR1_ATOSEL1_SHIFT  (8)       /* Bits 8-9: Active tamper shared 
output 1 selection */
+#define TAMP_ATCR1_ATOSEL1_MASK   (3 << TAMP_ATCR1_ATOSEL1_SHIFT)
+#define TAMP_ATCR1_ATOSEL2_SHIFT  (10)      /* Bits 10-11: Active tamper 
shared output 2 selection */
+#define TAMP_ATCR1_ATOSEL2_MASK   (3 << TAMP_ATCR1_ATOSEL2_SHIFT)
+#define TAMP_ATCR1_ATOSEL3_SHIFT  (12)      /* Bits 12-13: Active tamper 
shared output 3 selection */
+#define TAMP_ATCR1_ATOSEL3_MASK   (3 << TAMP_ATCR1_ATOSEL3_SHIFT)
+#define TAMP_ATCR1_ATOSEL4_SHIFT  (14)      /* Bits 14-15: Active tamper 
shared output 4 selection */
+#define TAMP_ATCR1_ATOSEL4_MASK   (3 << TAMP_ATCR1_ATOSEL4_SHIFT)
+#define TAMP_ATCR1_ATCKSEL_SHIFT  (16)      /* Bits 16-19: Active tamper RTC 
clock selection */
+#define TAMP_ATCR1_ATCKSEL_MASK   (15 << TAMP_ATCR1_ATCKSEL_SHIFT)
+#define TAMP_ATCR1_ATPER_SHIFT    (24)      /* Bits 24-26: Active tamper 
output change period */
+#define TAMP_ATCR1_ATPER_MASK     (7 << TAMP_ATCR1_ATPER_SHIFT)
+#define TAMP_ATCR1_ATOSHARE       (1 << 30) /* Bit 30: Active tamper output 
sharing */
+#define TAMP_ATCR1_FLTEN          (1 << 31) /* Bit 31: Active tamper filter 
enable */
+
+/* TAMP active tamper seed register */
+
+#define TAMP_ATSEEDR_SEED_SHIFT   (0)       /* Bits 0-31: Pseudo-random 
generator seed value */
+#define TAMP_ATSEEDR_SEED_MASK    (0xffffffff << TAMP_ATSEEDR_SEED_SHIFT)
+
+/* TAMP active tamper output register */
+
+#define TAMP_ATOR_PRNG_SHIFT      (0)       /* Bits 0-7: Pseudo-random 
generator value */
+#define TAMP_ATOR_PRNG_MASK       (0xff << TAMP_ATOR_PRNG_SHIFT)
+
+/* TAMP active tamper control register 2 */
+
+#define TAMP_ATCR2_ATOSEL1_SHIFT  (8)       /* Bits 8-10: Active tamper shared 
output 1 selection */
+#define TAMP_ATCR2_ATOSEL1_MASK   (7 << TAMP_ATCR2_ATOSEL1_SHIFT)
+#define TAMP_ATCR2_ATOSEL2_SHIFT  (11)      /* Bits 11-13: Active tamper 
shared output 2 selection */
+#define TAMP_ATCR2_ATOSEL2_MASK   (7 << TAMP_ATCR2_ATOSEL2_SHIFT)
+#define TAMP_ATCR2_ATOSEL3_SHIFT  (14)      /* Bits 14-16: Active tamper 
shared output 3 selection */
+#define TAMP_ATCR2_ATOSEL3_MASK   (7 << TAMP_ATCR2_ATOSEL3_SHIFT)
+#define TAMP_ATCR2_ATOSEL4_SHIFT  (17)      /* Bits 17-19: Active tamper 
shared output 4 selection */
+#define TAMP_ATCR2_ATOSEL4_MASK   (7 << TAMP_ATCR2_ATOSEL4_SHIFT)
+#define TAMP_ATCR2_ATOSEL5_SHIFT  (20)      /* Bits 20-22: Active tamper 
shared output 5 selection */
+#define TAMP_ATCR2_ATOSEL5_MASK   (7 << TAMP_ATCR2_ATOSEL5_SHIFT)
+#define TAMP_ATCR2_ATOSEL6_SHIFT  (23)      /* Bits 23-25: Active tamper 
shared output 6 selection */
+#define TAMP_ATCR2_ATOSEL6_MASK   (7 << TAMP_ATCR2_ATOSEL6_SHIFT)
+#define TAMP_ATCR2_ATOSEL7_SHIFT  (26)      /* Bits 26-28: Active tamper 
shared output 7 selection */
+#define TAMP_ATCR2_ATOSEL7_MASK   (7 << TAMP_ATCR2_ATOSEL7_SHIFT)
+
+/* TAMP secure mode control register */
+
+#define TAMP_SECCFGR_BKPRWSEC_SHIFT (0)     /* Bits 0-7: Backup registers 
read/write protection */
+#define TAMP_SECCFGR_BKPRWSEC_MASK (0xff << TAMP_SECCFGR_BKPRWSEC_SHIFT)
+#define TAMP_SECCFGR_CNT1SEC      (1 << 15) /* Bit 15: Monotonic counter 1 
secure protection */
+#define TAMP_SECCFGR_BKPWSEC_SHIFT (16)     /* Bits 16-23: Backup registers 
write protection */
+#define TAMP_SECCFGR_BKPWSEC_MASK (0xff << TAMP_SECCFGR_BKPWSEC_SHIFT)
+#define TAMP_SECCFGR_BHKLOCK      (1 << 30) /* Bit 30: Boot hardware key lock 
*/
+#define TAMP_SECCFGR_TAMPSEC      (1 << 31) /* Bit 31: Tamper protection */
+
+/* TAMP privilege mode control register */
+
+#define TAMP_PRIVCFGR_CNT1PRIV    (1 << 15) /* Bit 15: Monotonic counter 1 
privilege protection */
+#define TAMP_PRIVCFGR_BKPRWPRIV   (1 << 29) /* Bit 29: Backup registers zone 1 
privilege */
+#define TAMP_PRIVCFGR_BKPWPRIV    (1 << 30) /* Bit 30: Backup registers zone 2 
privilege */
+#define TAMP_PRIVCFGR_TAMPPRIV    (1 << 31) /* Bit 31: Tamper privilege 
protection */
+
+/* TAMP interrupt enable register */
+
+#define TAMP_IER_TAMP1IE          (1 << 0)  /* Bit 0: Tamper 1 interrupt 
enable */
+#define TAMP_IER_TAMP2IE          (1 << 1)  /* Bit 1: Tamper 2 interrupt 
enable */
+#define TAMP_IER_TAMP3IE          (1 << 2)  /* Bit 2: Tamper 3 interrupt 
enable */
+#define TAMP_IER_TAMP4IE          (1 << 3)  /* Bit 3: Tamper 4 interrupt 
enable */
+#define TAMP_IER_TAMP5IE          (1 << 4)  /* Bit 4: Tamper 5 interrupt 
enable */
+#define TAMP_IER_TAMP6IE          (1 << 5)  /* Bit 5: Tamper 6 interrupt 
enable */
+#define TAMP_IER_TAMP7IE          (1 << 6)  /* Bit 6: Tamper 7 interrupt 
enable */
+#define TAMP_IER_ITAMP1IE         (1 << 16) /* Bit 16: Internal tamper 1 
interrupt enable */
+#define TAMP_IER_ITAMP2IE         (1 << 17) /* Bit 17: Internal tamper 2 
interrupt enable */
+#define TAMP_IER_ITAMP3IE         (1 << 18) /* Bit 18: Internal tamper 3 
interrupt enable */
+#define TAMP_IER_ITAMP4IE         (1 << 19) /* Bit 19: Internal tamper 4 
interrupt enable */
+#define TAMP_IER_ITAMP5IE         (1 << 20) /* Bit 20: Internal tamper 5 
interrupt enable */
+#define TAMP_IER_ITAMP6IE         (1 << 21) /* Bit 21: Internal tamper 6 
interrupt enable */
+#define TAMP_IER_ITAMP7IE         (1 << 22) /* Bit 22: Internal tamper 7 
interrupt enable */
+#define TAMP_IER_ITAMP8IE         (1 << 23) /* Bit 23: Internal tamper 8 
interrupt enable */
+#define TAMP_IER_ITAMP9IE         (1 << 24) /* Bit 24: Internal tamper 9 
interrupt enable */
+#define TAMP_IER_ITAMP11IE        (1 << 26) /* Bit 26: Internal tamper 11 
interrupt enable */
+
+/* TAMP status register */
+
+#define TAMP_SR_TAMP1F            (1 << 0)  /* Bit 0: Tamper 1 detection flag 
*/
+#define TAMP_SR_TAMP2F            (1 << 1)  /* Bit 1: Tamper 2 detection flag 
*/
+#define TAMP_SR_TAMP3F            (1 << 2)  /* Bit 2: Tamper 3 detection flag 
*/
+#define TAMP_SR_TAMP4F            (1 << 3)  /* Bit 3: Tamper 4 detection flag 
*/
+#define TAMP_SR_TAMP5F            (1 << 4)  /* Bit 4: Tamper 5 detection flag 
*/
+#define TAMP_SR_TAMP6F            (1 << 5)  /* Bit 5: Tamper 6 detection flag 
*/
+#define TAMP_SR_TAMP7F            (1 << 6)  /* Bit 6: Tamper 7 detection flag 
*/
+#define TAMP_SR_ITAMP1F           (1 << 16) /* Bit 16: Internal tamper 1 flag 
*/
+#define TAMP_SR_ITAMP2F           (1 << 17) /* Bit 17: Internal tamper 2 flag 
*/
+#define TAMP_SR_ITAMP3F           (1 << 18) /* Bit 18: Internal tamper 3 flag 
*/
+#define TAMP_SR_ITAMP4F           (1 << 19) /* Bit 19: Internal tamper 4 flag 
*/
+#define TAMP_SR_ITAMP5F           (1 << 20) /* Bit 20: Internal tamper 5 flag 
*/
+#define TAMP_SR_ITAMP6F           (1 << 21) /* Bit 21: Internal tamper 6 flag 
*/
+#define TAMP_SR_ITAMP7F           (1 << 22) /* Bit 22: Internal tamper 7 flag 
*/
+#define TAMP_SR_ITAMP8F           (1 << 23) /* Bit 23: Internal tamper 8 flag 
*/
+#define TAMP_SR_ITAMP9F           (1 << 24) /* Bit 24: Internal tamper 9 flag 
*/
+#define TAMP_SR_ITAMP11F          (1 << 26) /* Bit 26: Internal tamper 11 flag 
*/
+
+/* TAMP masked interrupt status register */
+
+#define TAMP_MISR_TAMP1MF         (1 << 0)  /* Bit 0: Tamper 1 masked flag */
+#define TAMP_MISR_TAMP2MF         (1 << 1)  /* Bit 1: Tamper 2 masked flag */
+#define TAMP_MISR_TAMP3MF         (1 << 2)  /* Bit 2: Tamper 3 masked flag */
+#define TAMP_MISR_TAMP4MF         (1 << 3)  /* Bit 3: Tamper 4 masked flag */
+#define TAMP_MISR_TAMP5MF         (1 << 4)  /* Bit 4: Tamper 5 masked flag */
+#define TAMP_MISR_TAMP6MF         (1 << 5)  /* Bit 5: Tamper 6 masked flag */
+#define TAMP_MISR_TAMP7MF         (1 << 6)  /* Bit 6: Tamper 7 masked flag */
+#define TAMP_MISR_ITAMP1MF        (1 << 16) /* Bit 16: Internal tamper 1 
masked flag */
+#define TAMP_MISR_ITAMP2MF        (1 << 17) /* Bit 17: Internal tamper 2 
masked flag */
+#define TAMP_MISR_ITAMP3MF        (1 << 18) /* Bit 18: Internal tamper 3 
masked flag */
+#define TAMP_MISR_ITAMP4MF        (1 << 19) /* Bit 19: Internal tamper 4 
masked flag */
+#define TAMP_MISR_ITAMP5MF        (1 << 20) /* Bit 20: Internal tamper 5 
masked flag */
+#define TAMP_MISR_ITAMP6MF        (1 << 21) /* Bit 21: Internal tamper 6 
masked flag */
+#define TAMP_MISR_ITAMP7MF        (1 << 22) /* Bit 22: Internal tamper 7 
masked flag */
+#define TAMP_MISR_ITAMP8MF        (1 << 23) /* Bit 23: Internal tamper 8 
masked flag */
+#define TAMP_MISR_ITAMP9MF        (1 << 24) /* Bit 24: Internal tamper 9 
masked flag */
+#define TAMP_MISR_ITAMP11MF       (1 << 26) /* Bit 26: Internal tamper 11 
masked flag */
+
+/* TAMP secure masked interrupt status register */
+
+#define TAMP_SMISR_TAMP1MF        (1 << 0)  /* Bit 0: Tamper 1 secure masked 
flag */
+#define TAMP_SMISR_TAMP2MF        (1 << 1)  /* Bit 1: Tamper 2 secure masked 
flag */
+#define TAMP_SMISR_TAMP3MF        (1 << 2)  /* Bit 2: Tamper 3 secure masked 
flag */
+#define TAMP_SMISR_TAMP4MF        (1 << 3)  /* Bit 3: Tamper 4 secure masked 
flag */
+#define TAMP_SMISR_TAMP5MF        (1 << 4)  /* Bit 4: Tamper 5 secure masked 
flag */
+#define TAMP_SMISR_TAMP6MF        (1 << 5)  /* Bit 5: Tamper 6 secure masked 
flag */
+#define TAMP_SMISR_TAMP7MF        (1 << 6)  /* Bit 6: Tamper 7 secure masked 
flag */
+#define TAMP_SMISR_ITAMP1MF       (1 << 16) /* Bit 16: Int. tamper 1 secure 
masked flag */
+#define TAMP_SMISR_ITAMP2MF       (1 << 17) /* Bit 17: Int. tamper 2 secure 
masked flag */
+#define TAMP_SMISR_ITAMP3MF       (1 << 18) /* Bit 18: Int. tamper 3 secure 
masked flag */
+#define TAMP_SMISR_ITAMP4MF       (1 << 19) /* Bit 19: Int. tamper 4 secure 
masked flag */
+#define TAMP_SMISR_ITAMP5MF       (1 << 20) /* Bit 20: Int. tamper 5 secure 
masked flag */
+#define TAMP_SMISR_ITAMP6MF       (1 << 21) /* Bit 21: Int. tamper 6 secure 
masked flag */
+#define TAMP_SMISR_ITAMP7MF       (1 << 22) /* Bit 22: Int. tamper 7 secure 
masked flag */
+#define TAMP_SMISR_ITAMP8MF       (1 << 23) /* Bit 23: Int. tamper 8 secure 
masked flag */
+#define TAMP_SMISR_ITAMP9MF       (1 << 24) /* Bit 24: Int. tamper 9 secure 
masked flag */
+#define TAMP_SMISR_ITAMP11MF      (1 << 26) /* Bit 26: Int. tamper 11 secure 
masked flag */
+
+/* TAMP status clear register */
+
+#define TAMP_SCR_CTAMP1F          (1 << 0)  /* Bit 0: Clear tamper 1 detection 
flag */
+#define TAMP_SCR_CTAMP2F          (1 << 1)  /* Bit 1: Clear tamper 2 detection 
flag */
+#define TAMP_SCR_CTAMP3F          (1 << 2)  /* Bit 2: Clear tamper 3 detection 
flag */
+#define TAMP_SCR_CTAMP4F          (1 << 3)  /* Bit 3: Clear tamper 4 detection 
flag */
+#define TAMP_SCR_CTAMP5F          (1 << 4)  /* Bit 4: Clear tamper 5 detection 
flag */
+#define TAMP_SCR_CTAMP6F          (1 << 5)  /* Bit 5: Clear tamper 6 detection 
flag */
+#define TAMP_SCR_CTAMP7F          (1 << 6)  /* Bit 6: Clear tamper 7 detection 
flag */
+#define TAMP_SCR_CTAMP8F          (1 << 7)  /* Bit 7: Clear tamper 8 detection 
flag */
+#define TAMP_SCR_CITAMP1F         (1 << 16) /* Bit 16: Clear internal tamper 1 
flag */
+#define TAMP_SCR_CITAMP2F         (1 << 17) /* Bit 17: Clear internal tamper 2 
flag */
+#define TAMP_SCR_CITAMP3F         (1 << 18) /* Bit 18: Clear internal tamper 3 
flag */
+#define TAMP_SCR_CITAMP4F         (1 << 19) /* Bit 19: Clear internal tamper 4 
flag */
+#define TAMP_SCR_CITAMP5F         (1 << 20) /* Bit 20: Clear internal tamper 5 
flag */
+#define TAMP_SCR_CITAMP6F         (1 << 21) /* Bit 21: Clear internal tamper 6 
flag */
+#define TAMP_SCR_CITAMP7F         (1 << 22) /* Bit 22: Clear internal tamper 7 
flag */
+#define TAMP_SCR_CITAMP8F         (1 << 23) /* Bit 23: Clear internal tamper 8 
flag */
+#define TAMP_SCR_CITAMP9F         (1 << 24) /* Bit 24: Clear internal tamper 9 
flag */
+#define TAMP_SCR_CITAMP11F        (1 << 26) /* Bit 26: Clear internal tamper 
11 flag */
+
+/* TAMP monotonic counter 1 register */
+
+#define TAMP_COUNT1R_COUNT_SHIFT  (0)       /* Bits 0-31: Monotonic counter 
value */
+#define TAMP_COUNT1R_COUNT_MASK   (0xffffffff << TAMP_COUNT1R_COUNT_SHIFT)
+
+/* TAMP option register */
+
+#define TAMP_OR_VCOREMEN          (1 << 0)  /* Bit 0: VCORE monitoring enable 
*/
+
+/* TAMP resource protection configuration register */
+
+#define TAMP_RPCFGR_RPCFG0        (1 << 0)  /* Bit 0: Configurable resource 0 
protection */
+
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_TAMP_H */
diff --git a/arch/arm/src/common/stm32/stm32_alarm.h 
b/arch/arm/src/common/stm32/stm32_alarm.h
index 1c011e5fd94..d82b86e882f 100644
--- a/arch/arm/src/common/stm32/stm32_alarm.h
+++ b/arch/arm/src/common/stm32/stm32_alarm.h
@@ -42,7 +42,8 @@
  */
 
 #if defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_F4) || \
-    defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_L1)
+    defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_L1) || \
+    defined(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)
 #  define STM32_RTC_HAVE_ALARMB 1
 #endif
 
diff --git a/arch/arm/src/common/stm32/stm32_rtc.h 
b/arch/arm/src/common/stm32/stm32_rtc.h
index 949ac27d411..17a626ae7b4 100644
--- a/arch/arm/src/common/stm32/stm32_rtc.h
+++ b/arch/arm/src/common/stm32/stm32_rtc.h
@@ -29,7 +29,8 @@
 
 #include <nuttx/config.h>
 
-#ifdef CONFIG_STM32_HAVE_IP_RTC_M3M4_V1
+#if defined(CONFIG_STM32_HAVE_IP_RTC_M3M4_V1) || \
+    defined(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)
 
 #include "chip.h"
 
@@ -50,6 +51,12 @@
       defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F4XXX) || \
       defined(CONFIG_STM32_STM32G4XXX)
 #  include "hardware/stm32_rtcc.h"
+
+/* The M33/M55 RTC keeps its backup registers in the TAMP peripheral */
+
+#elif defined(CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1)
+#  include "hardware/stm32_rtcc.h"
+#  include "hardware/stm32_tamp.h"
 #endif
 
 #include "stm32_alarm.h"
@@ -91,7 +98,11 @@
 #  define CONFIG_STM32_RTC_MAGIC_REG      (0)
 #endif
 
-#define RTC_MAGIC_REG                     
STM32_RTC_BKR(CONFIG_STM32_RTC_MAGIC_REG)
+#ifdef CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1
+#  define RTC_MAGIC_REG                   
STM32_TAMP_BKPR(CONFIG_STM32_RTC_MAGIC_REG)
+#else
+#  define RTC_MAGIC_REG                   
STM32_RTC_BKR(CONFIG_STM32_RTC_MAGIC_REG)
+#endif
 
 #endif /* CONFIG_STM32_STM32F10XX */
 
@@ -213,5 +224,5 @@ struct rtc_lowerhalf_s *stm32_rtc_lowerhalf(void);
 #endif
 #endif /* __ASSEMBLY__ */
 
-#endif /* CONFIG_STM32_HAVE_IP_RTC_M3M4_V1 */
+#endif /* CONFIG_STM32_HAVE_IP_RTC_M3M4_V1 || 
CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1 */
 #endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_RTC_H */
diff --git a/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c 
b/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
new file mode 100644
index 00000000000..7c19dd5051d
--- /dev/null
+++ b/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
@@ -0,0 +1,1489 @@
+/****************************************************************************
+ * arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <sched.h>
+#include <time.h>
+#include <assert.h>
+#include <errno.h>
+#include <nuttx/debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+
+#include "arm_internal.h"
+#include "stm32.h"
+#include "stm32_rtc.h"
+
+#include <arch/board/board.h>
+
+#ifdef CONFIG_STM32_RTC
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+/* This RTC implementation supports the RTC of the STM32N6:
+ *  - date/time RTC hardware with sub-seconds
+ *  - Alarm A and Alarm B sharing one RTC interrupt with the wakeup timer
+ *  - the periodic wakeup timer
+ *  - backup registers in the TAMP peripheral
+ *
+ * Backup domain write access (PWR DBP) is enabled once and kept enabled:
+ * on the STM32N6 an RTC register write with DBP clear never completes and
+ * stalls the bus until the next power cycle.  Write protection relies on
+ * the RTC_WPR key instead.
+ */
+
+#ifndef CONFIG_RTC_DATETIME
+#  error "CONFIG_RTC_DATETIME must be set to use this driver"
+#endif
+
+#ifdef CONFIG_RTC_HIRES
+#  error "CONFIG_RTC_HIRES must NOT be set with this driver"
+#endif
+
+/* Constants ****************************************************************/
+
+#define SYNCHRO_TIMEOUT      (0x00020000)
+#define INITMODE_TIMEOUT     (0x00010000)
+
+/* RCC glue: the RTC is on APB4 and its clock source in CCIPR7.  CCIPR7 is
+ * reset with the system, so the clock selection is not retained.
+ */
+
+#if defined(RCC_APB4LENR_RTCEN)
+#  define STM32_RCC_RTCENR        STM32_RCC_APB4LENR
+#  define RCC_RTCENR_RTCEN        (RCC_APB4LENR_RTCEN | RCC_APB4LENR_RTCAPBEN)
+#  define STM32_RCC_RTCSELR       STM32_RCC_CCIPR7
+#  define RCC_RTCSELR_RTCSEL_MASK RCC_CCIPR7_RTCSEL_MASK
+#  define RCC_RTCSELR_RTCSEL_LSE  RCC_CCIPR7_RTCSEL_LSE
+#  define RCC_RTCSELR_RTCSEL_LSI  RCC_CCIPR7_RTCSEL_LSI
+#  define RCC_RTCSELR_RTCSEL_HSE  RCC_CCIPR7_RTCSEL_HSE
+#else
+#  error "Unknown RTC clock enable register"
+#endif
+
+#if defined(CONFIG_STM32_RTC_HSECLOCK)
+#  define RCC_RTCSELR_RTCSEL      RCC_RTCSELR_RTCSEL_HSE
+#elif defined(CONFIG_STM32_RTC_LSICLOCK)
+#  define RCC_RTCSELR_RTCSEL      RCC_RTCSELR_RTCSEL_LSI
+#else
+#  define RCC_RTCSELR_RTCSEL      RCC_RTCSELR_RTCSEL_LSE
+#endif
+
+/* The RTC is clocked at 1 MHz from the HSE (see AN4759), divided down by
+ * the RCC RTCPRE prescaler.
+ */
+
+#define RTC_HSE_FREQUENCY         1000000
+
+/* RTCCLK frequency, the wakeup timer counts RTCCLK/16 for short periods */
+
+#if defined(CONFIG_STM32_RTC_HSECLOCK)
+#  define RTC_CLK_FREQUENCY       RTC_HSE_FREQUENCY
+#elif defined(CONFIG_STM32_RTC_LSICLOCK)
+#  define RTC_CLK_FREQUENCY       STM32_LSI_FREQUENCY
+#else
+#  define RTC_CLK_FREQUENCY       STM32_LSE_FREQUENCY
+#endif
+
+#ifdef CONFIG_STM32_RTC_HSECLOCK
+#  if !defined(RCC_CCIPR7_RTCPRE_MASK)
+#    error "The RTC HSE clock needs the RCC RTCPRE prescaler"
+#  elif STM32_HSE_FREQUENCY % RTC_HSE_FREQUENCY != 0 || \
+        STM32_HSE_FREQUENCY / RTC_HSE_FREQUENCY - 1 > \
+        (RCC_CCIPR7_RTCPRE_MASK >> RCC_CCIPR7_RTCPRE_SHIFT)
+#    error "The HSE frequency cannot be divided down to 1 MHz for the RTC"
+#  endif
+#endif
+
+#define RTC_ALRMR_ENABLE          (0)
+
+/* The sub second value has 16 bits in BCD mode */
+
+#define RTC_SSR_BCD_MASK          (0xffff)
+
+/* Interrupt flags handled by this driver */
+
+#define RTC_SCR_ALLF              (RTC_SCR_CALRAF | RTC_SCR_CALRBF | \
+                                   RTC_SCR_CWUTF)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+typedef unsigned int rtc_alarmreg_t;
+
+struct alm_cbinfo_s
+{
+  volatile alm_callback_t ac_cb; /* Client callback function */
+  volatile void *ac_arg;         /* Argument to pass with the callback */
+};
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+static struct alm_cbinfo_s g_alarmcb[RTC_ALARM_LAST];
+#endif
+
+#ifdef CONFIG_RTC_PERIODIC
+static wakeupcb_t g_wakeupcb;
+#endif
+
+#if defined(CONFIG_RTC_ALARM) || defined(CONFIG_RTC_PERIODIC)
+static bool g_rtc_irq_enabled;  /* True: the RTC interrupt is attached */
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* g_rtc_enabled is set true after the RTC has successfully initialized */
+
+volatile bool g_rtc_enabled = false;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rtc_dumpregs
+ ****************************************************************************/
+
+#ifdef CONFIG_DEBUG_RTC_INFO
+static void rtc_dumpregs(const char *msg)
+{
+  rtcinfo("%s:\n", msg);
+  rtcinfo("      TR: %08" PRIx32 "\n", getreg32(STM32_RTC_TR));
+  rtcinfo("      DR: %08" PRIx32 "\n", getreg32(STM32_RTC_DR));
+  rtcinfo("     SSR: %08" PRIx32 "\n", getreg32(STM32_RTC_SSR));
+  rtcinfo("    ICSR: %08" PRIx32 "\n", getreg32(STM32_RTC_ICSR));
+  rtcinfo("    PRER: %08" PRIx32 "\n", getreg32(STM32_RTC_PRER));
+  rtcinfo("    WUTR: %08" PRIx32 "\n", getreg32(STM32_RTC_WUTR));
+  rtcinfo("      CR: %08" PRIx32 "\n", getreg32(STM32_RTC_CR));
+  rtcinfo("  ALRMAR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMAR));
+  rtcinfo("ALRMASSR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMASSR));
+  rtcinfo("  ALRMBR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMBR));
+  rtcinfo("ALRMBSSR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMBSSR));
+  rtcinfo("      SR: %08" PRIx32 "\n", getreg32(STM32_RTC_SR));
+  rtcinfo("    MISR: %08" PRIx32 "\n", getreg32(STM32_RTC_MISR));
+  rtcinfo("    CALR: %08" PRIx32 "\n", getreg32(STM32_RTC_CALR));
+  rtcinfo("MAGICREG: %08" PRIx32 "\n", getreg32(RTC_MAGIC_REG));
+}
+#else
+#  define rtc_dumpregs(msg)
+#endif
+
+/****************************************************************************
+ * Name: rtc_dumptime
+ ****************************************************************************/
+
+#ifdef CONFIG_DEBUG_RTC_INFO
+static void rtc_dumptime(const struct tm *tp, const char *msg)
+{
+  rtcinfo("%s:\n", msg);
+  rtcinfo("  tm_sec: %08x\n", tp->tm_sec);
+  rtcinfo("  tm_min: %08x\n", tp->tm_min);
+  rtcinfo(" tm_hour: %08x\n", tp->tm_hour);
+  rtcinfo(" tm_mday: %08x\n", tp->tm_mday);
+  rtcinfo("  tm_mon: %08x\n", tp->tm_mon);
+  rtcinfo(" tm_year: %08x\n", tp->tm_year);
+}
+#else
+#  define rtc_dumptime(tp, msg)
+#endif
+
+/****************************************************************************
+ * Name: rtc_wprunlock
+ *
+ * Description:
+ *    Disable RTC write protection
+ *
+ ****************************************************************************/
+
+static void rtc_wprunlock(void)
+{
+  /* The following steps are required to unlock the write protection on all
+   * the RTC registers (except for RTC_ICSR[13:8], RTC_SCR and the TAMP
+   * registers):
+   *
+   * 1. Write 0xCA into the RTC_WPR register.
+   * 2. Write 0x53 into the RTC_WPR register.
+   *
+   * Writing a wrong key re-activates the write protection.
+   */
+
+  putreg32(RTC_WPR_KEY1, STM32_RTC_WPR);
+  putreg32(RTC_WPR_KEY2, STM32_RTC_WPR);
+}
+
+/****************************************************************************
+ * Name: rtc_wprlock
+ *
+ * Description:
+ *    Enable RTC write protection
+ *
+ ****************************************************************************/
+
+static inline void rtc_wprlock(void)
+{
+  /* Writing any wrong key re-activates the write protection. */
+
+  putreg32(0xff, STM32_RTC_WPR);
+}
+
+/****************************************************************************
+ * Name: rtc_synchwait
+ *
+ * Description:
+ *   Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
+ *   synchronized with RTC APB clock.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int rtc_synchwait(void)
+{
+  volatile uint32_t timeout;
+  uint32_t regval;
+  int ret;
+
+  /* Disable the write protection for RTC registers */
+
+  rtc_wprunlock();
+
+  /* Clear Registers synchronization flag (RSF) */
+
+  regval  = getreg32(STM32_RTC_ICSR);
+  regval &= ~RTC_ICSR_RSF;
+  putreg32(regval, STM32_RTC_ICSR);
+
+  /* Now wait the registers to become synchronised */
+
+  ret = -ETIMEDOUT;
+  for (timeout = 0; timeout < SYNCHRO_TIMEOUT; timeout++)
+    {
+      regval = getreg32(STM32_RTC_ICSR);
+      if ((regval & RTC_ICSR_RSF) != 0)
+        {
+          /* Synchronized */
+
+          ret = OK;
+          break;
+        }
+    }
+
+  /* Re-enable the write protection for RTC registers */
+
+  rtc_wprlock();
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rtc_enterinit
+ *
+ * Description:
+ *   Enter RTC initialization mode.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int rtc_enterinit(void)
+{
+  volatile uint32_t timeout;
+  uint32_t regval;
+  int ret;
+
+  /* Check if the Initialization mode is already set */
+
+  regval = getreg32(STM32_RTC_ICSR);
+
+  ret = OK;
+  if ((regval & RTC_ICSR_INITF) == 0)
+    {
+      /* Set the Initialization mode */
+
+      putreg32(RTC_ICSR_INIT, STM32_RTC_ICSR);
+
+      /* Wait until the RTC is in the INIT state (or a timeout occurs) */
+
+      ret = -ETIMEDOUT;
+      for (timeout = 0; timeout < INITMODE_TIMEOUT; timeout++)
+        {
+          regval = getreg32(STM32_RTC_ICSR);
+          if ((regval & RTC_ICSR_INITF) != 0)
+            {
+              ret = OK;
+              break;
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rtc_exitinit
+ *
+ * Description:
+ *   Exit RTC initialization mode.
+ *
+ ****************************************************************************/
+
+static void rtc_exitinit(void)
+{
+  uint32_t regval;
+
+  regval  = getreg32(STM32_RTC_ICSR);
+  regval &= ~RTC_ICSR_INIT;
+  putreg32(regval, STM32_RTC_ICSR);
+}
+
+/****************************************************************************
+ * Name: rtc_bin2bcd
+ *
+ * Description:
+ *   Converts a 2 digit binary to BCD format
+ *
+ ****************************************************************************/
+
+static uint32_t rtc_bin2bcd(int value)
+{
+  uint32_t msbcd = 0;
+
+  while (value >= 10)
+    {
+      msbcd++;
+      value -= 10;
+    }
+
+  return (msbcd << 4) | value;
+}
+
+/****************************************************************************
+ * Name: rtc_bcd2bin
+ *
+ * Description:
+ *   Convert from 2 digit BCD to binary.
+ *
+ ****************************************************************************/
+
+static int rtc_bcd2bin(uint32_t value)
+{
+  uint32_t tens = (value >> 4) * 10;
+
+  return (int)(tens + (value & 0x0f));
+}
+
+/****************************************************************************
+ * Name: rtc_setup
+ *
+ * Description:
+ *   Performs first time configuration of the RTC.  A special value written
+ *   into the magic backup register will prevent this function from being
+ *   called on sub-sequent resets or power up.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int rtc_setup(void)
+{
+  uint32_t regval;
+  int ret;
+
+  /* Disable the write protection for RTC registers */
+
+  rtc_wprunlock();
+
+  /* Set Initialization mode */
+
+  ret = rtc_enterinit();
+  if (ret == OK)
+    {
+      /* Set the 24 hour format by clearing the FMT bit in the RTC
+       * control register
+       */
+
+      regval  = getreg32(STM32_RTC_CR);
+      regval &= ~RTC_CR_FMT;
+      putreg32(regval, STM32_RTC_CR);
+
+      /* Configure RTC pre-scaler with the required values */
+
+#ifdef CONFIG_STM32_RTC_HSECLOCK
+      /* STMicro app note AN4759 suggests using 7999 and 124 to
+       * get exactly 1Hz when using the RTC at 1MHz.
+       */
+
+      putreg32(((uint32_t)7999 << RTC_PRER_PREDIV_S_SHIFT) |
+               ((uint32_t)124 << RTC_PRER_PREDIV_A_SHIFT),
+               STM32_RTC_PRER);
+#else
+      /* Correct values for 32.768 KHz LSE clock and inaccurate LSI clock */
+
+      putreg32(((uint32_t)0xff << RTC_PRER_PREDIV_S_SHIFT) |
+               ((uint32_t)0x7f << RTC_PRER_PREDIV_A_SHIFT),
+               STM32_RTC_PRER);
+#endif
+
+      /* Exit RTC initialization mode */
+
+      rtc_exitinit();
+    }
+
+  /* Re-enable the write protection for RTC registers */
+
+  rtc_wprlock();
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: rtc_resume
+ *
+ * Description:
+ *   Called when the RTC was already initialized on a previous power cycle.
+ *   This just brings the RTC back into full operation.
+ *
+ ****************************************************************************/
+
+static void rtc_resume(void)
+{
+  /* Clear the RTC alarm and wakeup flags */
+
+  putreg32(RTC_SCR_ALLF, STM32_RTC_SCR);
+}
+
+/****************************************************************************
+ * Name: stm32_rtc_interrupt
+ *
+ * Description:
+ *   RTC interrupt service routine.  Alarm A, Alarm B and the periodic
+ *   wakeup share one NVIC line.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_RTC_ALARM) || defined(CONFIG_RTC_PERIODIC)
+static int stm32_rtc_interrupt(int irq, void *context, void *arg)
+{
+#ifdef CONFIG_RTC_ALARM
+  struct alm_cbinfo_s *cbinfo;
+  alm_callback_t cb;
+  void *cb_arg;
+#endif
+  uint32_t misr;
+
+  misr = getreg32(STM32_RTC_MISR);
+
+  /* Clear the flags first.  RTC_SCR is not protected by RTC_WPR. */
+
+  putreg32(misr & RTC_SCR_ALLF, STM32_RTC_SCR);
+
+#ifdef CONFIG_RTC_ALARM
+  if ((misr & RTC_MISR_ALRAMF) != 0)
+    {
+      cbinfo = &g_alarmcb[RTC_ALARMA];
+      if (cbinfo->ac_cb != NULL)
+        {
+          /* Alarm A callback */
+
+          cb     = cbinfo->ac_cb;
+          cb_arg = (void *)cbinfo->ac_arg;
+
+          cbinfo->ac_cb  = NULL;
+          cbinfo->ac_arg = NULL;
+
+          cb(cb_arg, RTC_ALARMA);
+        }
+    }
+
+#if CONFIG_RTC_NALARMS > 1
+  if ((misr & RTC_MISR_ALRBMF) != 0)
+    {
+      cbinfo = &g_alarmcb[RTC_ALARMB];
+      if (cbinfo->ac_cb != NULL)
+        {
+          /* Alarm B callback */
+
+          cb     = cbinfo->ac_cb;
+          cb_arg = (void *)cbinfo->ac_arg;
+
+          cbinfo->ac_cb  = NULL;
+          cbinfo->ac_arg = NULL;
+
+          cb(cb_arg, RTC_ALARMB);
+        }
+    }
+#endif
+#endif /* CONFIG_RTC_ALARM */
+
+#ifdef CONFIG_RTC_PERIODIC
+  if ((misr & RTC_MISR_WUTMF) != 0 && g_wakeupcb != NULL)
+    {
+      g_wakeupcb();
+    }
+#endif
+
+  return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: rtc_enable_irq
+ *
+ * Description:
+ *   Attach and enable the RTC interrupt.  Unlike the older RTC versions
+ *   the alarm and wakeup events do not go through the EXTI controller.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_RTC_ALARM) || defined(CONFIG_RTC_PERIODIC)
+static void rtc_enable_irq(void)
+{
+  if (!g_rtc_irq_enabled)
+    {
+      irq_attach(STM32_IRQ_RTC, stm32_rtc_interrupt, NULL);
+      up_enable_irq(STM32_IRQ_RTC);
+      g_rtc_irq_enabled = true;
+    }
+}
+#endif
+
+/****************************************************************************
+ * Name: rtchw_set_alrmXr X is a or b
+ *
+ * Description:
+ *   Set the alarm (A or B) hardware registers.  On this RTC version the
+ *   alarm registers may be written as soon as the alarm is disabled.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+static int rtchw_set_alrmar(rtc_alarmreg_t alarmreg)
+{
+  /* Disable the write protection for RTC registers */
+
+  rtc_wprunlock();
+
+  /* Disable RTC alarm & Interrupt */
+
+  modifyreg32(STM32_RTC_CR, (RTC_CR_ALRAE | RTC_CR_ALRAIE), 0);
+
+  /* Set the RTC Alarm register and clear a pending flag */
+
+  putreg32(alarmreg, STM32_RTC_ALRMAR);
+  putreg32(0, STM32_RTC_ALRMASSR);
+  putreg32(RTC_SCR_CALRAF, STM32_RTC_SCR);
+  rtcinfo("  ALRMAR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMAR));
+
+  /* Enable RTC alarm */
+
+  modifyreg32(STM32_RTC_CR, 0, (RTC_CR_ALRAE | RTC_CR_ALRAIE));
+
+  rtc_wprlock();
+  return OK;
+}
+#endif
+
+#if defined(CONFIG_RTC_ALARM) && CONFIG_RTC_NALARMS > 1
+static int rtchw_set_alrmbr(rtc_alarmreg_t alarmreg)
+{
+  /* Disable the write protection for RTC registers */
+
+  rtc_wprunlock();
+
+  /* Disable RTC alarm B & Interrupt B */
+
+  modifyreg32(STM32_RTC_CR, (RTC_CR_ALRBE | RTC_CR_ALRBIE), 0);
+
+  /* Set the RTC Alarm register and clear a pending flag */
+
+  putreg32(alarmreg, STM32_RTC_ALRMBR);
+  putreg32(0, STM32_RTC_ALRMBSSR);
+  putreg32(RTC_SCR_CALRBF, STM32_RTC_SCR);
+  rtcinfo("  ALRMBR: %08" PRIx32 "\n", getreg32(STM32_RTC_ALRMBR));
+
+  /* Enable RTC alarm B */
+
+  modifyreg32(STM32_RTC_CR, 0, (RTC_CR_ALRBE | RTC_CR_ALRBIE));
+
+  rtc_wprlock();
+  return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_getalarmdatetime
+ *
+ * Description:
+ *   Get the current date and time for a RTC alarm.
+ *
+ * Input Parameters:
+ *   reg - RTC alarm register
+ *   tp - The location to return the high resolution time value.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+static int stm32_rtc_getalarmdatetime(rtc_alarmreg_t reg, struct tm *tp)
+{
+  uint32_t data;
+  uint32_t tmp;
+
+  DEBUGASSERT(tp != NULL);
+
+  /* Sample the data time register. */
+
+  data = getreg32(reg);
+
+  /* Convert the RTC time to fields in struct tm format.  All of the STM32
+   * ranges of values correspond between struct tm and the time register.
+   */
+
+  tmp = (data & (RTC_ALRMR_SU_MASK | RTC_ALRMR_ST_MASK)) >>
+        RTC_ALRMR_SU_SHIFT;
+  tp->tm_sec = rtc_bcd2bin(tmp);
+
+  tmp = (data & (RTC_ALRMR_MNU_MASK | RTC_ALRMR_MNT_MASK)) >>
+        RTC_ALRMR_MNU_SHIFT;
+  tp->tm_min = rtc_bcd2bin(tmp);
+
+  tmp = (data & (RTC_ALRMR_HU_MASK | RTC_ALRMR_HT_MASK)) >>
+        RTC_ALRMR_HU_SHIFT;
+  tp->tm_hour = rtc_bcd2bin(tmp);
+
+  tmp = (data & (RTC_ALRMR_DU_MASK | RTC_ALRMR_DT_MASK)) >>
+        RTC_ALRMR_DU_SHIFT;
+  tp->tm_mday = rtc_bcd2bin(tmp);
+
+  return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: rtc_selectclock
+ *
+ * Description:
+ *   Enable the selected RTC clock source and route it to the RTC.  The
+ *   backup domain must be writable.
+ *
+ ****************************************************************************/
+
+static void rtc_selectclock(void)
+{
+#if defined(CONFIG_STM32_RTC_HSECLOCK)
+  /* Divide the HSE down to 1 MHz */
+
+  modifyreg32(STM32_RCC_CCIPR7, RCC_CCIPR7_RTCPRE_MASK,
+              (STM32_HSE_FREQUENCY / RTC_HSE_FREQUENCY - 1) <<
+              RCC_CCIPR7_RTCPRE_SHIFT);
+#elif defined(CONFIG_STM32_RTC_LSICLOCK)
+  stm32_rcc_enablelsi();
+#else
+  stm32_rcc_enablelse();
+#endif
+
+  modifyreg32(STM32_RCC_RTCSELR, RCC_RTCSELR_RTCSEL_MASK,
+              RCC_RTCSELR_RTCSEL);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_rtc_initialize
+ *
+ * Description:
+ *   Initialize the hardware RTC per the selected configuration.  This
+ *   function is called once during the OS initialization sequence
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+int up_rtc_initialize(void)
+{
+  uint32_t regval;
+  int ret;
+  int maxretry = 10;
+  int nretry = 0;
+
+  /* Enable write access to the backup domain for good, then the RTC
+   * clocks so that the RTC and TAMP registers can be accessed.
+   */
+
+  stm32_pwr_enablebkp(true);
+  modifyreg32(STM32_RCC_RTCENR, 0, RCC_RTCENR_RTCEN);
+
+  /* Save the token before losing it when resetting */
+
+  regval = getreg32(RTC_MAGIC_REG);
+
+  if (regval != RTC_MAGIC && regval != RTC_MAGIC_TIME_SET)
+    {
+      /* First start: select the clock source */
+
+      rtc_dumpregs("On reset");
+      rtc_selectclock();
+    }
+  else
+    {
+      rtc_dumpregs("On reset warm");
+
+      /* The clock selection is reset with the system, only the RTC itself
+       * keeps running.  Route the configured clock to it again.
+       */
+
+      rtc_selectclock();
+    }
+
+  /* Loop, attempting to initialize/resume the RTC.  This loop is necessary
+   * because it seems that occasionally it takes longer to initialize the RTC
+   * (the actual failure is in rtc_synchwait()).
+   */
+
+  do
+    {
+      /* Wait for the RTC Time and Date registers to be synchronized with RTC
+       * APB clock.
+       */
+
+      ret = rtc_synchwait();
+      if (ret != OK)
+        {
+          rtcerr("ERROR: rtc_syncwait() failed (%d)\n", ret);
+        }
+    }
+  while (ret != OK && ++nretry < maxretry);
+
+  /* Check if the one-time initialization of the RTC has already been
+   * performed. We can determine this by checking if the magic number
+   * has been written to the magic backup register.
+   */
+
+  if (regval != RTC_MAGIC && regval != RTC_MAGIC_TIME_SET)
+    {
+      rtcinfo("Do setup\n");
+
+      /* Perform the one-time setup of the clocking to the RTC */
+
+      ret = rtc_setup();
+
+      /* Remember that the RTC is initialized */
+
+      putreg32(RTC_MAGIC, RTC_MAGIC_REG);
+    }
+  else
+    {
+      rtcinfo("Do resume\n");
+
+      /* RTC already set-up, just resume normal operation */
+
+      rtc_resume();
+      rtc_dumpregs("Did resume");
+    }
+
+  if (ret != OK && nretry > 0)
+    {
+      rtcinfo("setup/resume ran %d times and failed with %d\n",
+              nretry, ret);
+      return -ETIMEDOUT;
+    }
+
+  rtc_dumpregs("After Initialization");
+
+  g_rtc_enabled = true;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_rtc_irqinitialize
+ *
+ * Description:
+ *   Initialize IRQs for RTC, not possible during up_rtc_initialize because
+ *   up_irqinitialize is called later.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+int stm32_rtc_irqinitialize(void)
+{
+  /* Nothing to do, the interrupt is attached on the first use. */
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: stm32_rtc_getdatetime_with_subseconds
+ *
+ * Description:
+ *   Get the current date and time from the date/time RTC.  This interface
+ *   is only supported by the date/time RTC hardware implementation.
+ *   It is used to replace the system timer.  It is only used by the RTOS
+ *   during initialization to set up the system time when CONFIG_RTC and
+ *   CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
+ *
+ *   NOTE: Some date/time RTC hardware is capability of sub-second accuracy.
+ *   That sub-second accuracy is returned through 'nsec'.
+ *
+ * Input Parameters:
+ *   tp - The location to return the high resolution time value.
+ *   nsec - The location to return the subsecond time value.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+int stm32_rtc_getdatetime_with_subseconds(struct tm *tp, long *nsec)
+#else
+int up_rtc_getdatetime(struct tm *tp)
+#endif
+{
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+  uint32_t ssr;
+#endif
+  uint32_t dr;
+  uint32_t tr;
+  uint32_t tmp;
+
+  /* Sample the data time registers.  There is a race condition here... If
+   * we sample the time just before midnight on December 31, the date could
+   * be wrong because the day rolled over while were sampling. Thus loop for
+   * checking overflow here is needed.  There is a race condition with
+   * subseconds too. If we sample TR register just before second rolling
+   * and subseconds are read at wrong second, we get wrong time.
+   */
+
+  do
+    {
+      dr  = getreg32(STM32_RTC_DR);
+      tr  = getreg32(STM32_RTC_TR);
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+      ssr = getreg32(STM32_RTC_SSR);
+      tmp = getreg32(STM32_RTC_TR);
+      if (tmp != tr)
+        {
+          continue;
+        }
+#endif
+
+      tmp = getreg32(STM32_RTC_DR);
+      if (tmp == dr)
+        {
+          break;
+        }
+    }
+  while (1);
+
+  rtc_dumpregs("Reading Time");
+
+  /* Convert the RTC time to fields in struct tm format.  All of the STM32
+   * ranges of values correspond between struct tm and the time register.
+   */
+
+  tmp = (tr & (RTC_TR_SU_MASK | RTC_TR_ST_MASK)) >> RTC_TR_SU_SHIFT;
+  tp->tm_sec = rtc_bcd2bin(tmp);
+
+  tmp = (tr & (RTC_TR_MNU_MASK | RTC_TR_MNT_MASK)) >> RTC_TR_MNU_SHIFT;
+  tp->tm_min = rtc_bcd2bin(tmp);
+
+  tmp = (tr & (RTC_TR_HU_MASK | RTC_TR_HT_MASK)) >> RTC_TR_HU_SHIFT;
+  tp->tm_hour = rtc_bcd2bin(tmp);
+
+  /* Now convert the RTC date to fields in struct tm format:
+   * Days: 1-31 match in both cases.
+   * Month: STM32 is 1-12, struct tm is 0-11.
+   * Years: STM32 is 00-99 (2000-2099), struct tm is years since 1900.
+   * WeekDay: STM32 is 1 = Mon - 7 = Sun
+   */
+
+  tmp = (dr & (RTC_DR_DU_MASK | RTC_DR_DT_MASK)) >> RTC_DR_DU_SHIFT;
+  tp->tm_mday = rtc_bcd2bin(tmp);
+
+  tmp = (dr & (RTC_DR_MU_MASK | RTC_DR_MT)) >> RTC_DR_MU_SHIFT;
+  tp->tm_mon = rtc_bcd2bin(tmp) - 1;
+
+  tmp = (dr & (RTC_DR_YU_MASK | RTC_DR_YT_MASK)) >> RTC_DR_YU_SHIFT;
+  tp->tm_year = rtc_bcd2bin(tmp) + 100;
+
+  tmp = (dr & RTC_DR_WDU_MASK) >> RTC_DR_WDU_SHIFT;
+  tp->tm_wday = tmp % 7;
+  tp->tm_yday = tp->tm_mday - 1 +
+                clock_daysbeforemonth(tp->tm_mon,
+                                      clock_isleapyear(tp->tm_year + 1900));
+  tp->tm_isdst = 0;
+
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+  /* Return RTC sub-seconds if a non-NULL value of nsec has been provided
+   * to receive the sub-second value.
+   */
+
+  if (nsec)
+    {
+      uint32_t prediv_s;
+      uint32_t usecs;
+
+      prediv_s   = getreg32(STM32_RTC_PRER) & RTC_PRER_PREDIV_S_MASK;
+      prediv_s >>= RTC_PRER_PREDIV_S_SHIFT;
+
+      ssr &= RTC_SSR_BCD_MASK;
+
+      /* Maximum prediv_s is 0x7fff, thus we can multiply by 100000 and
+       * still fit 32-bit unsigned integer.
+       */
+
+      usecs = (((prediv_s - ssr) * 100000) / (prediv_s + 1)) * 10;
+      *nsec = usecs * 1000;
+    }
+#endif /* CONFIG_STM32_HAVE_RTC_SUBSECONDS */
+
+  rtc_dumptime((const struct tm *)tp, "Returning");
+  return OK;
+}
+
+/****************************************************************************
+ * Name: up_rtc_getdatetime
+ *
+ * Description:
+ *   Get the current date and time from the date/time RTC.
+ *
+ * Input Parameters:
+ *   tp - The location to return the high resolution time value.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
+int up_rtc_getdatetime(struct tm *tp)
+{
+  return stm32_rtc_getdatetime_with_subseconds(tp, NULL);
+}
+#endif
+
+/****************************************************************************
+ * Name: up_rtc_getdatetime_with_subseconds
+ *
+ * Description:
+ *   Get the current date and time from the date/time RTC with sub-second
+ *   accuracy.
+ *
+ * Input Parameters:
+ *   tp - The location to return the high resolution time value.
+ *   nsec - The location to return the subsecond time value.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_HAVE_RTC_SUBSECONDS
+int up_rtc_getdatetime_with_subseconds(struct tm *tp, long *nsec)
+{
+  return stm32_rtc_getdatetime_with_subseconds(tp, nsec);
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_setdatetime
+ *
+ * Description:
+ *   Set the RTC to the provided time. RTC implementations which provide
+ *   up_rtc_getdatetime() (CONFIG_RTC_DATETIME is selected) should provide
+ *   this function.
+ *
+ * Input Parameters:
+ *   tp - the time to use
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+int stm32_rtc_setdatetime(const struct tm *tp)
+{
+  uint32_t tr;
+  uint32_t dr;
+  int ret;
+
+  rtc_dumptime(tp, "Setting time");
+
+  /* Convert the struct tm format to RTC time register fields.
+   * All of the ranges of values correspond between struct tm and the time
+   * register.
+   */
+
+  tr = (rtc_bin2bcd(tp->tm_sec)  << RTC_TR_SU_SHIFT) |
+       (rtc_bin2bcd(tp->tm_min)  << RTC_TR_MNU_SHIFT) |
+       (rtc_bin2bcd(tp->tm_hour) << RTC_TR_HU_SHIFT);
+
+  /* Now convert the fields in struct tm format to the RTC date register
+   * fields:
+   *
+   *   Days: 1-31 match in both cases.
+   *   Month: STM32 is 1-12, struct tm is 0-11.
+   *   Years: STM32 is 00-99, struct tm is years since 1900.
+   *   WeekDay: STM32 is 1 = Mon - 7 = Sun
+   */
+
+  dr = (rtc_bin2bcd(tp->tm_mday) << RTC_DR_DU_SHIFT) |
+       ((rtc_bin2bcd(tp->tm_mon + 1))  << RTC_DR_MU_SHIFT) |
+       ((tp->tm_wday == 0 ? 7 : (tp->tm_wday & 7))  << RTC_DR_WDU_SHIFT) |
+       ((rtc_bin2bcd(tp->tm_year - 100)) << RTC_DR_YU_SHIFT);
+
+  dr &= ~RTC_DR_RESERVED_BITS;
+
+  /* Disable the write protection for RTC registers */
+
+  rtc_wprunlock();
+
+  /* Set Initialization mode */
+
+  ret = rtc_enterinit();
+  if (ret == OK)
+    {
+      /* Set the RTC TR and DR registers */
+
+      putreg32(tr, STM32_RTC_TR);
+      putreg32(dr, STM32_RTC_DR);
+
+      /* Exit Initialization mode and wait for the RTC Time and Date
+       * registers to be synchronized with RTC APB clock.
+       */
+
+      rtc_exitinit();
+      ret = rtc_synchwait();
+    }
+
+  /* Remember that the RTC is initialized and had its time set. */
+
+  if (getreg32(RTC_MAGIC_REG) != RTC_MAGIC_TIME_SET)
+    {
+      putreg32(RTC_MAGIC_TIME_SET, RTC_MAGIC_REG);
+    }
+
+  /* Re-enable the write protection for RTC registers */
+
+  rtc_wprlock();
+  rtc_dumpregs("New time setting");
+  return ret;
+}
+
+/****************************************************************************
+ * Name: up_rtc_settime
+ *
+ * Description:
+ *   Set the RTC to the provided time.  All RTC implementations must be able
+ *   to set their time based on a standard timespec.
+ *
+ * Input Parameters:
+ *   tp - the time to use
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+int up_rtc_settime(const struct timespec *tp)
+{
+  struct tm newtime;
+
+  /* Break out the time values (not that the time is set only to units of
+   * seconds)
+   */
+
+  gmtime_r(&tp->tv_sec, &newtime);
+  return stm32_rtc_setdatetime(&newtime);
+}
+
+/****************************************************************************
+ * Name: stm32_rtc_setalarm
+ *
+ * Description:
+ *   Set an alarm to an absolute time using associated hardware.
+ *
+ * Input Parameters:
+ *  alminfo - Information about the alarm configuration.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+int stm32_rtc_setalarm(struct alm_setalarm_s *alminfo)
+{
+  struct alm_cbinfo_s *cbinfo;
+  rtc_alarmreg_t alarmreg;
+  int ret = -EINVAL;
+
+  DEBUGASSERT(alminfo != NULL);
+  DEBUGASSERT(RTC_ALARM_LAST > alminfo->as_id);
+
+  /* Make sure the RTC interrupt is enabled at the NVIC */
+
+  rtc_enable_irq();
+
+  rtc_dumptime(&alminfo->as_time, "New alarm time");
+
+  /* Break out the values to the HW alarm register format.  The values in
+   * all STM32 fields match the fields of struct tm in this case.  Notice
+   * that the alarm is limited to one month.
+   */
+
+  alarmreg = (rtc_bin2bcd(alminfo->as_time.tm_sec)  << RTC_ALRMR_SU_SHIFT) |
+             (rtc_bin2bcd(alminfo->as_time.tm_min)  << RTC_ALRMR_MNU_SHIFT) |
+             (rtc_bin2bcd(alminfo->as_time.tm_hour) << RTC_ALRMR_HU_SHIFT) |
+             (rtc_bin2bcd(alminfo->as_time.tm_mday) << RTC_ALRMR_DU_SHIFT);
+
+  /* Set the alarm in hardware and enable interrupts from the RTC */
+
+  switch (alminfo->as_id)
+    {
+      case RTC_ALARMA:
+        {
+          cbinfo         = &g_alarmcb[RTC_ALARMA];
+          cbinfo->ac_cb  = alminfo->as_cb;
+          cbinfo->ac_arg = alminfo->as_arg;
+
+          ret = rtchw_set_alrmar(alarmreg | RTC_ALRMR_ENABLE);
+          if (ret < 0)
+            {
+              cbinfo->ac_cb  = NULL;
+              cbinfo->ac_arg = NULL;
+            }
+
+          rtc_dumpregs("Set AlarmA");
+        }
+        break;
+
+#if CONFIG_RTC_NALARMS > 1
+      case RTC_ALARMB:
+        {
+          cbinfo         = &g_alarmcb[RTC_ALARMB];
+          cbinfo->ac_cb  = alminfo->as_cb;
+          cbinfo->ac_arg = alminfo->as_arg;
+
+          ret = rtchw_set_alrmbr(alarmreg | RTC_ALRMR_ENABLE);
+          if (ret < 0)
+            {
+              cbinfo->ac_cb  = NULL;
+              cbinfo->ac_arg = NULL;
+            }
+
+          rtc_dumpregs("Set AlarmB");
+        }
+        break;
+#endif
+
+      default:
+        rtcerr("ERROR: Invalid ALARM%d\n", alminfo->as_id);
+        break;
+    }
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_cancelalarm
+ *
+ * Description:
+ *   Cancel an alarm.
+ *
+ * Input Parameters:
+ *  alarmid - Identifies the alarm to be cancelled
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+int stm32_rtc_cancelalarm(enum alm_id_e alarmid)
+{
+  int ret = -EINVAL;
+
+  DEBUGASSERT(RTC_ALARM_LAST > alarmid);
+
+  /* Cancel the alarm in hardware and disable interrupts */
+
+  switch (alarmid)
+    {
+      case RTC_ALARMA:
+        {
+          /* Cancel the global callback function */
+
+          g_alarmcb[alarmid].ac_cb  = NULL;
+          g_alarmcb[alarmid].ac_arg = NULL;
+
+          /* Disable RTC alarm and interrupt, then unset the alarm */
+
+          rtc_wprunlock();
+          modifyreg32(STM32_RTC_CR, (RTC_CR_ALRAE | RTC_CR_ALRAIE), 0);
+          putreg32(-1, STM32_RTC_ALRMAR);
+          putreg32(RTC_SCR_CALRAF, STM32_RTC_SCR);
+          rtc_wprlock();
+          ret = OK;
+        }
+        break;
+
+#if CONFIG_RTC_NALARMS > 1
+      case RTC_ALARMB:
+        {
+          /* Cancel the global callback function */
+
+          g_alarmcb[alarmid].ac_cb  = NULL;
+          g_alarmcb[alarmid].ac_arg = NULL;
+
+          /* Disable RTC alarm and interrupt, then unset the alarm */
+
+          rtc_wprunlock();
+          modifyreg32(STM32_RTC_CR, (RTC_CR_ALRBE | RTC_CR_ALRBIE), 0);
+          putreg32(-1, STM32_RTC_ALRMBR);
+          putreg32(RTC_SCR_CALRBF, STM32_RTC_SCR);
+          rtc_wprlock();
+          ret = OK;
+        }
+        break;
+#endif
+
+      default:
+        rtcerr("ERROR: Invalid ALARM%d\n", alarmid);
+        break;
+    }
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_rdalarm
+ *
+ * Description:
+ *   Query an alarm configured in hardware.
+ *
+ * Input Parameters:
+ *  alminfo - Information about the alarm configuration.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_ALARM
+int stm32_rtc_rdalarm(struct alm_rdalarm_s *alminfo)
+{
+  int ret = -EINVAL;
+
+  DEBUGASSERT(alminfo != NULL);
+  DEBUGASSERT(RTC_ALARM_LAST > alminfo->ar_id);
+
+  switch (alminfo->ar_id)
+    {
+      case RTC_ALARMA:
+        ret = stm32_rtc_getalarmdatetime(STM32_RTC_ALRMAR,
+                                         (struct tm *)alminfo->ar_time);
+        break;
+
+#if CONFIG_RTC_NALARMS > 1
+      case RTC_ALARMB:
+        ret = stm32_rtc_getalarmdatetime(STM32_RTC_ALRMBR,
+                                         (struct tm *)alminfo->ar_time);
+        break;
+#endif
+
+      default:
+        rtcerr("ERROR: Invalid ALARM%d\n", alminfo->ar_id);
+        break;
+    }
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_setperiodic
+ *
+ * Description:
+ *   Set a periodic RTC wakeup
+ *
+ * Input Parameters:
+ *  period   - Time to sleep between wakeups
+ *  callback - Function to call when the period expires.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_PERIODIC
+int stm32_rtc_setperiodic(const struct timespec *period,
+                          wakeupcb_t callback)
+{
+  volatile uint32_t timeout;
+  uint64_t ticks;
+  uint32_t wut;
+  uint32_t wucksel;
+  int ret = -ETIMEDOUT;
+
+  DEBUGASSERT(period != NULL);
+
+  if (period->tv_sec == 0 && period->tv_nsec == 0)
+    {
+      return -EINVAL;
+    }
+
+  /* Up to 2^16 ticks of RTCCLK/16 (32 s with the LSE) the wakeup timer
+   * counts RTCCLK/16, longer periods count ck_spre (1 Hz): up to 2^17
+   * seconds.
+   */
+
+  ticks = ((uint64_t)period->tv_sec * NSEC_PER_SEC + period->tv_nsec) *
+          (RTC_CLK_FREQUENCY / 16) / NSEC_PER_SEC;
+
+  if (ticks <= 0x10000)
+    {
+      wucksel = RTC_CR_WUCKSEL_RTCDIV16;
+      wut     = ticks > 0 ? ticks : 1;
+    }
+  else
+    {
+      wut = period->tv_sec;
+      if (period->tv_nsec > 0)
+        {
+          wut++;
+        }
+
+      if (wut > 0x20000)
+        {
+          return -EINVAL;
+        }
+
+      if (wut > 0x10000)
+        {
+          wucksel = RTC_CR_WUCKSEL_CKSPREADD;
+          wut    -= 0x10000;
+        }
+      else
+        {
+          wucksel = RTC_CR_WUCKSEL_CKSPRE;
+        }
+    }
+
+  rtc_enable_irq();
+
+  g_wakeupcb = callback;
+
+  rtc_wprunlock();
+
+  /* Disable the wakeup timer and wait until it can be reprogrammed */
+
+  modifyreg32(STM32_RTC_CR, RTC_CR_WUTE | RTC_CR_WUTIE, 0);
+
+  for (timeout = 0; timeout < INITMODE_TIMEOUT; timeout++)
+    {
+      if ((getreg32(STM32_RTC_ICSR) & RTC_ICSR_WUTWF) != 0)
+        {
+          ret = OK;
+          break;
+        }
+    }
+
+  if (ret == OK)
+    {
+      putreg32((wut - 1) & RTC_WUTR_WUT_MASK, STM32_RTC_WUTR);
+      putreg32(RTC_SCR_CWUTF, STM32_RTC_SCR);
+      modifyreg32(STM32_RTC_CR, RTC_CR_WUCKSEL_MASK,
+                  wucksel | RTC_CR_WUTE | RTC_CR_WUTIE);
+    }
+  else
+    {
+      g_wakeupcb = NULL;
+    }
+
+  rtc_wprlock();
+  rtc_dumpregs("Set periodic");
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: stm32_rtc_cancelperiodic
+ *
+ * Description:
+ *   Cancel the periodic RTC wakeup
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_RTC_PERIODIC
+int stm32_rtc_cancelperiodic(void)
+{
+  g_wakeupcb = NULL;
+
+  rtc_wprunlock();
+  modifyreg32(STM32_RTC_CR, RTC_CR_WUTE | RTC_CR_WUTIE, 0);
+  putreg32(RTC_SCR_CWUTF, STM32_RTC_SCR);
+  rtc_wprlock();
+
+  return OK;
+}
+#endif
+
+#endif /* CONFIG_STM32_RTC */
diff --git a/arch/arm/src/stm32n6/Kconfig b/arch/arm/src/stm32n6/Kconfig
index 6ecf44bd06c..c1cbf50847f 100644
--- a/arch/arm/src/stm32n6/Kconfig
+++ b/arch/arm/src/stm32n6/Kconfig
@@ -17,6 +17,7 @@ config STM32_N6_PERIPHERALS
        select STM32_HAVE_IP_DBGMCU_V8
        select STM32_HAVE_IP_LPTIM_V2
        select STM32_HAVE_IP_RNG_V1
+       select STM32_HAVE_IP_RTCC_M33M55_V1
        select STM32_HAVE_IP_WDG_V3
        select STM32_HAVE_DMA1
        select STM32_HAVE_DMA2
@@ -26,6 +27,9 @@ config STM32_N6_PERIPHERALS
        select STM32_HAVE_LPTIM4
        select STM32_HAVE_LPTIM5
        select STM32_HAVE_RNG
+       select STM32_HAVE_RTC
+       select STM32_HAVE_RTC_MAGIC
+       select STM32_HAVE_RTC_SUBSECONDS
        select STM32_HAVE_TIM1
        select STM32_HAVE_TIM2
        select STM32_HAVE_TIM3
diff --git a/arch/arm/src/stm32n6/stm32_rcc.h b/arch/arm/src/stm32n6/stm32_rcc.h
index 3b9f26503ca..2c46cae853c 100644
--- a/arch/arm/src/stm32n6/stm32_rcc.h
+++ b/arch/arm/src/stm32n6/stm32_rcc.h
@@ -108,6 +108,26 @@ void stm32_clockenable(void);
 
 void stm32_rcc_enableperipherals(void);
 
+/****************************************************************************
+ * Name: stm32_rcc_enablelse
+ *
+ * Description:
+ *   Enable the External Low-Speed (LSE) oscillator.
+ *
+ ****************************************************************************/
+
+void stm32_rcc_enablelse(void);
+
+/****************************************************************************
+ * Name: stm32_rcc_enablelsi
+ *
+ * Description:
+ *   Enable the Internal Low-Speed (LSI) oscillator.
+ *
+ ****************************************************************************/
+
+void stm32_rcc_enablelsi(void);
+
 #if defined(__cplusplus)
 }
 #endif
diff --git a/arch/arm/src/stm32n6/stm32n6xx_rcc.c 
b/arch/arm/src/stm32n6/stm32n6xx_rcc.c
index d50c4d350a6..490b22de3a8 100644
--- a/arch/arm/src/stm32n6/stm32n6xx_rcc.c
+++ b/arch/arm/src/stm32n6/stm32n6xx_rcc.c
@@ -79,10 +79,11 @@
 
 /* Allow up to 100 milliseconds for a clock to become ready.  That is a
  * very long delay, but if the clock does not become ready we are hosed
- * anyway.
+ * anyway.  The LSE crystal may need up to a few seconds to start.
  */
 
 #define CLKRDY_TIMEOUT  (100 * CONFIG_BOARD_LOOPSPERMSEC)
+#define LSERDY_TIMEOUT  (3000 * CONFIG_BOARD_LOOPSPERMSEC)
 
 /* Defaults for optional board.h settings */
 
@@ -733,6 +734,59 @@ static void rcc_enableccip(void)
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: stm32_rcc_enablelse
+ *
+ * Description:
+ *   Enable the 32.768 kHz LSE oscillator.  The LSE lives in the backup
+ *   domain, so write access is enabled for the duration of the call.
+ *
+ ****************************************************************************/
+
+void stm32_rcc_enablelse(void)
+{
+  volatile int32_t timeout;
+  bool writable;
+
+  if ((getreg32(STM32_RCC_SR) & RCC_SR_LSERDY) != 0)
+    {
+      return;
+    }
+
+  writable = stm32_pwr_enablebkp(true);
+
+#ifdef CONFIG_STM32_RTC_LSECLOCK_START_DRV_CAPABILITY
+  modifyreg32(STM32_RCC_LSECFGR, RCC_LSECFGR_LSEDRV_MASK,
+              CONFIG_STM32_RTC_LSECLOCK_START_DRV_CAPABILITY <<
+              RCC_LSECFGR_LSEDRV_SHIFT);
+#endif
+
+  putreg32(RCC_CR_LSEON, STM32_RCC_CSR);
+  for (timeout = LSERDY_TIMEOUT; timeout > 0; timeout--)
+    {
+      if ((getreg32(STM32_RCC_SR) & RCC_SR_LSERDY) != 0)
+        {
+          break;
+        }
+    }
+
+  stm32_pwr_enablebkp(writable);
+}
+
+/****************************************************************************
+ * Name: stm32_rcc_enablelsi
+ *
+ * Description:
+ *   Enable the 32 kHz LSI oscillator.
+ *
+ ****************************************************************************/
+
+void stm32_rcc_enablelsi(void)
+{
+  putreg32(RCC_CR_LSION, STM32_RCC_CSR);
+  rcc_waitflag(STM32_RCC_SR, RCC_SR_LSIRDY, true);
+}
+
 /****************************************************************************
  * Name: stm32_rcc_enableperipherals
  ****************************************************************************/
diff --git a/boards/arm/stm32n6/stm32n6570-dk/configs/nsh/defconfig 
b/boards/arm/stm32n6/stm32n6570-dk/configs/nsh/defconfig
index ace85529dc3..a6c171057fc 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/configs/nsh/defconfig
+++ b/boards/arm/stm32n6/stm32n6570-dk/configs/nsh/defconfig
@@ -21,6 +21,7 @@ CONFIG_BOARD_LOOPSPERMSEC=84000
 CONFIG_BUILTIN=y
 CONFIG_DEBUG_FULLOPT=y
 CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXAMPLES_ALARM=y
 CONFIG_FS_PROCFS=y
 CONFIG_HAVE_CXX=y
 CONFIG_HAVE_CXXINITIALIZE=y
@@ -36,10 +37,16 @@ CONFIG_RAM_SIZE=2620416
 CONFIG_RAM_START=0x34180400
 CONFIG_RAW_BINARY=y
 CONFIG_RR_INTERVAL=200
+CONFIG_RTC_ALARM=y
+CONFIG_RTC_DATETIME=y
+CONFIG_RTC_DRIVER=y
+CONFIG_RTC_NALARMS=2
+CONFIG_RTC_PERIODIC=y
 CONFIG_SCHED_WAITPID=y
 CONFIG_STM32N6_DEBUG=y
 CONFIG_STM32_DMA1=y
 CONFIG_STM32_RNG=y
+CONFIG_STM32_RTC=y
 CONFIG_STM32_USART1=y
 CONFIG_SYSTEM_NSH=y
 CONFIG_USART1_SERIAL_CONSOLE=y
diff --git a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c 
b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
index b81fd84f858..d589047cb2c 100644
--- a/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
+++ b/boards/arm/stm32n6/stm32n6570-dk/src/stm32_bringup.c
@@ -34,7 +34,9 @@
 #include <nuttx/board.h>
 #include <nuttx/leds/userled.h>
 #include <nuttx/input/buttons.h>
+#include <nuttx/timers/rtc.h>
 
+#include "stm32_rtc.h"
 #include "stm32n6570-dk.h"
 
 #include <arch/board/board.h>
@@ -60,6 +62,7 @@
 int stm32_bringup(void)
 {
 #if defined(CONFIG_FS_PROCFS) || defined(CONFIG_INPUT_BUTTONS_LOWER) || \
+    (defined(CONFIG_RTC_DRIVER) && defined(CONFIG_STM32_RTC)) || \
     (!defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER))
   int ret;
 #endif
@@ -94,5 +97,15 @@ int stm32_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_RTC_DRIVER) && defined(CONFIG_STM32_RTC)
+  /* Register the RTC driver as /dev/rtc0 */
+
+  ret = rtc_initialize(0, stm32_rtc_lowerhalf());
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: rtc_initialize() failed: %d\n", ret);
+    }
+#endif
+
   return OK;
 }

Reply via email to