diff --git a/configs/photon/include/board.h b/configs/photon/include/board.h index 8c2fc655e3..96115ca57f 100644 --- a/configs/photon/include/board.h +++ b/configs/photon/include/board.h @@ -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 diff --git a/configs/photon/src/Makefile b/configs/photon/src/Makefile index 5d9501759c..23f31b4489 100644 --- a/configs/photon/src/Makefile +++ b/configs/photon/src/Makefile @@ -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 diff --git a/configs/photon/src/photon.h b/configs/photon/src/photon.h index 4e0f312b6c..5628d1b69c 100644 --- a/configs/photon/src/photon.h +++ b/configs/photon/src/photon.h @@ -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() * diff --git a/configs/photon/src/stm32_appinit.c b/configs/photon/src/stm32_appinit.c index dc2899789f..946dfbe8e2 100644 --- a/configs/photon/src/stm32_appinit.c +++ b/configs/photon/src/stm32_appinit.c @@ -2,7 +2,7 @@ * config/photon/src/stm32_appinit.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Simon Piriou + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,23 +38,14 @@ ****************************************************************************/ #include -#include -#include -#include +#include + +#include #include "photon.h" -#include "stm32_wdg.h" -#include -#include -/**************************************************************************** - * 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 */ diff --git a/configs/photon/src/stm32_autoleds.c b/configs/photon/src/stm32_autoleds.c new file mode 100644 index 0000000000..a490fa5432 --- /dev/null +++ b/configs/photon/src/stm32_autoleds.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * configs/photon/src/stm32_autoleds.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include +#include + +#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 */ diff --git a/configs/photon/src/stm32_boot.c b/configs/photon/src/stm32_boot.c index c9dfe28729..5adc28f31c 100644 --- a/configs/photon/src/stm32_boot.c +++ b/configs/photon/src/stm32_boot.c @@ -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 */ diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c new file mode 100644 index 0000000000..d83e0493ed --- /dev/null +++ b/configs/photon/src/stm32_bringup.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * config/photon/src/stm32_bringup.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Simon Piriou + * + * 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 + +#include +#include + +#include +#include +#include + +#include + +#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; +} diff --git a/configs/photon/src/stm32_usb.c b/configs/photon/src/stm32_usb.c index 5dc24d5ed8..6f361a2c3f 100644 --- a/configs/photon/src/stm32_usb.c +++ b/configs/photon/src/stm32_usb.c @@ -43,18 +43,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Data - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_leds.c b/configs/photon/src/stm32_userleds.c similarity index 97% rename from configs/photon/src/stm32_leds.c rename to configs/photon/src/stm32_userleds.c index 076df40ad6..8c7366f8a9 100644 --- a/configs/photon/src/stm32_leds.c +++ b/configs/photon/src/stm32_userleds.c @@ -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 @@ -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 */ diff --git a/configs/photon/src/stm32_wdt.c b/configs/photon/src/stm32_wdt.c index 1df96707c6..8ea352925c 100644 --- a/configs/photon/src/stm32_wdt.c +++ b/configs/photon/src/stm32_wdt.c @@ -53,11 +53,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ -/* Configuration *******************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_wlan.c b/configs/photon/src/stm32_wlan.c index a0b19e4e0f..068561d63a 100644 --- a/configs/photon/src/stm32_wlan.c +++ b/configs/photon/src/stm32_wlan.c @@ -38,16 +38,19 @@ ****************************************************************************/ #include + #include -#include #include #include -#include "photon.h" + +#include #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; } diff --git a/configs/same70-xplained/src/sam_autoleds.c b/configs/same70-xplained/src/sam_autoleds.c index 64fd6b663c..51e5272a19 100644 --- a/configs/same70-xplained/src/sam_autoleds.c +++ b/configs/same70-xplained/src/sam_autoleds.c @@ -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