This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 944ed5ae0aa04f0b4c49c0346d971f382aa47402 Author: Matias Nitsche <[email protected]> AuthorDate: Fri May 8 16:37:11 2020 -0300 stm32: move NRF24L01 support into common board logic --- boards/arm/stm32/common/include/stm32_nrf24l01.h | 87 +++++++++++ boards/arm/stm32/common/src/Make.defs | 4 + boards/arm/stm32/common/src/stm32_nrf24l01.c | 162 +++++++++++++++++++++ .../stm32/stm32_tiny/src/{Makefile => Make.defs} | 9 +- boards/arm/stm32/stm32_tiny/src/stm32_appinit.c | 13 +- boards/arm/stm32/stm32_tiny/src/stm32_nrf24l01.c | 129 ---------------- boards/arm/stm32/stm32f103-minimum/src/Make.defs | 4 - .../stm32/stm32f103-minimum/src/stm32_bringup.c | 18 ++- .../stm32/stm32f103-minimum/src/stm32_nrf24l01.c | 147 ------------------- 9 files changed, 285 insertions(+), 288 deletions(-) diff --git a/boards/arm/stm32/common/include/stm32_nrf24l01.h b/boards/arm/stm32/common/include/stm32_nrf24l01.h new file mode 100644 index 0000000..76fcd1f --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_nrf24l01.h @@ -0,0 +1,87 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_nrf24l01.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __STM32_NRF24L01_H +#define __STM32_NRF24L01_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct board_nrf24l01_config_s +{ + uint32_t ce_pincfg; /* CE pin config */ + uint32_t irq_pincfg; /* IRQ pin config */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_nrf24l01_initialize + * + * Description: + * Initialize the NRF24L01 wireless module + * + * Input Parameters: + * cfg - Instance configuration data + * busno - The SPI bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_nrf24l01_initialize(FAR struct board_nrf24l01_config_s *cfg, + int busno); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_NRF24L01_H diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index f3a6e9f..eefbe31 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -50,6 +50,10 @@ ifeq ($(CONFIG_SENSORS_LM75),y) CSRCS += stm32_lm75.c endif +ifeq ($(CONFIG_WL_NRF24L01),y) + CSRCS += stm32_nrf24l01.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/boards/arm/stm32/common/src/stm32_nrf24l01.c b/boards/arm/stm32/common/src/stm32_nrf24l01.c new file mode 100644 index 0000000..66cbe86 --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_nrf24l01.c @@ -0,0 +1,162 @@ +/**************************************************************************** +* boards/arm/stm32/stm32f103-minimum//src/stm32_nrf24l01.c +* +* Copyright (C) 2017 Gregory Nutt. All rights reserved. +* Author: Laurent Latil <[email protected]> +* +* 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> +#include <debug.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> + +#include <nuttx/spi/spi.h> +#include <nuttx/wireless/nrf24l01.h> +#include <arch/board/board.h> + +#include "arm_arch.h" +#include "chip.h" +#include "stm32.h" +#include "stm32_nrf24l01.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int nrf24l01_irq_attach(xcpt_t isr, FAR void *arg); +static void nrf24l01_chip_enable(bool enable); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static FAR struct nrf24l01_config_s nrf_cfg = +{ + .irqattach = nrf24l01_irq_attach, + .chipenable = nrf24l01_chip_enable, +}; + +static xcpt_t g_isr; +static FAR void *g_arg; + +struct board_nrf24l01_config_s g_cfg; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int nrf24l01_irq_attach(xcpt_t isr, FAR void *arg) +{ + wlinfo("Attach IRQ\n"); + g_isr = isr; + g_arg = arg; + stm32_gpiosetevent(g_cfg.irq_pincfg, false, true, false, g_isr, g_arg); + return OK; +} + +static void nrf24l01_chip_enable(bool enable) +{ + wlinfo("CE:%d\n", enable); + stm32_gpiowrite(g_cfg.ce_pincfg, enable); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_nrf24l01_initialize + * + * Description: + * Initialize the NRF24L01 wireless module + * + * Input Parameters: + * cfg - Instance configuration data + * busno - The SPI bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_nrf24l01_initialize(FAR struct board_nrf24l01_config_s *cfg, + int busno) +{ + FAR struct spi_dev_s *spidev; + int result; + + DEBUGASSERT(cfg); + + memcpy(&g_cfg, cfg, sizeof(g_cfg)); + + /* Setup CE & IRQ line IOs */ + + stm32_configgpio(g_cfg.ce_pincfg); + stm32_configgpio(g_cfg.irq_pincfg); + + /* Init SPI bus */ + + spidev = stm32_spibus_initialize(busno); + if (!spidev) + { + wlerr("ERROR: Failed to initialize SPI bus\n"); + return -ENODEV; + } + + result = nrf24l01_register(spidev, &nrf_cfg); + if (result != OK) + { + wlerr("ERROR: Failed to register initialize SPI bus\n"); + return -ENODEV; + } + + return OK; +} diff --git a/boards/arm/stm32/stm32_tiny/src/Makefile b/boards/arm/stm32/stm32_tiny/src/Make.defs similarity index 92% rename from boards/arm/stm32/stm32_tiny/src/Makefile rename to boards/arm/stm32/stm32_tiny/src/Make.defs index cbf94d9..0ec9bfd 100644 --- a/boards/arm/stm32/stm32_tiny/src/Makefile +++ b/boards/arm/stm32/stm32_tiny/src/Make.defs @@ -43,12 +43,11 @@ ifeq ($(CONFIG_PWM),y) CSRCS += stm32_pwm.c endif -ifeq ($(CONFIG_WL_NRF24L01),y) -CSRCS += stm32_nrf24l01.c -endif - ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += stm32_appinit.c endif -include $(TOPDIR)/boards/Board.mk +DEPPATH += --dep-path board +VPATH += :board +CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board) + diff --git a/boards/arm/stm32/stm32_tiny/src/stm32_appinit.c b/boards/arm/stm32/stm32_tiny/src/stm32_appinit.c index 8987c9a..7dd4b78 100644 --- a/boards/arm/stm32/stm32_tiny/src/stm32_appinit.c +++ b/boards/arm/stm32/stm32_tiny/src/stm32_appinit.c @@ -49,6 +49,10 @@ #include "stm32.h" #include "stm32_tiny.h" +#ifdef CONFIG_WL_NRF24L01 +#include "stm32_nrf24l01.h" +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,8 +97,13 @@ int board_app_initialize(uintptr_t arg) #endif #if defined(CONFIG_WL_NRF24L01) - syslog(LOG_INFO, "Register the nRF24L01 module"); - stm32_wlinitialize(); + /* Initialize the NRF24L01 wireless module */ + + ret = board_nrf24l01_initialize(&g_nrf24l01_cfg, 2); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: board_nrf24l01_initialize failed: %d\n", ret); + } #endif return OK; diff --git a/boards/arm/stm32/stm32_tiny/src/stm32_nrf24l01.c b/boards/arm/stm32/stm32_tiny/src/stm32_nrf24l01.c deleted file mode 100644 index 53164c3..0000000 --- a/boards/arm/stm32/stm32_tiny/src/stm32_nrf24l01.c +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32_tiny/src/stm32_nrf24l01.c - * - * Copyright (C) 2009, 2013, 2017 Gregory Nutt. All rights reserved. - * Author: Laurent Latil <[email protected]> - * - * 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 <nuttx/config.h> - -#include <stdint.h> -#include <stdbool.h> -#include <debug.h> -#include <errno.h> - -#include <nuttx/spi/spi.h> -#include <nuttx/wireless/nrf24l01.h> -#include <arch/board/board.h> - -#include "arm_arch.h" -#include "chip.h" -#include "stm32.h" -#include "stm32_tiny.h" - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg); - -static void stm32tiny_wl_chip_enable(bool enable); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static FAR struct nrf24l01_config_s nrf_cfg = -{ - .irqattach = stm32tiny_wl_irq_attach, - .chipenable = stm32tiny_wl_chip_enable, -}; - -static xcpt_t g_isr; -static FAR void *g_arg; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) -{ - _info("Attach IRQ\n"); - g_isr = isr; - g_arg = arg; - stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); - return OK; -} - -static void stm32tiny_wl_chip_enable(bool enable) -{ - _info("CE:%d\n", enable); - stm32_gpiowrite(GPIO_NRF24L01_CE, enable); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void stm32_wlinitialize(void) -{ -# ifndef CONFIG_STM32_SPI2 -# error "STM32_SPI2 is required to support nRF24L01 module on this board" -# endif - - int result; - FAR struct spi_dev_s *spidev; - - /* Setup CE & IRQ line IOs */ - - stm32_configgpio(GPIO_NRF24L01_CE); - stm32_configgpio(GPIO_NRF24L01_IRQ); - - /* Init SPI bus */ - - spidev = stm32_spibus_initialize(2); - if (!spidev) - { - _err("ERROR: Failed to initialize SPI bus\n"); - return; - } - - result = nrf24l01_register(spidev, &nrf_cfg); - if (result != OK) - { - _err("ERROR: Failed to register initialize SPI bus\n"); - return; - } -} diff --git a/boards/arm/stm32/stm32f103-minimum/src/Make.defs b/boards/arm/stm32/stm32f103-minimum/src/Make.defs index 25fd424..b9bf930 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/Make.defs +++ b/boards/arm/stm32/stm32f103-minimum/src/Make.defs @@ -131,10 +131,6 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y) CSRCS += stm32_qencoder.c endif -ifeq ($(CONFIG_WL_NRF24L01),y) - CSRCS += stm32_nrf24l01.c -endif - ifeq ($(CONFIG_USBDEV),y) CSRCS += stm32_usbdev.c endif diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c index 5872544..ebaa47d 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c @@ -113,6 +113,10 @@ #include "stm32_lm75.h" #endif +#ifdef CONFIG_WL_NRF24L01 +#include "stm32_nrf24l01.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -160,6 +164,14 @@ struct board_tone_config_s g_tone_cfg = }; #endif +#ifdef CONFIG_WL_NRF24L01 +struct board_nrf24l01_config_s g_nrf24l01_cfg = +{ + .ce_pincfg = GPIO_NRF24L01_CE, + .irq_pincfg = GPIO_NRF24L01_IRQ +}; +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -448,7 +460,11 @@ int stm32_bringup(void) #if defined(CONFIG_WL_NRF24L01) /* Initialize the NRF24L01 wireless module */ - stm32_wlinitialize(); + ret = board_nrf24l01_initialize(&g_nrf24l01_cfg, 1); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: board_nrf24l01_initialize failed: %d\n", ret); + } #endif return ret; diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_nrf24l01.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_nrf24l01.c deleted file mode 100644 index 010a729..0000000 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_nrf24l01.c +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** - * boards/arm/stm32/stm32f103-minimum//src/stm32_nrf24l01.c - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Laurent Latil <[email protected]> - * - * 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 <nuttx/config.h> - -#include <stdint.h> -#include <stdbool.h> -#include <debug.h> -#include <errno.h> - -#include <nuttx/spi/spi.h> -#include <nuttx/wireless/nrf24l01.h> -#include <arch/board/board.h> - -#include "arm_arch.h" -#include "chip.h" -#include "stm32.h" - -#include "stm32f103_minimum.h" - -#ifdef CONFIG_WL_NRF24L01 - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg); -static void stm32tiny_wl_chip_enable(bool enable); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static FAR struct nrf24l01_config_s nrf_cfg = -{ - .irqattach = stm32tiny_wl_irq_attach, - .chipenable = stm32tiny_wl_chip_enable, -}; - -static xcpt_t g_isr; -static FAR void *g_arg; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) -{ - wlinfo("Attach IRQ\n"); - g_isr = isr; - g_arg = arg; - stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); - return OK; -} - -static void stm32tiny_wl_chip_enable(bool enable) -{ - wlinfo("CE:%d\n", enable); - stm32_gpiowrite(GPIO_NRF24L01_CE, enable); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_wlinitialize - * - * Description: - * Initialize the NRF24L01 wireless module - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void stm32_wlinitialize(void) -{ -#ifndef CONFIG_STM32_SPI1 -# error "STM32_SPI1 is required to support nRF24L01 module on this board" -#endif - - FAR struct spi_dev_s *spidev; - int result; - - /* Setup CE & IRQ line IOs */ - - stm32_configgpio(GPIO_NRF24L01_CE); - stm32_configgpio(GPIO_NRF24L01_IRQ); - - /* Init SPI bus */ - - spidev = stm32_spibus_initialize(1); - if (!spidev) - { - wlerr("ERROR: Failed to initialize SPI bus\n"); - return; - } - - result = nrf24l01_register(spidev, &nrf_cfg); - if (result != OK) - { - wlerr("ERROR: Failed to register initialize SPI bus\n"); - return; - } -} - -#endif /* CONFIG_WL_NRF24L01 */
