From 002945cc6ce84eb691a5329db1cbd0f51a5e1f16 Mon Sep 17 00:00:00 2001 From: "Daniel P. Carvalho" Date: Thu, 15 Jul 2021 11:55:11 -0300 Subject: [PATCH] Add DAC example to nucleo-g431kb --- boards/arm/stm32/nucleo-g431kb/src/Make.defs | 4 + .../stm32/nucleo-g431kb/src/nucleo-g431kb.h | 12 +++ .../stm32/nucleo-g431kb/src/stm32_bringup.c | 10 +++ .../arm/stm32/nucleo-g431kb/src/stm32_dac.c | 89 +++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 boards/arm/stm32/nucleo-g431kb/src/stm32_dac.c diff --git a/boards/arm/stm32/nucleo-g431kb/src/Make.defs b/boards/arm/stm32/nucleo-g431kb/src/Make.defs index fce06a2232..f462d8923c 100755 --- a/boards/arm/stm32/nucleo-g431kb/src/Make.defs +++ b/boards/arm/stm32/nucleo-g431kb/src/Make.defs @@ -41,6 +41,10 @@ ifeq ($(CONFIG_STM32_COMP),y) CSRCS += stm32_comp.c endif +ifeq ($(CONFIG_STM32_DAC),y) +CSRCS += stm32_dac.c +endif + DEPPATH += --dep-path board VPATH += :board CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board) diff --git a/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h b/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h index 609d10c5a6..c1da1a7e71 100755 --- a/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h +++ b/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h @@ -114,4 +114,16 @@ int stm32_pwm_setup(void); int stm32_comp_setup(void); #endif +/**************************************************************************** + * Name: stm32_comp_setup + * + * Description: + * Initialize COMP peripheral for the board. + * + ****************************************************************************/ + +#ifdef CONFIG_DAC +int stm32_dac_setup(void); +#endif + #endif /* __BOARDS_ARM_STM32_NUCLEO_G431KB_SRC_NUCLEO_G431KB_H */ diff --git a/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c b/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c index fa504d7c27..80257f475a 100755 --- a/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c +++ b/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c @@ -98,6 +98,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_DAC + /* Initialize and register the DAC driver. */ + + ret = stm32_dac_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_dac_setup failed: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/boards/arm/stm32/nucleo-g431kb/src/stm32_dac.c b/boards/arm/stm32/nucleo-g431kb/src/stm32_dac.c new file mode 100644 index 0000000000..e5bed08fe2 --- /dev/null +++ b/boards/arm/stm32/nucleo-g431kb/src/stm32_dac.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * boards/arm/stm32/nucleo-g431kb/src/stm32_dac.c + * + * 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 +#include +#include + +#include +#include + +#include "stm32_dac.h" +#include "nucleo-g431kb.h" + +#ifdef CONFIG_DAC + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_STM32_DAC1CH1 +static struct dac_dev_s *g_dac1; +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_dac_setup + * + * Description: + * Initialize and register the DAC driver. + * + * Input parameters: + * devpath - The full path to the driver to register. E.g., "/dev/dac0" + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int stm32_dac_setup(void) +{ + int ret; +#ifdef CONFIG_STM32_DAC1CH1 + g_dac1 = stm32_dacinitialize(1); + if (g_dac1 == NULL) + { + aerr("ERROR: Failed to get DAC interface\n"); + return -ENODEV; + } + + /* Register the DAC driver at "/dev/dac0" */ + + ret = dac_register("/dev/dac0", g_dac1); + if (ret < 0) + { + aerr("ERROR: dac_register() failed: %d\n", ret); + return ret; + } + +#endif + + UNUSED(ret); + return OK; +} + +#endif /* CONFIG_DAC */