Add nucleo-g431kb Analog Comparator example.

This commit is contained in:
Daniel P. Carvalho 2021-07-07 15:00:27 -03:00 committed by Alan Carvalho de Assis
parent 2a21c45e0a
commit 59b2ed4210
6 changed files with 228 additions and 6 deletions

View File

@ -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"

View File

@ -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 */

View File

@ -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)

View File

@ -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 */

View File

@ -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;
}

View File

@ -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) */