From 09757bec7d01209455698d616b3ab50d7adb113e Mon Sep 17 00:00:00 2001 From: Juan Flores Date: Fri, 12 Jul 2019 07:22:20 -0600 Subject: [PATCH] configs/olimex-stm32-e407: Add DAC support. --- configs/olimex-stm32-e407/README.txt | 35 ++++-- configs/olimex-stm32-e407/dac/defconfig | 66 +++++++++++ configs/olimex-stm32-e407/src/Makefile | 4 + .../olimex-stm32-e407/src/olimex-stm32-e407.h | 18 +++ configs/olimex-stm32-e407/src/stm32_bringup.c | 10 ++ configs/olimex-stm32-e407/src/stm32_dac.c | 111 ++++++++++++++++++ 6 files changed, 233 insertions(+), 11 deletions(-) create mode 100644 configs/olimex-stm32-e407/dac/defconfig create mode 100644 configs/olimex-stm32-e407/src/stm32_dac.c diff --git a/configs/olimex-stm32-e407/README.txt b/configs/olimex-stm32-e407/README.txt index 5abaceebe7..2def1babed 100644 --- a/configs/olimex-stm32-e407/README.txt +++ b/configs/olimex-stm32-e407/README.txt @@ -62,17 +62,30 @@ Configurations BMP180: ------ - This a configuration example for the BMP180 barometer sensor. This - sensor works with I2C, you need to do the next connections: + This is a configuration example for the BMP180 barometer sensor. This + sensor works with I2C, you need to do the next connections: - BMP180 VIN -> Board 3.3V - BMP180 GND -> Board GND - BMP180 SCL -> Board PB6 (Arduino header D1) - BMP180 SDA -> Board PB7 (Arduino header D0) + BMP180 VIN -> Board 3.3V + BMP180 GND -> Board GND + BMP180 SCL -> Board PB6 (Arduino header D1) + BMP180 SDA -> Board PB7 (Arduino header D0) - This example is configured to work with the USBNSH instead of UART NSH, so - the console will be shown over the USB_OTG1 connector. + This example is configured to work with the USBNSH instead of UART NSH, so + the console will be shown over the USB_OTG1 connector. + + On the console, type "ls /dev " and if the registration process goes fine, + you should see a device called "press0". Now execute the app + BMP180 to see the ambient pressure value. + + DAC: + --- + This is a configuration example to use the DAC1 of the board.The DAC1 is attached + to the PA4 pin (Arduino header D10). + + This example is configured to work with the USBNSH instead of UART NSH, so + the console will be shown over the USB_OTG1 connector. + + On the console, type "ls /dev " and if the registration process goes fine, + you should see a device called "dac0". Now execute the app + dac put a value at the output. - On the console, type "ls /dev " and if the registration process goes fine, - you should see a device called "press0". Now execute the app - BMP180 to see the ambient pressure value. diff --git a/configs/olimex-stm32-e407/dac/defconfig b/configs/olimex-stm32-e407/dac/defconfig new file mode 100644 index 0000000000..77f614d02c --- /dev/null +++ b/configs/olimex-stm32-e407/dac/defconfig @@ -0,0 +1,66 @@ +# +# 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_ARCH_FPU is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ANALOG=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="olimex-stm32-e407" +CONFIG_ARCH_BOARD_OLIMEX_STM32E407=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_CHIP_STM32=y +CONFIG_ARCH_CHIP_STM32F407ZG=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_USBDEVCTRL=y +CONFIG_BOARD_LATE_INITIALIZE=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_CDCACM=y +CONFIG_CDCACM_CONSOLE=y +CONFIG_DAC=y +CONFIG_EXAMPLES_DAC=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_HELLOXX=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_INTELHEX_BINARY=y +CONFIG_LIB_BOARDCTL=y +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MM_REGIONS=2 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=16 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_STM32_DAC1=y +CONFIG_STM32_DAC1CH1=y +CONFIG_STM32_JTAG_SW_ENABLE=y +CONFIG_STM32_OTGFS=y +CONFIG_STM32_PWR=y +CONFIG_STM32_USART3=y +CONFIG_SYSTEM_NSH=y +CONFIG_USART3_RXBUFSIZE=128 +CONFIG_USART3_TXBUFSIZE=128 +CONFIG_USBDEV=y +CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/configs/olimex-stm32-e407/src/Makefile b/configs/olimex-stm32-e407/src/Makefile index 44defad9d7..89af9cc67e 100644 --- a/configs/olimex-stm32-e407/src/Makefile +++ b/configs/olimex-stm32-e407/src/Makefile @@ -84,5 +84,9 @@ ifeq ($(CONFIG_SENSORS_BMP180),y) CSRCS += stm32_bmp180.c endif +ifeq ($(CONFIG_DAC),y) +CSRCS += stm32_dac.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/olimex-stm32-e407/src/olimex-stm32-e407.h b/configs/olimex-stm32-e407/src/olimex-stm32-e407.h index af7ef82633..7c5a0a85ed 100644 --- a/configs/olimex-stm32-e407/src/olimex-stm32-e407.h +++ b/configs/olimex-stm32-e407/src/olimex-stm32-e407.h @@ -287,5 +287,23 @@ int stm32_can_setup(void); int stm32_bmp180initialize(FAR const char *devpath); #endif +/************************************************************************************ + * Name: stm32_dac_setup + * + * Description: + * Initialize and register the DAC0 of the microcontroller. + * + * 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. + * + ************************************************************************************/ + +#if defined(CONFIG_DAC) +int stm32_dac_setup(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_OLIMEX_STM32_E407_SRC_INTERNAL_H */ diff --git a/configs/olimex-stm32-e407/src/stm32_bringup.c b/configs/olimex-stm32-e407/src/stm32_bringup.c index 2f9becd43a..b6cb62e86c 100644 --- a/configs/olimex-stm32-e407/src/stm32_bringup.c +++ b/configs/olimex-stm32-e407/src/stm32_bringup.c @@ -229,6 +229,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_DAC + /* Initialize DAC and register the DAC driver. */ + + ret = stm32_dac_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to start ADC1: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/configs/olimex-stm32-e407/src/stm32_dac.c b/configs/olimex-stm32-e407/src/stm32_dac.c new file mode 100644 index 0000000000..fc801a0f50 --- /dev/null +++ b/configs/olimex-stm32-e407/src/stm32_dac.c @@ -0,0 +1,111 @@ +/***************************************************************************** + * configs/olimex-stm32-e407/src/stm32_dac.c + * + * Copyright (C) 2019 Acutronics Robotics All rights reserved. + * Authors: Acutronics Robotics (Juan Flores) + * Base on the work of: Juha Niskanen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include +#include + +#include +#include + +#include "stm32_dac.h" +#include "olimex-stm32-e407.h" + +#include + +#if defined(CONFIG_DAC) + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +static struct dac_dev_s *g_dac; + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + + /************************************************************************************ + * Name: stm32_dac_setup + * + * Description: + * Initialize and register the DAC0 of the microcontroller. + * + * 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) +{ + static bool initialized = false; + + if (!initialized) + { + + int ret; + + g_dac = stm32_dacinitialize(1); + if (g_dac == NULL) + { + aerr("ERROR: Failed to get DAC interface\n"); + return -ENODEV; + } + + /* Register the DAC driver at "/dev/dac0" */ + + ret = dac_register("/dev/dac0", g_dac); + if (ret < 0) + { + aerr("ERROR: dac_register failed: %d\n", ret); + return ret; + } + + initialized = true; + } + + return OK; +} + +#endif +