Add support for NuttX controlled LEDS and for board_initialize. Separate initialize logic to stm32_bringup.c so that in initialization can occur either through board_initialize() or through board_app_initialize(). Same as with most other newer board configurations.

This commit is contained in:
Gregory Nutt 2017-04-09 09:19:25 -06:00
parent 55b32430e1
commit dedc3c15d4
12 changed files with 362 additions and 103 deletions

View File

@ -152,11 +152,44 @@
#undef BOARD_ENABLE_USBOTG_HSULPI
/* LED definitions ******************************************************************/
/* LEDs
*
* A single LED is available driven by PA13.
*/
/* LED index values for use with board_userled() */
#define BOARD_LED1 0
#define BOARD_NLEDS 1
/* LED bits for use with board_userled_all() */
#define BOARD_LED1_BIT (1 << BOARD_LED1)
/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/sam_autoleds.c. The LEDs are used to encode
* OS-related events as follows:
*
* ------------------- ---------------------------- ------
* SYMBOL Meaning LED
* ------------------- ---------------------------- ------ */
#define LED_STARTED 0 /* NuttX has been started OFF */
#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */
#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */
#define LED_STACKCREATED 1 /* Idle stack created ON */
#define LED_INIRQ 2 /* In an interrupt N/C */
#define LED_SIGNAL 2 /* In a signal handler N/C */
#define LED_ASSERTION 2 /* An assertion failed N/C */
#define LED_PANIC 3 /* The system has crashed FLASH */
#undef LED_IDLE /* MCU is is sleep mode Not used */
/* Thus if LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/* Button definitions ***************************************************************/
#define BOARD_BUTTON1 0

View File

@ -35,18 +35,24 @@
-include $(TOPDIR)/Make.defs
ASRCS =
CSRCS = stm32_boot.c
CSRCS = stm32_boot.c stm32_bringup.c
ifeq ($(CONFIG_PHOTON_DFU_BOOTLOADER),y)
CSRCS += dfu_signature.c
endif
ifeq ($(CONFIG_LIB_BOARDCTL),y)
CSRCS += stm32_appinit.c
endif
ifeq ($(CONFIG_BUTTONS),y)
CSRCS += stm32_buttons.c
endif
ifeq ($(CONFIG_USERLED),y)
CSRCS += stm32_leds.c
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
else
CSRCS += stm32_userleds.c
endif
ifeq ($(CONFIG_PHOTON_WDG),y)
@ -61,8 +67,4 @@ ifeq ($(CONFIG_STM32_OTGHS),y)
CSRCS += stm32_usb.c
endif
ifeq ($(CONFIG_NSH_LIBRARY),y)
CSRCS += stm32_appinit.c
endif
include $(TOPDIR)/configs/Board.mk

View File

@ -89,6 +89,21 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_bringup
*
* Description:
* Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by
* board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function
* initializes and configures all on-board features appropriate for the
* selected configuration.
*
****************************************************************************/
#if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE)
int stm32_bringup(void);
#endif
/****************************************************************************
* Name: photon_watchdog_initialize()
*

View File

@ -2,7 +2,7 @@
* config/photon/src/stm32_appinit.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Simon Piriou <spiriou31@gmail.com>
* 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
@ -38,23 +38,14 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include <syslog.h>
#include <sys/types.h>
#include <nuttx/board.h>
#include "photon.h"
#include "stm32_wdg.h"
#include <nuttx/input/buttons.h>
#include <nuttx/leds/userled.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef OK
# define OK 0
#endif
#ifdef CONFIG_LIB_BOARDCTL
/****************************************************************************
* Public Functions
@ -87,65 +78,13 @@
int board_app_initialize(uintptr_t arg)
{
int ret = OK;
#ifndef CONFIG_BOARD_INITIALIZE
/* Perform board initialization */
#ifdef CONFIG_USERLED
#ifdef CONFIG_USERLED_LOWER
/* Register the LED driver */
ret = userled_lower_initialize("/dev/userleds");
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
return ret;
}
return stm32_bringup();
#else
board_userled_initialize();
#endif /* CONFIG_USERLED_LOWER */
#endif /* CONFIG_USERLED */
#ifdef CONFIG_BUTTONS
#ifdef CONFIG_BUTTONS_LOWER
/* Register the BUTTON driver */
ret = btn_lower_initialize("/dev/buttons");
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
return ret;
}
#else
board_button_initialize();
#endif /* CONFIG_BUTTONS_LOWER */
#endif /* CONFIG_BUTTONS */
#ifdef CONFIG_STM32_IWDG
stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY);
return OK;
#endif
#ifdef CONFIG_PHOTON_WDG
/* Start WDG kicker thread */
ret = photon_watchdog_initialize();
if (ret != OK)
{
syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_PHOTON_WLAN
/* Initialize wlan driver and hardware */
ret = photon_wlan_initialize();
if (ret != OK)
{
syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret);
return ret;
}
#endif
return ret;
}
#endif /* CONFIG_LIB_BOARDCTL */

View File

@ -0,0 +1,116 @@
/****************************************************************************
* configs/photon/src/stm32_autoleds.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* 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.
*
****************************************************************************/
/* LEDs
*
* A single LED is available driven by PA13.
*
* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
* defined. In that case, the usage by the board port is defined in
* include/board.h and src/sam_autoleds.c. The LEDs are used to encode
* OS-related events as follows:
*
* ------------------- ----------------------- ------
* SYMBOL Meaning LED
* ------------------- ----------------------- ------
* LED_STARTED NuttX has been started OFF
* LED_HEAPALLOCATE Heap has been allocated OFF
* LED_IRQSENABLED Interrupts enabled OFF
* LED_STACKCREATED Idle stack created ON
* LED_INIRQ In an interrupt N/C
* LED_SIGNAL In a signal handler N/C
* LED_ASSERTION An assertion failed N/C
* LED_PANIC The system has crashed FLASH
*
* Thus is LED is statically on, NuttX has successfully booted and is,
* apparently, running normally. If LED is flashing at approximately
* 2Hz, then a fatal error has been detected and the system has halted.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "stm32_gpio.h"
#include "photon.h"
#ifdef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_autoled_initialize
****************************************************************************/
void board_autoled_initialize(void)
{
/* Configure Photon LED gpio as output */
stm32_configgpio(GPIO_LED1);
}
/****************************************************************************
* Name: board_autoled_on
****************************************************************************/
void board_autoled_on(int led)
{
if (led == 1 || led == 3)
{
stm32_gpiowrite(GPIO_LED1, true);
}
}
/****************************************************************************
* Name: board_autoled_off
****************************************************************************/
void board_autoled_off(int led)
{
if (led == 3)
{
stm32_gpiowrite(GPIO_LED1, false);
}
}
#endif /* CONFIG_ARCH_LEDS */

View File

@ -73,4 +73,32 @@ void stm32_boardinitialize(void)
stm32_usbinitialize();
}
#endif
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */
board_autoled_initialize();
#endif
}
/****************************************************************************
* Name: board_initialize
*
* Description:
* If CONFIG_BOARD_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_initialize(). board_initialize() will be
* called immediately after up_intitialize() is called and just before the
* initial application is started. This additional initialization phase
* may be used, for example, to initialize board-specific device drivers.
*
****************************************************************************/
#ifdef CONFIG_BOARD_INITIALIZE
void board_initialize(void)
{
/* Perform board initialization */
(void)stm32_bringup();
}
#endif /* CONFIG_BOARD_INITIALIZE */

View File

@ -0,0 +1,132 @@
/****************************************************************************
* config/photon/src/stm32_bringup.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Simon Piriou <spiriou31@gmail.com>
*
* 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 <sys/types.h>
#include <syslog.h>
#include <nuttx/input/buttons.h>
#include <nuttx/leds/userled.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "photon.h"
#include "stm32_wdg.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_bringup
*
* Description:
* Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by
* board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function
* initializes and configures all on-board features appropriate for the
* selected configuration.
*
****************************************************************************/
int stm32_bringup(void)
{
int ret = OK;
#ifdef CONFIG_USERLED
#ifdef CONFIG_USERLED_LOWER
/* Register the LED driver */
ret = userled_lower_initialize("/dev/userleds");
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
return ret;
}
#else
board_userled_initialize();
#endif /* CONFIG_USERLED_LOWER */
#endif /* CONFIG_USERLED */
#ifdef CONFIG_BUTTONS
#ifdef CONFIG_BUTTONS_LOWER
/* Register the BUTTON driver */
ret = btn_lower_initialize("/dev/buttons");
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
return ret;
}
#else
board_button_initialize();
#endif /* CONFIG_BUTTONS_LOWER */
#endif /* CONFIG_BUTTONS */
#ifdef CONFIG_STM32_IWDG
stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY);
#endif
#ifdef CONFIG_PHOTON_WDG
/* Start WDG kicker thread */
ret = photon_watchdog_initialize();
if (ret != OK)
{
syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret);
return ret;
}
#endif
#ifdef CONFIG_PHOTON_WLAN
/* Initialize wlan driver and hardware */
ret = photon_wlan_initialize();
if (ret != OK)
{
syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret);
return ret;
}
#endif
return ret;
}

View File

@ -43,18 +43,6 @@
#include <stdbool.h>
#include <nuttx/usb/usbdev.h>
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/************************************************************************************
* Private Data
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/

View File

@ -1,5 +1,5 @@
/****************************************************************************
* configs/photon/src/stm32_leds.c
* configs/photon/src/stm32_userleds.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Simon Piriou <spiriou31@gmail.com>
@ -45,6 +45,8 @@
#include "stm32_gpio.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Public Functions
****************************************************************************/
@ -80,3 +82,5 @@ void board_userled_all(uint8_t ledset)
{
stm32_gpiowrite(GPIO_LED1, !!(ledset & BOARD_LED1_BIT));
}
#endif /* !CONFIG_ARCH_LEDS */

View File

@ -53,11 +53,6 @@
#include <nuttx/kthread.h>
#include <nuttx/clock.h>
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* Configuration *******************************************************************/
/************************************************************************************
* Public Functions
************************************************************************************/

View File

@ -38,16 +38,19 @@
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <arch/board/board.h>
#include <nuttx/wireless/ieee80211/bcmf_sdio.h>
#include <nuttx/wireless/ieee80211/bcmf_board.h>
#include "photon.h"
#include <arch/board/board.h>
#include "stm32_gpio.h"
#include "stm32_sdio.h"
#include "photon.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@ -105,25 +108,29 @@ int photon_wlan_initialize()
struct sdio_dev_s *sdio_dev;
/* Initialize sdio interface */
_info("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO);
wlinfo("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO);
sdio_dev = sdio_initialize(SDIO_WLAN0_SLOTNO);
if (!sdio_dev)
{
_err("ERROR: Failed to initialize SDIO with slot %d\n",
wlerr("ERROR: Failed to initialize SDIO with slot %d\n",
SDIO_WLAN0_SLOTNO);
return ERROR;
}
/* Bind the SDIO interface to the bcmf driver */
ret = bcmf_sdio_initialize(SDIO_WLAN0_MINOR, sdio_dev);
if (ret != OK)
{
_err("ERROR: Failed to bind SDIO to bcmf driver\n");
wlerr("ERROR: Failed to bind SDIO to bcmf driver\n");
/* FIXME deinitialize sdio device */
return ERROR;
}
return OK;
}

View File

@ -1,5 +1,5 @@
/****************************************************************************
* configs/same70-xplained/include/sam_autoleds.c
* configs/same70-xplained/src/sam_autoleds.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>