This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit d94ca301e1b8e3a1affb58dec947e1dcd1fa2877 Author: Darryl Ring <[email protected]> AuthorDate: Wed Oct 7 11:57:31 2026 -0700 boards/arm/stm32h5/nucleo-h563zi: Add dac config This adds a new board configuration enabling the DAC channel 2 (connected to PA5). Channel 1 cannot be used on this board because it is used to sense the VBUS voltage through a voltage divider Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Darryl Ring <[email protected]> --- .../arm/stm32h5/boards/nucleo-h563zi/index.rst | 11 +++ .../stm32h5/nucleo-h563zi/configs/dac/defconfig | 55 ++++++++++++++ boards/arm/stm32h5/nucleo-h563zi/include/board.h | 16 ++++- .../arm/stm32h5/nucleo-h563zi/src/CMakeLists.txt | 4 ++ boards/arm/stm32h5/nucleo-h563zi/src/Make.defs | 4 ++ .../arm/stm32h5/nucleo-h563zi/src/nucleo-h563zi.h | 11 +++ .../arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c | 8 +++ boards/arm/stm32h5/nucleo-h563zi/src/stm32_dac.c | 83 ++++++++++++++++++++++ 8 files changed, 189 insertions(+), 3 deletions(-) diff --git a/Documentation/platforms/arm/stm32h5/boards/nucleo-h563zi/index.rst b/Documentation/platforms/arm/stm32h5/boards/nucleo-h563zi/index.rst index ef92f0598c1..18244d39b2d 100644 --- a/Documentation/platforms/arm/stm32h5/boards/nucleo-h563zi/index.rst +++ b/Documentation/platforms/arm/stm32h5/boards/nucleo-h563zi/index.rst @@ -140,6 +140,17 @@ This configuration configures ADC1_IN3 and ADC1_IN10, which can be accessed at the CN9 A0 and A1 pins respectively. Modify nucleo-h563zi/src/stm32_adc.c to enable more channels. +dac: +-------- + +This configuration enables DAC1 (polled, no DMA). DAC1_OUT2 (PA5) is +registered as /dev/dac0, and can be tested with the dac example +application, e.g. ``dac -d 0``. + +The ADC/DAC kernel clock is switched from PLL2R to HCLK when the DAC is +enabled, because the DAC output voltage is invalid with other kernel clocks +(see the STM32H5 errata). + pwm: -------- diff --git a/boards/arm/stm32h5/nucleo-h563zi/configs/dac/defconfig b/boards/arm/stm32h5/nucleo-h563zi/configs/dac/defconfig new file mode 100644 index 00000000000..8e7b630500e --- /dev/null +++ b/boards/arm/stm32h5/nucleo-h563zi/configs/dac/defconfig @@ -0,0 +1,55 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_ARGCAT is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ANALOG=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nucleo-h563zi" +CONFIG_ARCH_BOARD_NUCLEO_H563ZI=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP="stm32h5" +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32H563ZI=y +CONFIG_ARCH_CHIP_STM32H5=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_STACKCHECK=y +CONFIG_BOARD_LOOPSPERMSEC=9251 +CONFIG_BUILTIN=y +CONFIG_DAC=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_EXAMPLES_DAC=y +CONFIG_EXPERIMENTAL=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LINE_MAX=64 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_IFUPDOWN=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=655360 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_STM32_DAC1=y +CONFIG_STM32_DAC1CH2=y +CONFIG_STM32_USART3=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_USART3_SERIAL_CONSOLE=y diff --git a/boards/arm/stm32h5/nucleo-h563zi/include/board.h b/boards/arm/stm32h5/nucleo-h563zi/include/board.h index 0612da9e478..80e1eddf29a 100644 --- a/boards/arm/stm32h5/nucleo-h563zi/include/board.h +++ b/boards/arm/stm32h5/nucleo-h563zi/include/board.h @@ -265,10 +265,20 @@ #define GPIO_ETH_RMII_CRS_DV (GPIO_ETH_RMII_CRS_DV_0 | GPIO_SPEED_100MHZ) /* PA7 */ #define GPIO_ETH_RMII_REF_CLK (GPIO_ETH_RMII_REF_CLK_0 | GPIO_SPEED_100MHZ) /* PA1 */ -/* ADC Clock Source *********************************************************/ +/* ADC/DAC Clock Source *****************************************************/ -#define STM32_RCC_CCIPR5_ADCDACSEL RCC_CCIPR5_ADCDACSEL_PLL2RCK -#define STM32_ADC_CLK_FREQUENCY STM32_PLL2R_FREQUENCY +/* The ADC and the DAC share a kernel clock. Erratum "Invalid DAC output + * voltage for several DAC kernel clocks" requires that the kernel clock is + * HCLK or SYSCLK whenever the DAC is used. + */ + +#ifdef CONFIG_STM32_DAC1 +# define STM32_RCC_CCIPR5_ADCDACSEL RCC_CCIPR5_ADCDACSEL_RCCHCLK +# define STM32_ADC_CLK_FREQUENCY STM32_HCLK_FREQUENCY +#else +# define STM32_RCC_CCIPR5_ADCDACSEL RCC_CCIPR5_ADCDACSEL_PLL2RCK +# define STM32_ADC_CLK_FREQUENCY STM32_PLL2R_FREQUENCY +#endif /* LED definitions **********************************************************/ diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/CMakeLists.txt b/boards/arm/stm32h5/nucleo-h563zi/src/CMakeLists.txt index 65614b78d27..bea3151a43b 100644 --- a/boards/arm/stm32h5/nucleo-h563zi/src/CMakeLists.txt +++ b/boards/arm/stm32h5/nucleo-h563zi/src/CMakeLists.txt @@ -40,6 +40,10 @@ if(CONFIG_ADC) list(APPEND SRCS stm32_adc.c) endif() +if(CONFIG_DAC) + list(APPEND SRCS stm32_dac.c) +endif() + if(CONFIG_STM32_DTS) list(APPEND SRCS stm32_dts.c) endif() diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/Make.defs b/boards/arm/stm32h5/nucleo-h563zi/src/Make.defs index 6dc7a2fc920..61479fc3834 100644 --- a/boards/arm/stm32h5/nucleo-h563zi/src/Make.defs +++ b/boards/arm/stm32h5/nucleo-h563zi/src/Make.defs @@ -40,6 +40,10 @@ ifeq ($(CONFIG_ADC),y) CSRCS += stm32_adc.c endif +ifeq ($(CONFIG_DAC),y) +CSRCS += stm32_dac.c +endif + ifeq ($(CONFIG_STM32_DTS),y) CSRCS += stm32_dts.c endif diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/nucleo-h563zi.h b/boards/arm/stm32h5/nucleo-h563zi/src/nucleo-h563zi.h index 96866ab06f3..7ad48f96ed5 100644 --- a/boards/arm/stm32h5/nucleo-h563zi/src/nucleo-h563zi.h +++ b/boards/arm/stm32h5/nucleo-h563zi/src/nucleo-h563zi.h @@ -141,6 +141,17 @@ void stm32_spiinitialize(void); int stm32_adc_setup(void); #endif +/**************************************************************************** + * Name: stm32_dac_setup + * + * Description: + * Initialize the DAC and register the DAC driver. + ****************************************************************************/ + +#ifdef CONFIG_DAC +int stm32_dac_setup(void); +#endif + #ifdef CONFIG_STM32_DTS int stm32_dts_setup(int devno); #endif diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c index f903ea339fc..335dfd2cd22 100644 --- a/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c +++ b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_bringup.c @@ -107,6 +107,14 @@ int stm32_bringup(void) } #endif /* CONFIG_ADC*/ +#ifdef CONFIG_DAC + ret = stm32_dac_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_dac_setup failed: %d\n", ret); + } +#endif /* CONFIG_DAC */ + #ifdef CONFIG_STM32_DTS /* devno == 0 creates /dev/sensor_temp0 */ diff --git a/boards/arm/stm32h5/nucleo-h563zi/src/stm32_dac.c b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_dac.c new file mode 100644 index 00000000000..52a38660016 --- /dev/null +++ b/boards/arm/stm32h5/nucleo-h563zi/src/stm32_dac.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * boards/arm/stm32h5/nucleo-h563zi/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 <stdbool.h> +#include <errno.h> +#include <nuttx/debug.h> + +#include <nuttx/analog/dac.h> + +#include "stm32.h" +#include "nucleo-h563zi.h" + +#if defined(CONFIG_DAC) && defined(CONFIG_STM32_DAC1) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_dac_setup + * + * Description: + * Initialize the DAC and register the DAC driver. DAC1_OUT2 (PA5) is + * registered as /dev/dac0. + * + ****************************************************************************/ + +int stm32_dac_setup(void) +{ + static bool initialized = false; + struct dac_dev_s *dac; + int ret; + + if (!initialized) + { +#ifdef CONFIG_STM32_DAC1CH2 + dac = stm32_dacinitialize(1); + if (dac == NULL) + { + aerr("ERROR: Failed to get DAC1 channel 2\n"); + return -ENODEV; + } + + ret = dac_register("/dev/dac0", dac); + if (ret < 0) + { + aerr("ERROR: dac_register /dev/dac0 failed: %d\n", ret); + return ret; + } +#endif + + initialized = true; + } + + return OK; +} + +#endif /* CONFIG_DAC && CONFIG_STM32_DAC1 */
