diff --git a/configs/stm32f4discovery/README.txt b/configs/stm32f4discovery/README.txt index cc64fab1c81..217dd7e4bde 100644 --- a/configs/stm32f4discovery/README.txt +++ b/configs/stm32f4discovery/README.txt @@ -1251,7 +1251,9 @@ Where is one of the following: on your system and that you have the full path to the installed genromfs executable in PATH variable (see apps/examples/README.txt) - 6. This configuration can be extended to use the hello++4 example and to build uClibc with the following additions to to the configuration file (from Leo aloe3132): + 6. This configuration can be extended to use the hello++4 example and to + build uClibc with the following additions to to the configuration file + (from Leo aloe3132): CONFIG_C99_BOOL8=y CONFIG_HAVE_CXXINITIALIZE=y @@ -1264,6 +1266,17 @@ Where is one of the following: CONFIG_EXAMPLES_ELF_CXXINITIALIZE=y CONFIG_EXAMPLES_ELF_UCLIBCXX=y + 4. The network initialization thread is enabled in this configuration. + As a result, networking initialization is performed asynchronously with + NSH bring-up. + + The network monitor is not enabled in this configuration, however, so + the firmware will not know when the network is disconnected or + reconnected. The NSH Network Monitor cannot be used with the + STM32F4DIS-BB base board because the LAN8720 is configured in REF_CLK + OUT mode. In that mode, the PHY interrupt is not supported. The NINT + pin serves as REFLCK0 in that case. + ipv6: ---- This is another version of the NuttShell configuration for the @@ -1278,7 +1291,9 @@ Where is one of the following: configuration other than using IPv6. So all of the notes above regarding the netnsh configuration apply. - Telnet does not work with IPv6. + a. Telnet does not work with IPv6. + b. The network initialization thread was enabed in the netnsh + configuration on 2015-09-28, but not in the ipv6 configuration. 2. This configuration can be modified to that both IPv4 and IPv6 are support. Here is a summary of the additional configuration diff --git a/configs/stm32f4discovery/netnsh/defconfig b/configs/stm32f4discovery/netnsh/defconfig index e73f1dcfa1b..6cec4472b96 100644 --- a/configs/stm32f4discovery/netnsh/defconfig +++ b/configs/stm32f4discovery/netnsh/defconfig @@ -854,7 +854,7 @@ CONFIG_NET_ETHERNET=y # # Network Device Operations # -# CONFIG_NETDEV_PHY_IOCTL is not set +CONFIG_NETDEV_PHY_IOCTL=y # # Internet Protocol Selection @@ -1281,7 +1281,9 @@ CONFIG_NSH_ARCHINIT=y # # Networking Configuration # -# CONFIG_NSH_NETINIT_THREAD is not set +CONFIG_NSH_NETINIT_THREAD=y +CONFIG_NSH_NETINIT_THREAD_STACKSIZE=1568 +CONFIG_NSH_NETINIT_THREAD_PRIORITY=80 # # IP Address Configuration @@ -1336,6 +1338,7 @@ CONFIG_SYSTEM_READLINE=y CONFIG_READLINE_ECHO=y # CONFIG_READLINE_TABCOMPLETION is not set # CONFIG_READLINE_CMD_HISTORY is not set +# CONFIG_SYSTEM_MDIO is not set # CONFIG_SYSTEM_RAMTRON is not set # CONFIG_SYSTEM_SDCARD is not set # CONFIG_SYSTEM_SUDOKU is not set diff --git a/configs/stm32f4discovery/src/Makefile b/configs/stm32f4discovery/src/Makefile index 2015245019d..b30d0b03565 100644 --- a/configs/stm32f4discovery/src/Makefile +++ b/configs/stm32f4discovery/src/Makefile @@ -64,6 +64,10 @@ ifeq ($(CONFIG_STM32_SDIO),y) CSRCS += stm32_sdio.c endif +ifeq ($(CONFIG_STM32_ETHMAC),y) +CSRCS += stm32_ethernet.c +endif + ifeq ($(CONFIG_PWM),y) CSRCS += stm32_pwm.c endif diff --git a/configs/stm32f4discovery/src/stm32_boot.c b/configs/stm32f4discovery/src/stm32_boot.c index ffebf8a1d80..2f1a431ae70 100644 --- a/configs/stm32f4discovery/src/stm32_boot.c +++ b/configs/stm32f4discovery/src/stm32_boot.c @@ -95,6 +95,15 @@ void stm32_boardinitialize(void) } #endif +#ifdef HAVE_NETMONITOR + /* Configure board resources to support networking. */ + + if (stm32_netinitialize) + { + stm32_netinitialize(); + } +#endif + #ifdef CONFIG_ARCH_LEDS /* Configure on-board LEDs if LED support has been selected. */ diff --git a/configs/stm32f4discovery/src/stm32_ethernet.c b/configs/stm32f4discovery/src/stm32_ethernet.c new file mode 100644 index 00000000000..b1d420e041f --- /dev/null +++ b/configs/stm32f4discovery/src/stm32_ethernet.c @@ -0,0 +1,250 @@ +/************************************************************************************ + * configs/stm32f4discovery/src/stm32_ethernet.c + * + * Copyright (C) 2015 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. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +/* Force verbose debug on in this file only to support unit-level testing. */ + +#ifdef CONFIG_NETDEV_PHY_DEBUG +# undef CONFIG_DEBUG_VERBOSE +# define CONFIG_DEBUG_VERBOSE 1 +# undef CONFIG_DEBUG_NET +# define CONFIG_DEBUG_NET 1 +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "stm32_gpio.h" +#include "stm32_eth.h" + +#include "stm32f4discovery.h" + +#if defined(CONFIG_STM32F4DISBB) && defined(CONFIG_STM32_ETHMAC) + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#define STM32_ETHMAC_DEVNAME "eth0" + +#define AT24XX_MACADDR_OFFSET 0x9a + +/* Debug ********************************************************************/ +/* Extra, in-depth debug output that is only available if + * CONFIG_NETDEV_PHY_DEBUG us defined. + */ + +#ifdef CONFIG_NETDEV_PHY_DEBUG +# define phydbg dbg +# define phylldbg lldbg +#else +# define phydbg(x...) +# define phylldbg(x...) +#endif + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +#ifdef HAVE_NETMONITOR +static xcpt_t g_ethmac_handler; +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_emac0_phy_enable + ************************************************************************************/ + +#ifdef HAVE_NETMONITOR +static void stm32_emac0_phy_enable(bool enable) +{ + phydbg("enable=%d\n", enable); + if (enable && g_ethmac_handler != NULL) + { + /* Attach and enable GPIO interrupt (and event) on the falling edge */ + + (void)stm32_gpiosetevent(GPIO_EMAC_NINT, false, true, true, g_ethmac_handler); + } + else + { + /* Detach and disable GPIO interrupt */ + + (void)stm32_gpiosetevent(GPIO_EMAC_NINT, false, false, false, NULL); + } +} +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_netinitialize + * + * Description: + * Configure board resources to support networking. + * + ************************************************************************************/ + +void weak_function stm32_netinitialize(void) +{ +#ifdef HAVE_NETMONITOR + /* Configure the PHY interrupt GPIO */ + + phydbg("Configuring %08x\n", GPIO_EMAC_NINT); + stm32_configgpio(GPIO_EMAC_NINT); +#endif + + /* Configure PHY /RESET output */ + + stm32_configgpio(GPIO_EMAC_NRST); +} + +/**************************************************************************** + * Name: arch_phy_irq + * + * Description: + * This function may be called to register an interrupt handler that will + * be called when a PHY interrupt occurs. This function both attaches + * the interrupt handler and enables the interrupt if 'handler' is non- + * NULL. If handler is NULL, then the interrupt is detached and disabled + * instead. + * + * The PHY interrupt is always disabled upon return. The caller must + * call back through the enable function point to control the state of + * the interrupt. + * + * This interrupt may or may not be available on a given platform depending + * on how the network hardware architecture is implemented. In a typical + * case, the PHY interrupt is provided to board-level logic as a GPIO + * interrupt (in which case this is a board-specific interface and really + * should be called board_phy_irq()); In other cases, the PHY interrupt + * may be cause by the chip's MAC logic (in which case arch_phy_irq()) is + * an appropriate name. Other other boards, there may be no PHY interrupts + * available at all. If client attachable PHY interrupts are available + * from the board or from the chip, then CONFIG_ARCH_PHY_INTERRUPT should + * be defined to indicate that fact. + * + * Typical usage: + * a. OS service logic (not application logic*) attaches to the PHY + * PHY interrupt and enables the PHY interrupt. + * b. When the PHY interrupt occurs: (1) the interrupt should be + * disabled and () work should be scheduled on the worker thread (or + * perhaps a dedicated application thread). + * c. That worker thread should use the SIOCGMIIPHY, SIOCGMIIREG, + * and SIOCSMIIREG ioctl calls** to communicate with the PHY, + * determine what network event took place (Link Up/Down?), and + * take the appropriate actions. + * d. It should then interact the the PHY to clear any pending + * interrupts, then re-enable the PHY interrupt. + * + * * This is an OS internal interface and should not be used from + * application space. Rather applications should use the SIOCMIISIG + * ioctl to receive a signal when a PHY event occurs. + * ** This interrupt is really of no use if the Ethernet MAC driver + * does not support these ioctl calls. + * + * Input Parameters: + * intf - Identifies the network interface. For example "eth0". Only + * useful on platforms that support multiple Ethernet interfaces + * and, hence, multiple PHYs and PHY interrupts. + * handler - The client interrupt handler to be invoked when the PHY + * asserts an interrupt. Must reside in OS space, but can + * signal tasks in user space. A value of NULL can be passed + * in order to detach and disable the PHY interrupt. + * enable - A function pointer that be unsed to enable or disable the + * PHY interrupt. + * + * Returned Value: + * The previous PHY interrupt handler address is returned. This allows you + * to temporarily replace an interrupt handler, then restore the original + * interrupt handler. NULL is returned if there is was not handler in + * place when the call was made. + * + ****************************************************************************/ + +#ifdef HAVE_NETMONITOR +xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +{ + phy_enable_t enabler; + xcpt_t oldhandler; + irqstate_t flags; + + nvdbg("%s: handler=%p\n", intf, handler); + phydbg("ETHMAC: devname=%s\n", STM32_ETHMAC_DEVNAME); + + DEBUGASSERT(intf); + + flags = irqsave(); + oldhandler = g_ethmac_handler; + + if (strcmp(intf, STM32_ETHMAC_DEVNAME) == 0) + { + phydbg("Select ETHMAC\n"); + g_ethmac_handler = handler; + enabler = stm32_emac0_phy_enable; + } + else + { + ndbg("Unsupported interface: %s\n", intf); + enabler = NULL; + } + + if (enable) + { + *enable = enabler; + } + + irqrestore(flags); + return oldhandler; +} +#endif + +#endif /* CONFIG_STM32F4DISBB && CONFIG_STM32_ETHMAC */ diff --git a/configs/stm32f4discovery/src/stm32f4discovery.h b/configs/stm32f4discovery/src/stm32f4discovery.h index 4a738b35b5e..5be97e61586 100644 --- a/configs/stm32f4discovery/src/stm32f4discovery.h +++ b/configs/stm32f4discovery/src/stm32f4discovery.h @@ -70,6 +70,7 @@ #define HAVE_SDIO 1 #define HAVE_RTC_DRIVER 1 #define HAVE_ELF 1 +#define HAVE_NETMONITOR 1 /* Can't support USB host or device features if USB OTG FS is not enabled */ @@ -148,6 +149,27 @@ # undef HAVE_ELF #endif +/* NSH Network monitor */ + +#if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC) +# undef HAVE_NETMONITOR +#endif + +#if !defined(CONFIG_NSH_NETINIT_THREAD) || !defined(CONFIG_ARCH_PHY_INTERRUPT) || \ + !defined(CONFIG_NETDEV_PHY_IOCTL) || !defined(CONFIG_NET_UDP) || \ + defined(CONFIG_DISABLE_SIGNALS) +# undef HAVE_NETMONITOR +#endif + +/* The NSH Network Monitor cannot be used with the STM32F4DIS-BB base board. + * That is because the LAN8720 is configured in REF_CLK OUT mode. In that + * mode, the PHY interrupt is not supported. The NINT pin serves instead as + * REFLCK0. + */ + +#ifdef CONFIG_STM32F4DISBB +# undef HAVE_NETMONITOR +#endif /* STM32F4 Discovery GPIOs **************************************************/ /* LEDs */ @@ -260,6 +282,31 @@ GPIO_PORTB|GPIO_PIN15) #endif +/* STM32F4DIS-BB LAN8720 + * + * ---------- ------------- ------------------------------ + * PIO SIGNAL Comments + * ---------- ------------- ------------------------------ + * PB11 TXEN Configured by driver + * PB12 TXD0 " " "" " " + * PB13 TXD1 " " "" " " + * PC4 RXD0/MODE0 " " "" " " + * PC5 RXD1/MODE1 " " "" " " + * PA7 CRS_DIV/MODE2 " " "" " " + * PA2 MDIO " " "" " " + * PC1 MDC " " "" " " + * PA1 NINT/REFCLK0 " " "" " " + * PE2 DAT2 " " "" " " + * ---------- ------------- ------------------------------ + */ + +#if defined(CONFIG_STM32F4DISBB) && defined(CONFIG_STM32_ETHMAC) +# define GPIO_EMAC_NINT (GPIO_INPUT|GPIO_PULLUP|GPIO_EXTI|\ + GPIO_PORTA|GPIO_PIN1) +# define GPIO_EMAC_NRST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\ + GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN2) +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -455,5 +502,17 @@ int stm32_bringup(void); int stm32_sdio_initialize(void); #endif +/************************************************************************************ + * Name: stm32_netinitialize + * + * Description: + * Configure board resources to support networking. + * + ************************************************************************************/ + +#ifdef HAVE_NETMONITOR +void weak_function stm32_netinitialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_STM32F4DISCOVERY_SRC_STM32F4DISCOVERY_H */