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 46805c0f921bc091e0fd2073c1428442446ea981
Author: raiden00pl <[email protected]>
AuthorDate: Mon Nov 9 14:53:36 2026 +0100

    arch/arm/stm32h5: Add RTC support.
    
    STM32H5 had no RTC driver.  Its RTC is the same IP as on STM32N6, so use
    the common M33/M55 RTC driver.
    
    - The driver gets the STM32H5 RCC glue: RTC kernel clock enable and
      source in BDCR, RTC APB clock in APB3ENR.
    - STM32H5 selects STM32_HAVE_IP_RTCC_M33M55_V1 and the RTC capabilities.
    - HSE as RTC clock is not supported on STM32H5 (build error).
    
    Tested on STM32H573I-DK.
    
    Assisted-by: Claude:claude-fable-5-1
    Signed-off-by: raiden00pl <[email protected]>
---
 Documentation/guides/chip-specific/stm32_ports.rst |  1 +
 Documentation/platforms/arm/stm32h5/index.rst      |  2 +-
 arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c   | 25 ++++++++++++++++++----
 arch/arm/src/stm32h5/Kconfig                       |  4 ++++
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/Documentation/guides/chip-specific/stm32_ports.rst 
b/Documentation/guides/chip-specific/stm32_ports.rst
index a6ddd595fa8..a5c9767479f 100644
--- a/Documentation/guides/chip-specific/stm32_ports.rst
+++ b/Documentation/guides/chip-specific/stm32_ports.rst
@@ -622,6 +622,7 @@ ICACHE        to be done    
arch/arm/src/stm32h5/stm32_icache.c
 OCTOSPI       to be done    arch/arm/src/stm32h5/stm32_qspi.c      
 PWR           to be done    arch/arm/src/stm32h5/stm32_pwr.c       
 RCC           to be done    arch/arm/src/stm32h5/stm32_rcc.c       
+RTC           M33M55 v1     arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
 SPI/I2S       to be done    arch/arm/src/stm32h5/stm32_spi.c       
 TIM           v3            arch/arm/src/common/stm32/stm32_tim.c  
 USART/LPUART  v3            arch/arm/src/stm32h5/stm32_serial.c    
diff --git a/Documentation/platforms/arm/stm32h5/index.rst 
b/Documentation/platforms/arm/stm32h5/index.rst
index c3a7021b5b4..190e561a8cf 100644
--- a/Documentation/platforms/arm/stm32h5/index.rst
+++ b/Documentation/platforms/arm/stm32h5/index.rst
@@ -74,7 +74,7 @@ RAMCFG      No
 SBS         No
 SDMMC       No
 RNG         No
-RTC         No
+RTC         Yes
 SAES        No
 SAI         No
 TAMP        No
diff --git a/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c 
b/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
index 7c19dd5051d..a5e61392a7a 100644
--- a/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
+++ b/arch/arm/src/common/stm32/stm32_rtcc_m33m55_v1.c
@@ -52,7 +52,7 @@
 
 /* Configuration ************************************************************/
 
-/* This RTC implementation supports the RTC of the STM32N6:
+/* This RTC implementation supports the RTC of the STM32N6 and STM32H5:
  *  - date/time RTC hardware with sub-seconds
  *  - Alarm A and Alarm B sharing one RTC interrupt with the wakeup timer
  *  - the periodic wakeup timer
@@ -77,18 +77,34 @@
 #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.
+/* RCC glue: the RTC kernel clock enable and source selection, and the RTC
+ * APB clock enable.
+ *
+ * STM32N6: all in APB4LENR and CCIPR7.  CCIPR7 is reset with the system,
+ * so the clock selection is not retained.
+ * STM32H5: kernel clock in the backup domain BDCR, APB clock in APB3ENR.
  */
 
 #if defined(RCC_APB4LENR_RTCEN)
 #  define STM32_RCC_RTCENR        STM32_RCC_APB4LENR
-#  define RCC_RTCENR_RTCEN        (RCC_APB4LENR_RTCEN | RCC_APB4LENR_RTCAPBEN)
+#  define RCC_RTCENR_RTCEN        RCC_APB4LENR_RTCEN
+#  define STM32_RCC_RTCAPBENR     STM32_RCC_APB4LENR
+#  define RCC_RTCAPBENR_RTCAPBEN  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
+#elif defined(RCC_BDCR_RTCEN)
+#  define STM32_RCC_RTCENR        STM32_RCC_BDCR
+#  define RCC_RTCENR_RTCEN        RCC_BDCR_RTCEN
+#  define STM32_RCC_RTCAPBENR     STM32_RCC_APB3ENR
+#  define RCC_RTCAPBENR_RTCAPBEN  RCC_APB3ENR_RTCAPBEN
+#  define STM32_RCC_RTCSELR       STM32_RCC_BDCR
+#  define RCC_RTCSELR_RTCSEL_MASK RCC_BDCR_RTCSEL_MASK
+#  define RCC_RTCSELR_RTCSEL_LSE  RCC_BDCR_RTCSEL_LSE
+#  define RCC_RTCSELR_RTCSEL_LSI  RCC_BDCR_RTCSEL_LSI
+#  define RCC_RTCSELR_RTCSEL_HSE  RCC_BDCR_RTCSEL_HSE
 #else
 #  error "Unknown RTC clock enable register"
 #endif
@@ -761,6 +777,7 @@ int up_rtc_initialize(void)
    */
 
   stm32_pwr_enablebkp(true);
+  modifyreg32(STM32_RCC_RTCAPBENR, 0, RCC_RTCAPBENR_RTCAPBEN);
   modifyreg32(STM32_RCC_RTCENR, 0, RCC_RTCENR_RTCEN);
 
   /* Save the token before losing it when resetting */
diff --git a/arch/arm/src/stm32h5/Kconfig b/arch/arm/src/stm32h5/Kconfig
index d32337d3f06..2563fd7106d 100644
--- a/arch/arm/src/stm32h5/Kconfig
+++ b/arch/arm/src/stm32h5/Kconfig
@@ -16,6 +16,7 @@ config STM32_H5_PERIPHERALS
        select STM32_HAVE_IP_TIMERS_V3
        select STM32_HAVE_IP_DBGMCU_V5
        select STM32_HAVE_IP_LPTIM_V2
+       select STM32_HAVE_IP_RTCC_M33M55_V1
        select STM32_HAVE_IP_USART_M33_V3
        select STM32_HAVE_DMA1
        select STM32_HAVE_DMA2
@@ -25,6 +26,9 @@ config STM32_H5_PERIPHERALS
        select STM32_HAVE_LPTIM2
        select STM32_HAVE_RNG
        select STM32_HAVE_IP_RNG_V1
+       select STM32_HAVE_RTC
+       select STM32_HAVE_RTC_MAGIC
+       select STM32_HAVE_RTC_SUBSECONDS
        select STM32_HAVE_SPI1
        select STM32_HAVE_SPI2
        select STM32_HAVE_SPI3

Reply via email to