Clicker2-STM32: Add framework for MRF24J40 support. Untested and still some missing logic.
This commit is contained in:
parent
0be851d339
commit
22651dcae2
@ -21,4 +21,20 @@ config CLICKER2_STM32_MB2_SPI
|
||||
---help---
|
||||
Enable SPI support on mikroBUS1 (STM32 SPI2)
|
||||
|
||||
config CLICKER2_STM32_MB1_BEE
|
||||
bool "mikroBUS1 MRF24J40 BEE"
|
||||
default y
|
||||
depends on IEEE802154_MRF24J40
|
||||
select CLICKER2_STM32_MB1_SPI
|
||||
---help---
|
||||
Enable support for MRF24J40 BEE on mikroBUS1
|
||||
|
||||
config CLICKER2_STM32_MB2_BEE
|
||||
bool "mikroBUS2 MRF24J40 BEE"
|
||||
default n
|
||||
depends on IEEE802154_MRF24J40
|
||||
select CLICKER2_STM32_MB2_SPI
|
||||
---help---
|
||||
Enable support for MRF24J40 BEE on mikroBUS2
|
||||
|
||||
endif # ARCH_BOARD_CLICKER2_STM32
|
||||
|
@ -56,6 +56,10 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += stm32_appinit.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_IEEE802154_MRF24J40),y)
|
||||
CSRCS += stm32_mrf24j40.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADC),y)
|
||||
CSRCS += stm32_adc.c
|
||||
endif
|
||||
|
@ -286,5 +286,21 @@ int stm32_adc_setup(void);
|
||||
int stm32_can_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_mrf24j40_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the MRF24J40 device.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE)
|
||||
int stm32_mrf24j40_initialize(void)
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_OLIMEX_STM32_P407_SRC_H */
|
||||
|
@ -153,6 +153,16 @@ int stm32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE)
|
||||
/* Configure MRF24J40 wireless */
|
||||
|
||||
ret = stm32_mrf24j40_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_mrf24j40_initialize() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BUTTONS
|
||||
/* Register the BUTTON driver */
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_exti.h"
|
||||
|
||||
#include "clicker2-stm32.h"
|
||||
|
||||
|
291
configs/clicker2-stm32/src/stm32_mrf24j40.c
Normal file
291
configs/clicker2-stm32/src/stm32_mrf24j40.c
Normal file
@ -0,0 +1,291 @@
|
||||
/****************************************************************************
|
||||
* configs/freedom-kl25z/src/stm32_mrf24j40.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt, All rights reserver
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/wireless/ieee80154/mrf24j40.h>
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_exti.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
#include "clicker2-stm32.h"
|
||||
|
||||
#ifdef CONFIG_IEEE802154_MRF24J40
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DRIVERS_WIRELESS
|
||||
# error Wireless support requires CONFIG_DRIVERS_WIRELESS
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_CLICKER2_STM32_MB1_BEE) && !defined(CONFIG_CLICKER2_STM32_MB2_BEE)
|
||||
# error Only the Mikroe BEE board is supported
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB1_BEE
|
||||
# ifndef CONFIG_STM32_SPI3
|
||||
# error Mikroe BEE on mikroBUS1 requires CONFIG_STM32_SPI3
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB2_BEE
|
||||
# ifndef CONFIG_STM32_SPI2
|
||||
# error Mikroe BEE on mikroBUS1 requires CONFIG_STM32_SPI2
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct stm32_priv_s
|
||||
{
|
||||
struct mrf24j40_lower_s dev;
|
||||
xcpt_t handler;
|
||||
uint32_t intcfg;
|
||||
uint8_t spidev;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks
|
||||
* to isolate the MRF24J40 driver from differences in GPIO interrupt handling
|
||||
* varying boards and MCUs.
|
||||
*
|
||||
* irq_attach - Attach the MRF24J40 interrupt handler to the GPIO
|
||||
interrupt
|
||||
* irq_enable - Enable or disable the GPIO interrupt
|
||||
*/
|
||||
|
||||
static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
|
||||
xcpt_t handler);
|
||||
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower,
|
||||
int state);
|
||||
static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)'
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* A reference to a structure of this type must be passed to the MRF24J40
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the MRF24J40 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active. The
|
||||
* memory must be writable because, under certain circumstances, the driver
|
||||
* may modify frequency or X plate resistance values.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB1_BEE
|
||||
static struct stm32_priv_s g_mrf24j40_mb1_priv =
|
||||
{
|
||||
.dev.attach = stm32_attach_irq,
|
||||
.dev.enable = stm32_enable_irq,
|
||||
.handler = NULL,
|
||||
.intcfg = GPIO_MB1_INT,
|
||||
.spidev = 3,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB2_BEE
|
||||
static struct stm32_priv_s g_mrf24j40_mb2_priv =
|
||||
{
|
||||
.dev.attach = stm32_attach_irq,
|
||||
.dev.enable = stm32_enable_irq,
|
||||
.uint32_t = GPIO_MB2_INT,
|
||||
.spidev = 2,
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the MRF24J40 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs. If possible,
|
||||
* interrupts should be configured on both rising and falling edges
|
||||
* so that contact and loss-of-contact events can be detected.
|
||||
*
|
||||
* irq_attach - Attach the MRF24J40 interrupt handler to the GPIO
|
||||
* interrupt
|
||||
* irq_enable - Enable or disable the GPIO interrupt
|
||||
*/
|
||||
|
||||
static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower,
|
||||
xcpt_t handler)
|
||||
{
|
||||
FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower;
|
||||
|
||||
DEBUASSERT(priv != NULL);
|
||||
|
||||
/* Just save the handler for use when the interrupt is enabled */
|
||||
|
||||
priv->handler = handler;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state)
|
||||
{
|
||||
FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower;
|
||||
|
||||
/* The caller should not attempt to enable interrupts if the handler
|
||||
* has not yet been 'attached'
|
||||
*/
|
||||
|
||||
DEBUGASSERT(priv != NULL && (priv->handler != NULL || state == 0));
|
||||
|
||||
/* Attach and enable, or detach and disable */
|
||||
|
||||
wlinfo("state:%d\n", state);
|
||||
if (state != 0)
|
||||
{
|
||||
(void)stm32_gpiosetevent(priv->intcfg, true, true, true,
|
||||
priv->handler, lower);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)stm32_gpiosetevent(priv->intcfg, false, false, false,
|
||||
NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_mrf24j40_devsetup
|
||||
*
|
||||
* Description:
|
||||
* Initialize one the MRF24J40 device in one mikroBUS slot
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)
|
||||
{
|
||||
FAR struct ieee802154_radio_s *radio;
|
||||
FAR struct spi_dev_s *spi;
|
||||
|
||||
/* Configure the interrupt pin */
|
||||
|
||||
stm32_configgpio(priv->intcfg);
|
||||
|
||||
/* Initialize the SPI bus and get an instance of the SPI interface */
|
||||
|
||||
spi = stm32_spibus_initialize(priv->spidev);
|
||||
if (spi == NULL)
|
||||
{
|
||||
wlerr("ERROR: Failed to initialize SPI bus %d\n", priv->spidev);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Initialize and register the SPI MRF24J40 device */
|
||||
|
||||
radio = mrf24j40_init(spi, &priv->dev);
|
||||
if (radio == NULL)
|
||||
{
|
||||
wlerr("ERROR: Failed to initialize SPI bus %d\n", priv->spidev);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Now.. do what with the MRF24J40 instance? */
|
||||
#warning Missing logic
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_mrf24j40_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the MRF24J40 device.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_mrf24j40_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB1_BEE
|
||||
wlinfo("Configuring BEE in mikroBUS1\n");
|
||||
|
||||
ret = stm32_mrf24j40_devsetup(&g_mrf24j40_mb1_priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: Failed to initialize BD in mikroBUS1: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLICKER2_STM32_MB2_BEE
|
||||
wlinfo("Configuring BEE in mikroBUS2\n");
|
||||
|
||||
ret = stm32_mrf24j40_devsetup(&g_mrf24j40_mb2_priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: Failed to initialize BD in mikroBUS2: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
#endif /* CONFIG_IEEE802154_MRF24J40 */
|
@ -52,12 +52,12 @@
|
||||
*
|
||||
* The MRF24J40 interrupt is an active low, *level* interrupt. From Datasheet:
|
||||
* "Note 1: The INTEDGE polarity defaults to:
|
||||
* 0 = Falling Edge. Ensure that the inter-
|
||||
* rupt polarity matches the interrupt pin
|
||||
* polarity of the host microcontroller.
|
||||
* Note 2: The INT pin will remain high or low,
|
||||
* depending on INTEDGE polarity setting,
|
||||
* until INTSTAT register is read."
|
||||
*
|
||||
* 0 = Falling Edge. Ensure that the interrupt polarity matches the
|
||||
* interrupt pin polarity of the host microcontroller.
|
||||
*
|
||||
* Note 2: The INT pin will remain high or low, depending on INTEDGE
|
||||
* polarity setting, until INTSTAT register is read."
|
||||
*/
|
||||
|
||||
struct mrf24j40_lower_s
|
||||
|
Loading…
Reference in New Issue
Block a user