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

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

commit 63b3dce51d1a6153aee7f85975b0d7c4ec21b913
Author: Darryl Ring <[email protected]>
AuthorDate: Mon Nov 23 12:28:40 2026 -0700

    arch/arm/stm32: Move the STM32H5 DAC driver to common.
    
    The polled DAC driver of STM32H5 becomes
    common/stm32/stm32_dac_m33_v1.c behind STM32_HAVE_IP_DAC_M33_V1, so
    that other families with the same DAC IP can use it.
    
    The output pins now come from GPIO_DAC1_OUT1/GPIO_DAC1_OUT2 in board.h,
    as in the other common DAC driver, and the RCC enable and reset bits are
    chosen per family.  stm32_dac_dumpregs() is only used by the low-level
    ops and is now built only with them.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Darryl Ring <[email protected]>
---
 Documentation/guides/chip-specific/stm32_ports.rst |  2 +-
 arch/arm/src/common/stm32/CMakeLists.txt           |  4 ++
 arch/arm/src/common/stm32/Kconfig.dac              |  4 +-
 arch/arm/src/common/stm32/Kconfig.have             |  3 +
 arch/arm/src/common/stm32/Make.defs                |  4 ++
 arch/arm/src/common/stm32/hardware/stm32_dac.h     |  5 +-
 .../stm32/hardware/stm32_dac_m33_v1.h}             |  8 +--
 arch/arm/src/common/stm32/stm32_dac.h              |  2 +
 .../stm32/stm32_dac_m33_v1.c}                      | 72 ++++++++++++++--------
 .../stm32/stm32_dac_m33_v1.h}                      |  8 +--
 arch/arm/src/stm32h5/CMakeLists.txt                |  4 --
 arch/arm/src/stm32h5/Kconfig                       |  1 +
 arch/arm/src/stm32h5/Make.defs                     |  4 --
 boards/arm/stm32h5/nucleo-h563zi/include/board.h   |  4 ++
 14 files changed, 81 insertions(+), 44 deletions(-)

diff --git a/Documentation/guides/chip-specific/stm32_ports.rst 
b/Documentation/guides/chip-specific/stm32_ports.rst
index 0ca9ed61f63..2d70725417e 100644
--- a/Documentation/guides/chip-specific/stm32_ports.rst
+++ b/Documentation/guides/chip-specific/stm32_ports.rst
@@ -609,7 +609,7 @@ Peripheral    Core version  Driver
 ADC           to be done    arch/arm/src/stm32h5/stm32_adc.c       
 AES/CRYP      to be done    not supported                          
 CAN/FDCAN     FDCAN         arch/arm/src/stm32h5/stm32_fdcan.c     
-DAC           to be done    not supported                          
+DAC           M33 v1        arch/arm/src/common/stm32/stm32_dac_m33_v1.c
 DTS           to be done    arch/arm/src/stm32h5/stm32_dts.c       
 ETH           v2            arch/arm/src/common/stm32/stm32_eth_v2.c
 EXTI          to be done    arch/arm/src/stm32h5/stm32_exti_gpio.c 
diff --git a/arch/arm/src/common/stm32/CMakeLists.txt 
b/arch/arm/src/common/stm32/CMakeLists.txt
index cef85ca6dfa..fe3cae17396 100644
--- a/arch/arm/src/common/stm32/CMakeLists.txt
+++ b/arch/arm/src/common/stm32/CMakeLists.txt
@@ -99,6 +99,10 @@ if(CONFIG_STM32_SPI AND CONFIG_STM32_HAVE_IP_SPI_V5)
   list(APPEND SRCS stm32_spi_v5.c)
 endif()
 
+if(CONFIG_STM32_DAC AND CONFIG_STM32_HAVE_IP_DAC_M33_V1)
+  list(APPEND SRCS stm32_dac_m33_v1.c)
+endif()
+
 if(CONFIG_STM32_ETHMAC AND CONFIG_STM32_HAVE_IP_ETHMAC_V2)
   list(APPEND SRCS stm32_eth_v2.c)
 endif()
diff --git a/arch/arm/src/common/stm32/Kconfig.dac 
b/arch/arm/src/common/stm32/Kconfig.dac
index 6b38c01469d..3cf8b867d41 100644
--- a/arch/arm/src/common/stm32/Kconfig.dac
+++ b/arch/arm/src/common/stm32/Kconfig.dac
@@ -83,7 +83,7 @@ config STM32_DAC1CH1_MODE
 
 config STM32_DAC1CH1_DMA
        bool "DAC1CH1 DMA"
-       depends on STM32_DAC1CH1 && !ARCH_CHIP_STM32H5
+       depends on STM32_DAC1CH1 && !STM32_HAVE_IP_DAC_M33_V1
        default n
        ---help---
                If DMA is selected, then a timer and output frequency must also 
be
@@ -165,7 +165,7 @@ config STM32_DAC1CH2_MODE
 
 config STM32_DAC1CH2_DMA
        bool "DAC1CH2 DMA"
-       depends on STM32_DAC1CH2 && !ARCH_CHIP_STM32H5
+       depends on STM32_DAC1CH2 && !STM32_HAVE_IP_DAC_M33_V1
        default n
        ---help---
                If DMA is selected, then a timer and output frequency must also 
be
diff --git a/arch/arm/src/common/stm32/Kconfig.have 
b/arch/arm/src/common/stm32/Kconfig.have
index 9bc0909aed7..923fbe5e2e1 100644
--- a/arch/arm/src/common/stm32/Kconfig.have
+++ b/arch/arm/src/common/stm32/Kconfig.have
@@ -235,6 +235,9 @@ config STM32_HAVE_IP_DAC_M3M4_V2
 config STM32_HAVE_IP_DAC_M0_V1
        bool
 
+config STM32_HAVE_IP_DAC_M33_V1
+       bool
+
 config STM32_HAVE_DAC1
        bool
 
diff --git a/arch/arm/src/common/stm32/Make.defs 
b/arch/arm/src/common/stm32/Make.defs
index 95cd99f01ba..ba72c1e3c81 100644
--- a/arch/arm/src/common/stm32/Make.defs
+++ b/arch/arm/src/common/stm32/Make.defs
@@ -110,6 +110,10 @@ ifeq ($(CONFIG_STM32_SPI)$(CONFIG_STM32_HAVE_IP_SPI_V5),yy)
 CHIP_CSRCS += stm32_spi_v5.c
 endif
 
+ifeq ($(CONFIG_STM32_DAC)$(CONFIG_STM32_HAVE_IP_DAC_M33_V1),yy)
+CHIP_CSRCS += stm32_dac_m33_v1.c
+endif
+
 ifeq ($(CONFIG_STM32_ETHMAC)$(CONFIG_STM32_HAVE_IP_ETHMAC_V2),yy)
 CHIP_CSRCS += stm32_eth_v2.c
 endif
diff --git a/arch/arm/src/common/stm32/hardware/stm32_dac.h 
b/arch/arm/src/common/stm32/hardware/stm32_dac.h
index dd8df7ed9b1..4855f584958 100644
--- a/arch/arm/src/common/stm32/hardware/stm32_dac.h
+++ b/arch/arm/src/common/stm32/hardware/stm32_dac.h
@@ -29,7 +29,8 @@
 
 #if (defined(CONFIG_STM32_HAVE_IP_DAC_M0_V1) + \
      defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V1) + \
-     defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V2)) > 1
+     defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V2) + \
+     defined(CONFIG_STM32_HAVE_IP_DAC_M33_V1)) > 1
 #  error Only one STM32 DAC IP version must be selected
 #endif
 
@@ -38,6 +39,8 @@
 #elif defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V1) || \
       defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V2)
 #  include "hardware/stm32_dac_v1v2.h"
+#elif defined(CONFIG_STM32_HAVE_IP_DAC_M33_V1)
+#  include "hardware/stm32_dac_m33_v1.h"
 #else
 #  error "Unsupported STM32 DAC"
 #endif
diff --git a/arch/arm/src/stm32h5/hardware/stm32_dac.h 
b/arch/arm/src/common/stm32/hardware/stm32_dac_m33_v1.h
similarity index 97%
rename from arch/arm/src/stm32h5/hardware/stm32_dac.h
rename to arch/arm/src/common/stm32/hardware/stm32_dac_m33_v1.h
index 73b32e22a89..39853e0d544 100644
--- a/arch/arm/src/stm32h5/hardware/stm32_dac.h
+++ b/arch/arm/src/common/stm32/hardware/stm32_dac_m33_v1.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * arch/arm/src/stm32h5/hardware/stm32_dac.h
+ * arch/arm/src/common/stm32/hardware/stm32_dac_m33_v1.h
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -20,8 +20,8 @@
  *
  ****************************************************************************/
 
-#ifndef __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_DAC_H
-#define __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_DAC_H
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_DAC_M33_V1_H
+#define __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_DAC_M33_V1_H
 
 /****************************************************************************
  * Included Files
@@ -155,4 +155,4 @@
 #  define DAC_MCR_HFSEL_AHB_80MHZ  (1 << DAC_MCR_HFSEL_SHIFT) /* HCLK > 80 MHz 
*/
 #  define DAC_MCR_HFSEL_AHB_160MHZ (2 << DAC_MCR_HFSEL_SHIFT) /* HCLK > 160 
MHz */
 
-#endif /* __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_DAC_H */
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_HARDWARE_STM32_DAC_M33_V1_H */
diff --git a/arch/arm/src/common/stm32/stm32_dac.h 
b/arch/arm/src/common/stm32/stm32_dac.h
index 192a666ec93..62c5d2d081d 100644
--- a/arch/arm/src/common/stm32/stm32_dac.h
+++ b/arch/arm/src/common/stm32/stm32_dac.h
@@ -32,6 +32,8 @@
 #if defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V1) || \
     defined(CONFIG_STM32_HAVE_IP_DAC_M3M4_V2)
 #  include "stm32_dac_m3m4_v1.h"
+#elif defined(CONFIG_STM32_HAVE_IP_DAC_M33_V1)
+#  include "stm32_dac_m33_v1.h"
 #else
 #  error "Unsupported STM32 stm32_dac"
 #endif
diff --git a/arch/arm/src/stm32h5/stm32_dac.c 
b/arch/arm/src/common/stm32/stm32_dac_m33_v1.c
similarity index 92%
rename from arch/arm/src/stm32h5/stm32_dac.c
rename to arch/arm/src/common/stm32/stm32_dac_m33_v1.c
index 2d3bdaf8866..29f016faca4 100644
--- a/arch/arm/src/stm32h5/stm32_dac.c
+++ b/arch/arm/src/common/stm32/stm32_dac_m33_v1.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * arch/arm/src/stm32h5/stm32_dac.c
+ * arch/arm/src/common/stm32/stm32_dac_m33_v1.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -59,6 +59,30 @@
 #  error "At least one DAC1 channel must be enabled"
 #endif
 
+#if defined(CONFIG_STM32_DAC1CH1) && !defined(GPIO_DAC1_OUT1)
+#  error "GPIO_DAC1_OUT1 must be defined in board.h"
+#endif
+
+#if defined(CONFIG_STM32_DAC1CH2) && !defined(GPIO_DAC1_OUT2)
+#  error "GPIO_DAC1_OUT2 must be defined in board.h"
+#endif
+
+/* DAC1 clock enable and reset bits (AHB2 on H5, AHB2 bank 1 on U3) */
+
+#if defined(RCC_AHB2ENR_DAC1EN)
+#  define STM32_RCC_DAC1_EN_REG   STM32_RCC_AHB2ENR
+#  define STM32_RCC_DAC1_EN       RCC_AHB2ENR_DAC1EN
+#  define STM32_RCC_DAC1_RST_REG  STM32_RCC_AHB2RSTR
+#  define STM32_RCC_DAC1_RST      RCC_AHB2RSTR_DACRST
+#elif defined(RCC_AHB2ENR1_DAC1EN)
+#  define STM32_RCC_DAC1_EN_REG   STM32_RCC_AHB2ENR1
+#  define STM32_RCC_DAC1_EN       RCC_AHB2ENR1_DAC1EN
+#  define STM32_RCC_DAC1_RST_REG  STM32_RCC_AHB2RSTR1
+#  define STM32_RCC_DAC1_RST      RCC_AHB2RSTR1_DAC1RST
+#else
+#  error "Unknown DAC1 RCC registers"
+#endif
+
 /* Helper macros for register bits */
 
 #define DAC_CR_EN(ch)         ((ch) == 1 ? DAC_CR_EN1 : DAC_CR_EN2)
@@ -117,7 +141,6 @@ struct stm32_chan_s
  * Private Function Prototypes
  ****************************************************************************/
 
-static void stm32_dac_dumpregs(struct stm32_chan_s *chan);
 static void stm32_dac_enable(struct stm32_chan_s *chan);
 
 static void stm32_dac_reset(struct dac_dev_s *dev);
@@ -132,6 +155,7 @@ static int  stm32_dac_chaninit(struct stm32_chan_s *chan);
 static void stm32_dac_blockinit(void);
 
 #ifdef CONFIG_STM32_DAC_LL_OPS
+static void stm32_dac_dumpregs(struct stm32_chan_s *chan);
 static void stm32_dac_llops_enable(struct stm32_dac_dev_s *dev,
                                    bool enabled);
 static void stm32_dac_llops_writedro(struct stm32_dac_dev_s *dev,
@@ -171,7 +195,7 @@ static struct stm32_chan_s g_dac1ch1priv =
   .llops      = &g_dac_llops,
 #endif
   .ch         = 1,
-  .pin        = GPIO_DAC1_OUT1_0,
+  .pin        = GPIO_DAC1_OUT1,
   .dro        = DAC_DHR12R(1),
 };
 
@@ -191,7 +215,7 @@ static struct stm32_chan_s g_dac1ch2priv =
   .llops      = &g_dac_llops,
 #endif
   .ch         = 2,
-  .pin        = GPIO_DAC1_OUT2_0,
+  .pin        = GPIO_DAC1_OUT2,
   .dro        = DAC_DHR12R(2),
 };
 
@@ -208,22 +232,6 @@ static struct stm32_dac_s g_dacblock;
  * Private Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: stm32_dac_dumpregs
- ****************************************************************************/
-
-static void stm32_dac_dumpregs(struct stm32_chan_s *chan)
-{
-  UNUSED(chan);
-
-  ainfo("CR:   0x%08" PRIx32 "  SR:  0x%08" PRIx32 "  MCR: 0x%08" PRIx32
-        "\n",
-        getreg32(STM32_DAC1_CR), getreg32(STM32_DAC1_SR),
-        getreg32(STM32_DAC1_MCR));
-  ainfo("DOR1: 0x%08" PRIx32 "  DOR2: 0x%08" PRIx32 "\n",
-        getreg32(STM32_DAC1_DOR1), getreg32(STM32_DAC1_DOR2));
-}
-
 /****************************************************************************
  * Name: stm32_dac_enable
  *
@@ -388,11 +396,11 @@ static void stm32_dac_blockinit(void)
 
   flags = enter_critical_section();
 
-  /* Enable the DAC1 clock (AHB2) and pulse its reset */
+  /* Enable the DAC1 clock and pulse its reset */
 
-  modifyreg32(STM32_RCC_AHB2ENR, 0, RCC_AHB2ENR_DAC1EN);
-  modifyreg32(STM32_RCC_AHB2RSTR, 0, RCC_AHB2RSTR_DACRST);
-  modifyreg32(STM32_RCC_AHB2RSTR, RCC_AHB2RSTR_DACRST, 0);
+  modifyreg32(STM32_RCC_DAC1_EN_REG, 0, STM32_RCC_DAC1_EN);
+  modifyreg32(STM32_RCC_DAC1_RST_REG, 0, STM32_RCC_DAC1_RST);
+  modifyreg32(STM32_RCC_DAC1_RST_REG, STM32_RCC_DAC1_RST, 0);
 
   g_dacblock.init = 1;
   leave_critical_section(flags);
@@ -400,6 +408,22 @@ static void stm32_dac_blockinit(void)
 
 #ifdef CONFIG_STM32_DAC_LL_OPS
 
+/****************************************************************************
+ * Name: stm32_dac_dumpregs
+ ****************************************************************************/
+
+static void stm32_dac_dumpregs(struct stm32_chan_s *chan)
+{
+  UNUSED(chan);
+
+  ainfo("CR:   0x%08" PRIx32 "  SR:  0x%08" PRIx32 "  MCR: 0x%08" PRIx32
+        "\n",
+        getreg32(STM32_DAC1_CR), getreg32(STM32_DAC1_SR),
+        getreg32(STM32_DAC1_MCR));
+  ainfo("DOR1: 0x%08" PRIx32 "  DOR2: 0x%08" PRIx32 "\n",
+        getreg32(STM32_DAC1_DOR1), getreg32(STM32_DAC1_DOR2));
+}
+
 /****************************************************************************
  * Name: stm32_dac_llops_enable
  ****************************************************************************/
diff --git a/arch/arm/src/stm32h5/stm32_dac.h 
b/arch/arm/src/common/stm32/stm32_dac_m33_v1.h
similarity index 94%
rename from arch/arm/src/stm32h5/stm32_dac.h
rename to arch/arm/src/common/stm32/stm32_dac_m33_v1.h
index 601b125c1de..14f67ae3dce 100644
--- a/arch/arm/src/stm32h5/stm32_dac.h
+++ b/arch/arm/src/common/stm32/stm32_dac_m33_v1.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * arch/arm/src/stm32h5/stm32_dac.h
+ * arch/arm/src/common/stm32/stm32_dac_m33_v1.h
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -20,8 +20,8 @@
  *
  ****************************************************************************/
 
-#ifndef __ARCH_ARM_SRC_STM32H5_STM32_DAC_H
-#define __ARCH_ARM_SRC_STM32H5_STM32_DAC_H
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_DAC_M33_V1_H
+#define __ARCH_ARM_SRC_COMMON_STM32_STM32_DAC_M33_V1_H
 
 /****************************************************************************
  * Included Files
@@ -117,4 +117,4 @@ struct dac_dev_s *stm32_dacinitialize(int intf);
 }
 #endif
 #endif /* __ASSEMBLY__ */
-#endif /* __ARCH_ARM_SRC_STM32H5_STM32_DAC_H */
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_DAC_M33_V1_H */
diff --git a/arch/arm/src/stm32h5/CMakeLists.txt 
b/arch/arm/src/stm32h5/CMakeLists.txt
index 3fdec57f497..92a6500a773 100644
--- a/arch/arm/src/stm32h5/CMakeLists.txt
+++ b/arch/arm/src/stm32h5/CMakeLists.txt
@@ -40,10 +40,6 @@ if(CONFIG_ADC)
   list(APPEND SRCS stm32_adc.c)
 endif()
 
-if(CONFIG_STM32_DAC)
-  list(APPEND SRCS stm32_dac.c)
-endif()
-
 if(CONFIG_STM32_FDCAN_CHARDRIVER)
   list(APPEND SRCS stm32_fdcan.c)
 endif()
diff --git a/arch/arm/src/stm32h5/Kconfig b/arch/arm/src/stm32h5/Kconfig
index e07b2e67582..0b3440bca8d 100644
--- a/arch/arm/src/stm32h5/Kconfig
+++ b/arch/arm/src/stm32h5/Kconfig
@@ -59,6 +59,7 @@ config STM32_H5_PERIPHERALS
        select STM32_HAVE_USBDRD_HOST
        select STM32_HAVE_ADC_H5
        select STM32_HAVE_DAC1
+       select STM32_HAVE_IP_DAC_M33_V1
        select STM32_HAVE_USART_H5
        select STM32_HAVE_USART_WUS
        select STM32_HAVE_I2C_H5
diff --git a/arch/arm/src/stm32h5/Make.defs b/arch/arm/src/stm32h5/Make.defs
index 906cd6853c0..7eb3c8eed35 100644
--- a/arch/arm/src/stm32h5/Make.defs
+++ b/arch/arm/src/stm32h5/Make.defs
@@ -48,10 +48,6 @@ ifeq ($(CONFIG_ADC),y)
 CHIP_CSRCS += stm32_adc.c
 endif
 
-ifeq ($(CONFIG_STM32_DAC),y)
-CHIP_CSRCS += stm32_dac.c
-endif
-
 ifeq ($(CONFIG_STM32_FDCAN_CHARDRIVER),y)
 CHIP_CSRCS += stm32_fdcan.c
 endif
diff --git a/boards/arm/stm32h5/nucleo-h563zi/include/board.h 
b/boards/arm/stm32h5/nucleo-h563zi/include/board.h
index 8efa8502193..ca8f9b70ab3 100644
--- a/boards/arm/stm32h5/nucleo-h563zi/include/board.h
+++ b/boards/arm/stm32h5/nucleo-h563zi/include/board.h
@@ -289,6 +289,10 @@
 #  define STM32_ADC_CLK_FREQUENCY    STM32_PLL2R_FREQUENCY
 #endif
 
+/* DAC: DAC1_OUT2 only; PA4 (DAC1_OUT1) is VBUS sense */
+
+#define GPIO_DAC1_OUT2        GPIO_DAC1_OUT2_0  /* PA5 */
+
 /* LED definitions **********************************************************/
 
 /* The Nucleo board has numerous LEDs but only three, LD1 a Green LED,

Reply via email to