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 34d8c37eb3499f77edec06732da8830d779b5a42
Author: Darryl Ring <[email protected]>
AuthorDate: Mon Nov 23 12:28:41 2026 -0700

    boards/nucleo-u3c5zi-q: Add DAC support
    
    Enable the newly added STM32U3 DAC support on the NUCLEO-U3C5ZI-Q board.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Darryl Ring <[email protected]>
---
 .../arm/stm32u3/boards/nucleo-u3c5zi-q/index.rst   |   3 +-
 .../nucleo-u3c5zi-q/configs/jumbo/defconfig        |   5 ++
 boards/arm/stm32u3/nucleo-u3c5zi-q/include/board.h |   5 ++
 .../arm/stm32u3/nucleo-u3c5zi-q/src/CMakeLists.txt |   8 +-
 boards/arm/stm32u3/nucleo-u3c5zi-q/src/Make.defs   |   4 +
 .../stm32u3/nucleo-u3c5zi-q/src/nucleo-u3c5zi-q.h  |   4 +
 .../stm32u3/nucleo-u3c5zi-q/src/stm32_bringup.c    |   9 ++
 boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_dac.c | 100 +++++++++++++++++++++
 8 files changed, 136 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/platforms/arm/stm32u3/boards/nucleo-u3c5zi-q/index.rst 
b/Documentation/platforms/arm/stm32u3/boards/nucleo-u3c5zi-q/index.rst
index 3f6c72a3c34..c811ad2b297 100644
--- a/Documentation/platforms/arm/stm32u3/boards/nucleo-u3c5zi-q/index.rst
+++ b/Documentation/platforms/arm/stm32u3/boards/nucleo-u3c5zi-q/index.rst
@@ -27,4 +27,5 @@ jumbo
 -----
 
 Enables a broad set of NuttX features to provide additional build and runtime
-coverage.
+coverage.  DAC1 channel 1 (PA4) is registered as ``/dev/dac0`` and can be
+driven with the ``dac`` example.
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/configs/jumbo/defconfig 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/configs/jumbo/defconfig
index 238d30f4048..cf8e7a3b2a3 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/configs/jumbo/defconfig
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/configs/jumbo/defconfig
@@ -5,6 +5,7 @@
 # You can then do "make savedefconfig" to generate a new defconfig file that 
includes your
 # modifications.
 #
+CONFIG_ANALOG=y
 CONFIG_ARCH="arm"
 CONFIG_ARCH_BOARD="nucleo-u3c5zi-q"
 CONFIG_ARCH_BOARD_COMMON=y
@@ -17,9 +18,11 @@ CONFIG_ARCH_INTERRUPTSTACK=2048
 CONFIG_ARCH_STACKDUMP=y
 CONFIG_BOARD_LOOPSPERMSEC=4800
 CONFIG_BUILTIN=y
+CONFIG_DAC=y
 CONFIG_DEBUG_FEATURES=y
 CONFIG_DEBUG_FULLOPT=y
 CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXAMPLES_DAC=y
 CONFIG_EXAMPLES_HELLO=y
 CONFIG_FS_PROCFS=y
 CONFIG_FS_PROCFS_REGISTER=y
@@ -49,6 +52,8 @@ CONFIG_SCHED_IRQMONITOR=y
 CONFIG_SCHED_LPWORK=y
 CONFIG_SCHED_WAITPID=y
 CONFIG_STACK_COLORATION=y
+CONFIG_STM32_DAC1=y
+CONFIG_STM32_DAC1CH1=y
 CONFIG_STM32_USART1=y
 CONFIG_SYSLOG_INTBUFFER=y
 CONFIG_SYSLOG_PRIORITY=y
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/include/board.h 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/include/board.h
index 70e57c5291a..5d5b1237d94 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/include/board.h
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/include/board.h
@@ -108,6 +108,11 @@
 #define GPIO_USART1_RX               GPIO_USART1_RX_1
 #define GPIO_USART1_TX               GPIO_USART1_TX_1
 
+/* DAC1 outputs.  PA5 is also the green LED. */
+
+#define GPIO_DAC1_OUT1               GPIO_DAC1_OUT1_1  /* PA4 */
+#define GPIO_DAC1_OUT2               GPIO_DAC1_OUT2_1  /* PA5 */
+
 /* User LEDs */
 
 #define GPIO_LED_GREEN               (GPIO_OUTPUT | GPIO_PUSHPULL | \
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/CMakeLists.txt 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/CMakeLists.txt
index 796aec3b5d1..270010fff7a 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/CMakeLists.txt
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/CMakeLists.txt
@@ -20,6 +20,12 @@
 #
 # 
##############################################################################
 
-target_sources(board PRIVATE stm32_boot.c stm32_bringup.c)
+set(SRCS stm32_boot.c stm32_bringup.c)
+
+if(CONFIG_DAC AND CONFIG_STM32_DAC1)
+  list(APPEND SRCS stm32_dac.c)
+endif()
+
+target_sources(board PRIVATE ${SRCS})
 
 set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld")
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/Make.defs 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/Make.defs
index 5d2504c5e8e..f0356b087bd 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/Make.defs
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/Make.defs
@@ -25,6 +25,10 @@
 ASRCS =
 CSRCS = stm32_boot.c stm32_bringup.c
 
+ifeq ($(CONFIG_DAC)$(CONFIG_STM32_DAC1),yy)
+CSRCS += stm32_dac.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/nucleo-u3c5zi-q.h 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/nucleo-u3c5zi-q.h
index f9184c2567b..3d50e19e705 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/nucleo-u3c5zi-q.h
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/nucleo-u3c5zi-q.h
@@ -31,5 +31,9 @@
 
 int stm32_bringup(void);
 
+#if defined(CONFIG_DAC) && defined(CONFIG_STM32_DAC1)
+int stm32_dac_setup(void);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_ARM_STM32U3_NUCLEO_U3C5ZI_Q_SRC_NUCLEO_U3C5ZI_Q_H */
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_bringup.c 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_bringup.c
index f5166e166d8..da138522193 100644
--- a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_bringup.c
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_bringup.c
@@ -32,6 +32,7 @@
 #include <nuttx/board.h>
 
 #include "board_common.h"
+#include "nucleo-u3c5zi-q.h"
 
 /****************************************************************************
  * Public Functions
@@ -50,5 +51,13 @@ int stm32_bringup(void)
              ret);
     }
 
+#if defined(CONFIG_DAC) && defined(CONFIG_STM32_DAC1)
+  ret = stm32_dac_setup();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: stm32_dac_setup() failed: %d\n", ret);
+    }
+#endif
+
   return OK;
 }
diff --git a/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_dac.c 
b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_dac.c
new file mode 100644
index 00000000000..790644e608a
--- /dev/null
+++ b/boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_dac.c
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * boards/arm/stm32u3/nucleo-u3c5zi-q/src/stm32_dac.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 <errno.h>
+#include <syslog.h>
+
+#include <nuttx/analog/dac.h>
+
+#include "stm32_dac.h"
+#include "nucleo-u3c5zi-q.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_dac_register
+ *
+ * Description:
+ *   Initialize one DAC1 channel and register it at the given path.
+ *
+ ****************************************************************************/
+
+static int stm32_dac_register(int intf, const char *path)
+{
+  struct dac_dev_s *dac;
+  int ret;
+
+  dac = stm32_dacinitialize(intf);
+  if (dac == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get DAC interface %d\n", intf);
+      return -ENODEV;
+    }
+
+  ret = dac_register(path, dac);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: dac_register %s failed: %d\n", path, ret);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_dac_setup
+ *
+ * Description:
+ *   Register DAC1 channel 1 (PA4) as /dev/dac0 and channel 2 (PA5) as
+ *   /dev/dac1.
+ *
+ ****************************************************************************/
+
+int stm32_dac_setup(void)
+{
+  int ret = OK;
+
+#ifdef CONFIG_STM32_DAC1CH1
+  ret = stm32_dac_register(0, "/dev/dac0");
+  if (ret < 0)
+    {
+      return ret;
+    }
+#endif
+
+#ifdef CONFIG_STM32_DAC1CH2
+  ret = stm32_dac_register(1, "/dev/dac1");
+#endif
+
+  return ret;
+}

Reply via email to