boards/arm/stm32/nucleo-f446re: added support for GPIO driver
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
parent
6c67b560b4
commit
02d42e4f03
@ -559,6 +559,16 @@ Configurations
|
||||
Functionality of CAN driver can be tested by calling application
|
||||
"can" in NuttShell. This application sends 100 messages over CAN 1.
|
||||
|
||||
gpio:
|
||||
-----
|
||||
This is an nsh configuration (see above) with added support for GPIO
|
||||
driver and GPIO test application "gpio". Three pins are configured for
|
||||
testing purposes:
|
||||
|
||||
PA_7 - GPIO_INPUT
|
||||
PB_6 - GPIO_OUTPUT
|
||||
PC_7 - GPIO_INPUT_INTERRUPT
|
||||
|
||||
ihm08m1_f32 and ihm08m1_b16:
|
||||
----------------------------
|
||||
|
||||
|
56
boards/arm/stm32/nucleo-f446re/configs/gpio/defconfig
Normal file
56
boards/arm/stm32/nucleo-f446re/configs/gpio/defconfig
Normal file
@ -0,0 +1,56 @@
|
||||
#
|
||||
# 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_NSH_DISABLE_IFCONFIG is not set
|
||||
# CONFIG_NSH_DISABLE_PS is not set
|
||||
# CONFIG_STM32_FLASH_PREFETCH is not set
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-f446re"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_F446RE=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32"
|
||||
CONFIG_ARCH_CHIP_STM32=y
|
||||
CONFIG_ARCH_CHIP_STM32F446R=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARD_LATE_INITIALIZE=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=8499
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEV_GPIO=y
|
||||
CONFIG_EXAMPLES_GPIO=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=131072
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=14
|
||||
CONFIG_START_MONTH=10
|
||||
CONFIG_START_YEAR=2014
|
||||
CONFIG_STM32_CRC=y
|
||||
CONFIG_STM32_JTAG_SW_ENABLE=y
|
||||
CONFIG_STM32_OTGFS=y
|
||||
CONFIG_STM32_PWR=y
|
||||
CONFIG_STM32_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=0
|
||||
CONFIG_TESTING_OSTEST=y
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -53,6 +53,10 @@ ifeq ($(CONFIG_STM32_PWM),y)
|
||||
CSRCS += stm32_pwm.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEV_GPIO),y)
|
||||
CSRCS += stm32_gpio.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += stm32_appinit.c
|
||||
endif
|
||||
|
@ -192,6 +192,19 @@
|
||||
#define GPIO_BUTTON_G \
|
||||
(GPIO_INPUT | GPIO_PULLUP |GPIO_EXTI | GPIO_PORTC | GPIO_PIN7)
|
||||
|
||||
/* GPIO pins used by the GPIO Subsystem */
|
||||
|
||||
#define BOARD_NGPIOIN 1 /* Amount of GPIO Input pins */
|
||||
#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */
|
||||
#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */
|
||||
|
||||
#define GPIO_IN1 (GPIO_INPUT | GPIO_PULLDOWN | GPIO_SPEED_2MHz | \
|
||||
GPIO_PORTA | GPIO_PIN7)
|
||||
#define GPIO_OUT1 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHz | \
|
||||
GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN6)
|
||||
#define GPIO_INT1 (GPIO_INPUT | GPIO_PULLDOWN | GPIO_SPEED_2MHz | \
|
||||
GPIO_PORTC | GPIO_PIN7)
|
||||
|
||||
/* Itead Joystick Signal interpretation:
|
||||
*
|
||||
* --------- ----------------------- ---------------------------
|
||||
@ -345,4 +358,19 @@ int stm32_foc_setup(void);
|
||||
int stm32_pwm_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_gpio_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize GPIO drivers for use with /apps/examples/gpio
|
||||
*
|
||||
* Return Value:
|
||||
* OK on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEV_GPIO
|
||||
int stm32_gpio_initialize(void);
|
||||
#endif
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_NUCLEO_F401RE_SRC_NUCLEO_F446RE_H */
|
||||
|
@ -192,5 +192,15 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DEV_GPIO
|
||||
/* Initialize GPIO driver */
|
||||
|
||||
ret = stm32_gpio_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_gpio_initialize() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
341
boards/arm/stm32/nucleo-f446re/src/stm32_gpio.c
Normal file
341
boards/arm/stm32/nucleo-f446re/src/stm32_gpio.c
Normal file
@ -0,0 +1,341 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/nucleo-f446re/src/stm32_gpio.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 <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/ioexpander/gpio.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "chip.h"
|
||||
#include "stm32.h"
|
||||
#include "nucleo-f446re.h"
|
||||
|
||||
#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct stm32gpio_dev_s
|
||||
{
|
||||
struct gpio_dev_s gpio;
|
||||
uint8_t id;
|
||||
};
|
||||
|
||||
struct stm32gpint_dev_s
|
||||
{
|
||||
struct stm32gpio_dev_s stm32gpio;
|
||||
pin_interrupt_t callback;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if BOARD_NGPIOIN > 0
|
||||
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value);
|
||||
#endif
|
||||
#if BOARD_NGPIOOUT > 0
|
||||
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value);
|
||||
static int gpout_write(FAR struct gpio_dev_s *dev, bool value);
|
||||
#endif
|
||||
#if BOARD_NGPIOINT > 0
|
||||
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value);
|
||||
static int gpint_attach(FAR struct gpio_dev_s *dev,
|
||||
pin_interrupt_t callback);
|
||||
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#if BOARD_NGPIOIN > 0
|
||||
static const struct gpio_operations_s gpin_ops =
|
||||
{
|
||||
.go_read = gpin_read,
|
||||
.go_write = NULL,
|
||||
.go_attach = NULL,
|
||||
.go_enable = NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOOUT > 0
|
||||
static const struct gpio_operations_s gpout_ops =
|
||||
{
|
||||
.go_read = gpout_read,
|
||||
.go_write = gpout_write,
|
||||
.go_attach = NULL,
|
||||
.go_enable = NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOINT > 0
|
||||
static const struct gpio_operations_s gpint_ops =
|
||||
{
|
||||
.go_read = gpint_read,
|
||||
.go_write = NULL,
|
||||
.go_attach = gpint_attach,
|
||||
.go_enable = gpint_enable,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOIN > 0
|
||||
/* This array maps the GPIO pins used as INPUT */
|
||||
|
||||
static const uint32_t g_gpioinputs[BOARD_NGPIOIN] =
|
||||
{
|
||||
GPIO_IN1,
|
||||
};
|
||||
|
||||
static struct stm32gpio_dev_s g_gpin[BOARD_NGPIOIN];
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOOUT
|
||||
/* This array maps the GPIO pins used as OUTPUT */
|
||||
|
||||
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
|
||||
{
|
||||
GPIO_OUT1,
|
||||
};
|
||||
|
||||
static struct stm32gpio_dev_s g_gpout[BOARD_NGPIOOUT];
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOINT > 0
|
||||
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
|
||||
|
||||
static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] =
|
||||
{
|
||||
GPIO_INT1,
|
||||
};
|
||||
|
||||
static struct stm32gpint_dev_s g_gpint[BOARD_NGPIOINT];
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#if BOARD_NGPIOINT > 0
|
||||
static int stm32gpio_interrupt(int irq, void *context, void *arg)
|
||||
{
|
||||
FAR struct stm32gpint_dev_s *stm32gpint =
|
||||
(FAR struct stm32gpint_dev_s *)arg;
|
||||
|
||||
DEBUGASSERT(stm32gpint != NULL && stm32gpint->callback != NULL);
|
||||
gpioinfo("Interrupt! callback=%p\n", stm32gpint->callback);
|
||||
|
||||
stm32gpint->callback(&stm32gpint->stm32gpio.gpio,
|
||||
stm32gpint->stm32gpio.id);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOIN > 0
|
||||
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value)
|
||||
{
|
||||
FAR struct stm32gpio_dev_s *stm32gpio =
|
||||
(FAR struct stm32gpio_dev_s *)dev;
|
||||
|
||||
DEBUGASSERT(stm32gpio != NULL && value != NULL);
|
||||
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOIN);
|
||||
gpioinfo("Reading...\n");
|
||||
|
||||
*value = stm32_gpioread(g_gpioinputs[stm32gpio->id]);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOOUT > 0
|
||||
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value)
|
||||
{
|
||||
FAR struct stm32gpio_dev_s *stm32gpio =
|
||||
(FAR struct stm32gpio_dev_s *)dev;
|
||||
|
||||
DEBUGASSERT(stm32gpio != NULL && value != NULL);
|
||||
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
|
||||
gpioinfo("Reading...\n");
|
||||
|
||||
*value = stm32_gpioread(g_gpiooutputs[stm32gpio->id]);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int gpout_write(FAR struct gpio_dev_s *dev, bool value)
|
||||
{
|
||||
FAR struct stm32gpio_dev_s *stm32gpio =
|
||||
(FAR struct stm32gpio_dev_s *)dev;
|
||||
|
||||
DEBUGASSERT(stm32gpio != NULL);
|
||||
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
|
||||
gpioinfo("Writing %d\n", (int)value);
|
||||
|
||||
stm32_gpiowrite(g_gpiooutputs[stm32gpio->id], value);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOINT > 0
|
||||
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value)
|
||||
{
|
||||
FAR struct stm32gpint_dev_s *stm32gpint =
|
||||
(FAR struct stm32gpint_dev_s *)dev;
|
||||
|
||||
DEBUGASSERT(stm32gpint != NULL && value != NULL);
|
||||
DEBUGASSERT(stm32gpint->stm32gpio.id < BOARD_NGPIOINT);
|
||||
gpioinfo("Reading int pin...\n");
|
||||
|
||||
*value = stm32_gpioread(g_gpiointinputs[stm32gpint->stm32gpio.id]);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int gpint_attach(FAR struct gpio_dev_s *dev,
|
||||
pin_interrupt_t callback)
|
||||
{
|
||||
FAR struct stm32gpint_dev_s *stm32gpint =
|
||||
(FAR struct stm32gpint_dev_s *)dev;
|
||||
|
||||
gpioinfo("Attaching the callback\n");
|
||||
|
||||
/* Make sure the interrupt is disabled */
|
||||
|
||||
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id], false,
|
||||
false, false, NULL, NULL);
|
||||
|
||||
gpioinfo("Attach %p\n", callback);
|
||||
stm32gpint->callback = callback;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)
|
||||
{
|
||||
FAR struct stm32gpint_dev_s *stm32gpint =
|
||||
(FAR struct stm32gpint_dev_s *)dev;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if (stm32gpint->callback != NULL)
|
||||
{
|
||||
gpioinfo("Enabling the interrupt\n");
|
||||
|
||||
/* Configure the interrupt for rising edge */
|
||||
|
||||
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id],
|
||||
true, false, false, stm32gpio_interrupt,
|
||||
&g_gpint[stm32gpint->stm32gpio.id]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gpioinfo("Disable the interrupt\n");
|
||||
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id],
|
||||
false, false, false, NULL, NULL);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_gpio_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize GPIO drivers for use with /apps/examples/gpio
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_gpio_initialize(void)
|
||||
{
|
||||
int i;
|
||||
int pincount = 0;
|
||||
|
||||
#if BOARD_NGPIOIN > 0
|
||||
for (i = 0; i < BOARD_NGPIOIN; i++)
|
||||
{
|
||||
/* Setup and register the GPIO pin */
|
||||
|
||||
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN;
|
||||
g_gpin[i].gpio.gp_ops = &gpin_ops;
|
||||
g_gpin[i].id = i;
|
||||
gpio_pin_register(&g_gpin[i].gpio, pincount);
|
||||
|
||||
/* Configure the pin that will be used as input */
|
||||
|
||||
stm32_configgpio(g_gpioinputs[i]);
|
||||
|
||||
pincount++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOOUT > 0
|
||||
for (i = 0; i < BOARD_NGPIOOUT; i++)
|
||||
{
|
||||
/* Setup and register the GPIO pin */
|
||||
|
||||
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
|
||||
g_gpout[i].gpio.gp_ops = &gpout_ops;
|
||||
g_gpout[i].id = i;
|
||||
gpio_pin_register(&g_gpout[i].gpio, pincount);
|
||||
|
||||
/* Configure the pin that will be used as output */
|
||||
|
||||
stm32_gpiowrite(g_gpiooutputs[i], 0);
|
||||
stm32_configgpio(g_gpiooutputs[i]);
|
||||
|
||||
pincount++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_NGPIOINT > 0
|
||||
for (i = 0; i < BOARD_NGPIOINT; i++)
|
||||
{
|
||||
/* Setup and register the GPIO pin */
|
||||
|
||||
g_gpint[i].stm32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
|
||||
g_gpint[i].stm32gpio.gpio.gp_ops = &gpint_ops;
|
||||
g_gpint[i].stm32gpio.id = i;
|
||||
gpio_pin_register(&g_gpint[i].stm32gpio.gpio, pincount);
|
||||
|
||||
/* Configure the pin that will be used as interrupt input */
|
||||
|
||||
stm32_configgpio(g_gpiointinputs[i]);
|
||||
|
||||
pincount++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */
|
Loading…
x
Reference in New Issue
Block a user