You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/08 00:35:10 UTC
[incubator-nuttx] 02/04: Add nucleo-g431kb Analog Comparator
example.
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/incubator-nuttx.git
commit 59b2ed4210288365e0004709842fc2eaf2350297
Author: Daniel P. Carvalho <da...@gmail.com>
AuthorDate: Wed Jul 7 15:00:27 2021 -0300
Add nucleo-g431kb Analog Comparator example.
---
.../arm/stm32/nucleo-g431kb/configs/comp/defconfig | 44 +++++++
boards/arm/stm32/nucleo-g431kb/include/board.h | 18 ++-
boards/arm/stm32/nucleo-g431kb/src/Make.defs | 4 +
boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h | 12 ++
boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c | 10 ++
boards/arm/stm32/nucleo-g431kb/src/stm32_comp.c | 146 +++++++++++++++++++++
6 files changed, 228 insertions(+), 6 deletions(-)
diff --git a/boards/arm/stm32/nucleo-g431kb/configs/comp/defconfig b/boards/arm/stm32/nucleo-g431kb/configs/comp/defconfig
new file mode 100644
index 0000000..56b536b
--- /dev/null
+++ b/boards/arm/stm32/nucleo-g431kb/configs/comp/defconfig
@@ -0,0 +1,44 @@
+#
+# 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_ANALOG=y
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-g431kb"
+CONFIG_ARCH_BOARD_NUCLEO_G431KB=y
+CONFIG_ARCH_CHIP="stm32"
+CONFIG_ARCH_CHIP_STM32=y
+CONFIG_ARCH_CHIP_STM32G431K=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARD_LOOPSPERMSEC=5483
+CONFIG_BUILTIN=y
+CONFIG_COMP=y
+CONFIG_DEFAULT_SMALL=y
+CONFIG_INTELHEX_BINARY=y
+CONFIG_MAX_TASKS=16
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=22528
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_START_DAY=15
+CONFIG_START_MONTH=6
+CONFIG_START_YEAR=2021
+CONFIG_STM32_COMP2=y
+CONFIG_STM32_COMP2_HYST=3
+CONFIG_STM32_COMP2_OUT=y
+CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y
+CONFIG_STM32_FORCEPOWER=y
+CONFIG_STM32_JTAG_FULL_ENABLE=y
+CONFIG_STM32_USART2=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_USART2_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="nsh_main"
diff --git a/boards/arm/stm32/nucleo-g431kb/include/board.h b/boards/arm/stm32/nucleo-g431kb/include/board.h
index 4729dc0..3798e59 100755
--- a/boards/arm/stm32/nucleo-g431kb/include/board.h
+++ b/boards/arm/stm32/nucleo-g431kb/include/board.h
@@ -234,6 +234,18 @@
#define GPIO_USART2_TX GPIO_USART2_TX_1 /* PA2 */
#define GPIO_USART2_RX GPIO_USART2_RX_1 /* PA3 */
+/* PWM configuration ********************************************************/
+
+/* TIM1 PWM */
+
+#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 /* PA8 */
+
+/* Comparators configuration ************************************************/
+
+#define GPIO_COMP2_OUT GPIO_COMP2_OUT_3 /* PA12 */
+#define GPIO_COMP2_INP GPIO_COMP2_INP_2 /* PA7 */
+#define GPIO_COMP2_INM GPIO_COMP2_INM_2 /* PA5 check solder bridge SB2 */
+
/* DMA channels *************************************************************/
/* USART2 */
@@ -241,10 +253,4 @@
#define DMACHAN_USART2_TX DMAMAP_DMA12_USART2TX_0 /* DMA1 */
#define DMACHAN_USART2_RX DMAMAP_DMA12_USART2RX_0 /* DMA1 */
-/* PWM configuration ********************************************************/
-
-/* TIM1 PWM */
-
-#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 /* PA8 */
-
#endif /* __BOARDS_ARM_STM32_NUCLEO_G431KB_INCLUDE_BOARD_H */
diff --git a/boards/arm/stm32/nucleo-g431kb/src/Make.defs b/boards/arm/stm32/nucleo-g431kb/src/Make.defs
index 22b1461..fce06a2 100755
--- a/boards/arm/stm32/nucleo-g431kb/src/Make.defs
+++ b/boards/arm/stm32/nucleo-g431kb/src/Make.defs
@@ -37,6 +37,10 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
+ifeq ($(CONFIG_STM32_COMP),y)
+CSRCS += stm32_comp.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 854ac09..609d10c 100755
--- a/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h
+++ b/boards/arm/stm32/nucleo-g431kb/src/nucleo-g431kb.h
@@ -102,4 +102,16 @@ int stm32_bringup(void);
int stm32_pwm_setup(void);
#endif
+/****************************************************************************
+ * Name: stm32_comp_setup
+ *
+ * Description:
+ * Initialize COMP peripheral for the board.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STM32_COMP
+int stm32_comp_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 11e8e59..fa504d7 100755
--- a/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c
+++ b/boards/arm/stm32/nucleo-g431kb/src/stm32_bringup.c
@@ -88,6 +88,16 @@ int stm32_bringup(void)
}
#endif
+#ifdef CONFIG_STM32_COMP
+ /* Initialize and register the COMP driver. */
+
+ ret = stm32_comp_setup();
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "ERROR: stm32_comp_setup failed: %d\n", ret);
+ }
+#endif
+
UNUSED(ret);
return OK;
}
diff --git a/boards/arm/stm32/nucleo-g431kb/src/stm32_comp.c b/boards/arm/stm32/nucleo-g431kb/src/stm32_comp.c
new file mode 100644
index 0000000..6a074bd
--- /dev/null
+++ b/boards/arm/stm32/nucleo-g431kb/src/stm32_comp.c
@@ -0,0 +1,146 @@
+/****************************************************************************
+ * boards/arm/stm32/nucleo-g431kb/src/stm32_comp.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 <nuttx/config.h>
+
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/board.h>
+#include <nuttx/analog/comp.h>
+
+#include "stm32.h"
+
+#if defined(CONFIG_STM32_COMP) && (defined(CONFIG_STM32_COMP1) || \
+ defined(CONFIG_STM32_COMP2) || \
+ defined(CONFIG_STM32_COMP3) || \
+ defined(CONFIG_STM32_COMP4))
+
+#ifdef CONFIG_STM32_COMP1
+# if defined(CONFIG_STM32_COMP2) || \
+ defined(CONFIG_STM32_COMP3) || \
+ defined(CONFIG_STM32_COMP4)
+# error "Currently only one COMP device supported"
+# endif
+#elif CONFIG_STM32_COMP2
+# if defined(CONFIG_STM32_COMP1) || \
+ defined(CONFIG_STM32_COMP3) || \
+ defined(CONFIG_STM32_COMP4)
+# error "Currently only one COMP device supported"
+# endif
+#elif CONFIG_STM32_COMP3
+# if defined(CONFIG_STM32_COMP1) || \
+ defined(CONFIG_STM32_COMP2) || \
+ defined(CONFIG_STM32_COMP4)
+# error "Currently only one COMP device supported"
+# endif
+#elif CONFIG_STM32_COMP4
+# if defined(CONFIG_STM32_COMP1) || \
+ defined(CONFIG_STM32_COMP2) || \
+ defined(CONFIG_STM32_COMP3)
+# error "Currently only one COMP device supported"
+# endif
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_comp_setup
+ *
+ * Description:
+ * Initialize COMP
+ *
+ ****************************************************************************/
+
+int stm32_comp_setup(void)
+{
+ static bool initialized = false;
+ struct comp_dev_s *comp = NULL;
+ int ret = OK;
+
+ if (!initialized)
+ {
+ /* Get the comparator interface */
+
+#ifdef CONFIG_STM32_COMP1
+ comp = stm32_compinitialize(1);
+ if (comp == NULL)
+ {
+ aerr("ERROR: Failed to get COMP%d interface\n", 1);
+ return -ENODEV;
+ }
+#endif
+
+#ifdef CONFIG_STM32_COMP2
+ comp = stm32_compinitialize(2);
+ if (comp == NULL)
+ {
+ aerr("ERROR: Failed to get COMP%d interface\n", 2);
+ return -ENODEV;
+ }
+#endif
+
+#ifdef CONFIG_STM32_COMP3
+ comp = stm32_compinitialize(3);
+ if (comp == NULL)
+ {
+ aerr("ERROR: Failed to get COMP%d interface\n", 3);
+ return -ENODEV;
+ }
+#endif
+
+#ifdef CONFIG_STM32_COMP4
+ comp = stm32_compinitialize(4);
+ if (comp == NULL)
+ {
+ aerr("ERROR: Failed to get COMP%d interface\n", 4);
+ return -ENODEV;
+ }
+#endif
+
+#ifdef CONFIG_COMP
+
+ /* Register the comparator character driver at /dev/comp0 */
+
+ ret = comp_register("/dev/comp0", comp);
+ if (ret < 0)
+ {
+ aerr("ERROR: comp_register failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ initialized = true;
+ }
+
+ return ret;
+}
+
+#endif /* CONFIG_COMP && (CONFIG_STM32_COMP1 ||
+ * CONFIG_STM32_COMP2 ||
+ * CONFIG_STM32_COMP3 ||
+ * CONFIG_STM32_COMP4) */