stm32h7: added stm32-dac driver

+ added dac driver
* modified Kconfig for DAC, DAC_DMA, TMX_DAC
* checked DMA+DAC/DAC only
* checked DCASH/wo DCASH
* checked TIM 1,2,4,5,6,7,8,15

Signed-off-by: Andrey Sobol <andrey.sobol.nn@gmail.com>
This commit is contained in:
Andrey Sobol 2026-07-02 10:17:48 +03:00 committed by Alan C. Assis
parent 3b1aea4bb0
commit 85041e1699
7 changed files with 1334 additions and 12 deletions

View file

@ -116,6 +116,7 @@ endif # STM32_HRTIM_DAC
config STM32_DAC1CH1_TIMER
int "DAC1CH1 timer"
depends on !STM32_DAC1CH1_DMA_EXTERNAL
range 1 15 if ARCH_CHIP_STM32H7
range 2 8
config STM32_DAC1CH1_TIMER_FREQUENCY
@ -177,6 +178,7 @@ endif # STM32_HRTIM_DAC
config STM32_DAC1CH2_TIMER
int "DAC1CH2 timer"
depends on !STM32_DAC1CH2_DMA_EXTERNAL
range 1 15 if ARCH_CHIP_STM32H7
range 2 8
config STM32_DAC1CH2_TIMER_FREQUENCY

View file

@ -946,6 +946,7 @@ config STM32_HAVE_TIM_DAC_TRIGGER
default y if STM32_COMMON_LEGACY
default y if ARCH_CHIP_STM32F7
default y if STM32_COMMON_L4_L5_U5
default y if ARCH_CHIP_STM32H7
config STM32_HAVE_TIM1
bool

View file

@ -51,6 +51,7 @@ config STM32_H7_PERIPHERALS
select STM32_HAVE_USART_RXFIFO_THRESHOLD
select STM32_HAVE_FDCAN_H7
select STM32_HAVE_IP_WDG_M3M4_V1
select STM32_HAVE_DAC1
choice
prompt "STM32 H7 Chip Selection"

View file

@ -75,6 +75,10 @@ ifeq ($(CONFIG_STM32_ADC),y)
CHIP_CSRCS += stm32_adc.c
endif
ifeq ($(CONFIG_STM32_DAC),y)
CHIP_CSRCS += stm32_dac.c
endif
ifeq ($(CONFIG_STM32_FDCAN),y)
CHIP_CSRCS += stm32_fdcan_sock.c
endif

View file

@ -87,22 +87,22 @@
#define DAC_CR_EN1 (1 << 0) /* Bit 0: ch1 enable */
#define DAC_CR_TEN1 (1 << 1) /* Bit 1: ch1 trigger enable */
#define DAC_CR_TSEL1_SHIFT (1 << 2) /* Bits 5-2: ch1 trigger sel */
#define DAC_CR_TSEL1_SHIFT (2) /* Bits 5-2: ch1 trigger sel */
#define DAC_CR_TSEL1_MASK (15 << DAC_CR_TSEL1_SHIFT)
#define DAC_CR_WAVE1_SHIFT (1 << 6) /* Bits 7-6: ch1 wave enable */
#define DAC_CR_WAVE1_SHIFT (6) /* Bits 7-6: ch1 wave enable */
#define DAC_CR_WAVE1_MASK (3 << DAC_CR_WAVE1_SHIFT)
#define DAC_CR_MAMP1_SHIFT (1 << 8) /* Bits 11-8: ch1 mask/amplitude */
#define DAC_CR_MAMP1_SHIFT (8) /* Bits 11-8: ch1 mask/amplitude */
#define DAC_CR_MAMP1_MASK (15 << DAC_CR_MAMP1_SHIFT)
#define DAC_CR_DMAEN1 (1 << 12) /* Bit 12: ch1 dma enable */
#define DAC_CR_DMAUDRIE1 (1 << 13) /* Bit 13: ch1 dma underrun interrupt enable */
#define DAC_CR_CEN1 (1 << 14) /* Bit 14: ch1 calibration enable */
#define DAC_CR_EN2 (1 << 16) /* Bit 16: ch2 enable */
#define DAC_CR_TEN2 (1 << 17) /* Bit 17: ch2 trigger enable */
#define DAC_CR_TSEL2_SHIFT (1 << 18) /* Bits 28-21: ch2 trigger sel */
#define DAC_CR_TSEL2_SHIFT (8) /* Bits 28-21: ch2 trigger sel */
#define DAC_CR_TSEL2_MASK (15 << DAC_CR_TSEL2_SHIFT)
#define DAC_CR_WAVE2_SHIFT (1 << 22) /* Bits 23-22: ch2 wave enable */
#define DAC_CR_WAVE2_SHIFT (22) /* Bits 23-22: ch2 wave enable */
#define DAC_CR_WAVE2_MASK (3 << DAC_CR_WAVE2_SHIFT)
#define DAC_CR_MAMP2_SHIFT (1 << 24) /* Bits 27-24: ch2 mask/amplitude */
#define DAC_CR_MAMP2_SHIFT (24) /* Bits 27-24: ch2 mask/amplitude */
#define DAC_CR_MAMP2_MASK (15 << DAC_CR_MAMP2_SHIFT)
#define DAC_CR_DMAEN2 (1 << 28) /* Bit 28: ch2 dma enable */
#define DAC_CR_DMAUDRIE2 (1 << 29) /* Bit 29: ch2 dma underrun interrupt enable */
@ -123,19 +123,19 @@
#define DAC_SR_BWST2 (1 << 31) /* Bit 31: ch2 busy writing */
/* DAC mode control register */
#define DAC_MCR_MODE1_SHIFT (1 << 0) /* Bits 2-0: ch1 mode */
#define DAC_MCR_MODE1_SHIFT (0) /* Bits 2-0: ch1 mode */
#define DAC_MCR_MODE1_MASK (7 << DAC_MCR_MODE1_SHIFT)
#define DAC_MCR_MODE1_NORM (4 << DAC_MCR_MODE1_SHIFT) /* ch1 normal mode */
#define DAC_MCR_MODE1_SAMPLE_HOLD (0 << DAC_MCR_MODE1_SHIFT) /* ch1 sample and hold mode */
#define DAC_MCR_MODE1_DIS_BUFFER (2 << DAC_MCR_MODE1_SHIFT) /* ch1 buffer disabled */
#define DAC_MCR_MODE1_EXT (0 << DAC_MCR_MODE1_SHIFT) /* ch1 to external pin */
#define DAC_MCR_MODE1_ON_CHIP (1 << DAC_MCR_MODE1_SHIFT) /* ch1 to on chip and external */
#define DAC_MCR_MODE2_SHIFT (1 << 16) /* Bits 18-16: ch2 mode */
#define DAC_MCR_MODE1_EXT (1 << DAC_MCR_MODE1_SHIFT) /* ch1 to external pin */
#define DAC_MCR_MODE1_ON_CHIP (5 << DAC_MCR_MODE1_SHIFT) /* ch1 to on chip and external */
#define DAC_MCR_MODE2_SHIFT (16) /* Bits 18-16: ch2 mode */
#define DAC_MCR_MODE2_MASK (7 << DAC_MCR_MODE2_SHIFT)
#define DAC_MCR_MODE2_NORM (4 << DAC_MCR_MODE2_SHIFT) /* ch2 normal mode */
#define DAC_MCR_MODE2_SAMPLE_HOLD (0 << DAC_MCR_MODE2_SHIFT) /* ch2 sample and hold mode */
#define DAC_MCR_MODE2_DIS_BUFFER (2 << DAC_MCR_MODE2_SHIFT) /* ch2 buffer disabled */
#define DAC_MCR_MODE2_EXT (0 << DAC_MCR_MODE2_SHIFT) /* ch2 to external pin */
#define DAC_MCR_MODE2_ON_CHIP (1 << DAC_MCR_MODE2_SHIFT) /* ch2 to on chip and external */
#define DAC_MCR_MODE2_EXT (1 << DAC_MCR_MODE2_SHIFT) /* ch2 to external pin */
#define DAC_MCR_MODE2_ON_CHIP (5 << DAC_MCR_MODE2_SHIFT) /* ch2 to on chip and external */
#endif /* __ARCH_ARM_SRC_STM32H7_HARDWARE_STM32_DAC_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,182 @@
/****************************************************************************
* arch/arm/src/stm32h7/stm32_dac.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_STM32_STM32H7_DAC_H
#define __ARCH_ARM_SRC_STM32_STM32H7_DAC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "chip.h"
#include "hardware/stm32_dac.h"
#include <nuttx/analog/dac.h>
/****************************************************************************
* Pre-processor definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Timer devices may be used for different purposes. One special purpose is
* to control periodic DAC outputs. If CONFIG_STM32_TIMn is defined then
* CONFIG_STM32_TIMn_DAC must also be defined to indicate that timer "n"
* is intended to be used for that purpose.
*/
#ifndef CONFIG_STM32_TIM1
# undef CONFIG_STM32_TIM1_DAC
#endif
#ifndef CONFIG_STM32_TIM2
# undef CONFIG_STM32_TIM2_DAC
#endif
#ifndef CONFIG_STM32_TIM3
# undef CONFIG_STM32_TIM3_DAC
#endif
#ifndef CONFIG_STM32_TIM4
# undef CONFIG_STM32_TIM4_DAC
#endif
#ifndef CONFIG_STM32_TIM5
# undef CONFIG_STM32_TIM5_DAC
#endif
#ifndef CONFIG_STM32_TIM6
# undef CONFIG_STM32_TIM6_DAC
#endif
#ifndef CONFIG_STM32_TIM7
# undef CONFIG_STM32_TIM7_DAC
#endif
#ifndef CONFIG_STM32_TIM8
# undef CONFIG_STM32_TIM8_DAC
#endif
#ifndef CONFIG_STM32_TIM15
# undef CONFIG_STM32_TIM15_DAC
#endif
#ifndef CONFIG_STM32_TIM16
# undef CONFIG_STM32_TIM16_DAC
#endif
#ifndef CONFIG_STM32_TIM17
# undef CONFIG_STM32_TIM17_DAC
#endif
/* Low-level ops helpers ****************************************************/
#define DAC_ENABLE(dac,d) \
(dac)->llops->enable(dac,d)
#define DAC_WRITE_DRO(dac,d) \
(dac)->llops->write_dro(dac,d)
#define DAC_START_DMA(dac) \
(dac)->llops->start_dma(dac)
#define DAC_STOP_DMA(dac) \
(dac)->llops->stop_dma(dac)
#define DAC_DUMP_REGS(dac) \
(dac)->llops->dump_regs(dac)
/****************************************************************************
* Public Types
****************************************************************************/
#ifdef CONFIG_STM32_DAC_LL_OPS
/* This structure provides the publicly visible representation of the
* "lower-half" DAC driver structure.
*/
struct stm32_dac_dev_s
{
/* Publicly visible portion of the "lower-half" ADC driver structure */
const struct stm32_dac_ops_s *llops;
/* Require cast-compatibility with private "lower-half" ADC structure */
};
/* Low-level operations for DAC */
struct stm32_dac_ops_s
{
/* Enable / Disable DAC */
void (*enable)(struct stm32_dac_dev_s *dev, bool enabled);
/* Write DRO */
void (*write_dro)(struct stm32_dac_dev_s *dev, uint16_t data);
/* Start DMA */
void (*start_dma)(struct stm32_dac_dev_s *dev);
/* Stop DMA */
void (*stop_dma)(struct stm32_dac_dev_s *dev);
/* Dump DAC regs */
void (*dump_regs)(struct stm32_dac_dev_s *dev);
};
#endif /* CONFIG_STM32_DAC_LL_OPS */
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_dacinitialize
*
* Description:
* Initialize the DAC
*
* Input Parameters:
* intf - The DAC interface number.
*
* Returned Value:
* Valid dac device structure reference on success; a NULL on failure
*
****************************************************************************/
struct dac_dev_s;
struct dac_dev_s *stm32_dacinitialize(int intf);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_STM32_STM32H7_DAC_H */