diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index 4e369cb1a2..2807e1a47a 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -2058,6 +2058,16 @@ config STM32_PHYADDR ---help--- The 5-bit address of the PHY on the board. Default: 1 +config STM32_PHYINIT + bool "Board-specific PHY Initialization" + default n + ---help--- + Some boards require specialized initialization of the PHY before it can be used. + This may include such things as configuring GPIOs, resetting the PHY, etc. If + STM32_PHYINIT is defined in the configuration then the board specific logic must + provide stm32_phyinitialize(); The STM32 Ethernet driver will call this function + one time before it first uses the PHY. + config STM32_MII bool "Use MII interface" default n diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index 3054142ce8..006f67142b 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -2594,6 +2594,17 @@ static int stm32_phyinit(FAR struct stm32_ethmac_s *priv) } up_mdelay(PHY_RESET_DELAY); + /* Perform any necessary, board-specific PHY initialization */ + +#ifdef CONFIG_STM32_PHYINIT + ret = stm32_phy_boardinitialize(0); + if (ret < 0) + { + ndbg("Failed to initialize the PHY: %d\n", ret); + return ret; + } +#endif + /* Special workaround for the Davicom DM9161 PHY is required. */ #ifdef CONFIG_PHY_DM9161 diff --git a/arch/arm/src/stm32/stm32_eth.h b/arch/arm/src/stm32/stm32_eth.h index f0c14b5b1f..4501712b14 100644 --- a/arch/arm/src/stm32/stm32_eth.h +++ b/arch/arm/src/stm32/stm32_eth.h @@ -66,14 +66,13 @@ extern "C" { * Function: stm32_ethinitialize * * Description: - * Initialize the Ethernet driver for one interface. If the STM32 chip - * supports multiple Ethernet controllers, then board specific logic - * must implement up_netinitialize() and call this function to initialize - * the desired interfaces. + * Initialize the Ethernet driver for one interface. If the STM32 chip supports + * multiple Ethernet controllers, then board specific logic must implement + * up_netinitialize() and call this function to initialize the desired interfaces. * * Parameters: - * intf - In the case where there are multiple EMACs, this value - * identifies which EMAC is to be initialized. + * intf - In the case where there are multiple EMACs, this value identifies which + * EMAC is to be initialized. * * Returned Value: * OK on success; Negated errno on failure. @@ -86,6 +85,30 @@ extern "C" { EXTERN int stm32_ethinitialize(int intf); #endif +/************************************************************************************ + * Function: stm32_phy_boardinitialize + * + * Description: + * Some boards require specialized initialization of the PHY before it can be used. + * This may include such things as configuring GPIOs, resetting the PHY, etc. If + * CONFIG_STM32_PHYINIT is defined in the configuration then the board specific + * logic must provide stm32_phyinitialize(); The STM32 Ethernet driver will call + * this function one time before it first uses the PHY. + * + * Parameters: + * intf - Always zero for now. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_PHYINIT +EXTERN int stm32_phy_boardinitialize(int intf); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/configs/cloudctrl/src/Makefile b/configs/cloudctrl/src/Makefile index 3e4773518a..37c944f4d4 100644 --- a/configs/cloudctrl/src/Makefile +++ b/configs/cloudctrl/src/Makefile @@ -85,6 +85,9 @@ ifeq ($(CONFIG_WATCHDOG),y) CSRCS += up_watchdog.c endif +ifeq ($(CONFIG_STM32_PHYINIT),y) +CSRCS += up_phyinit.c +endif COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/configs/cloudctrl/src/up_boot.c b/configs/cloudctrl/src/up_boot.c index f536429716..fe0093d48d 100644 --- a/configs/cloudctrl/src/up_boot.c +++ b/configs/cloudctrl/src/up_boot.c @@ -56,16 +56,6 @@ * Private Functions ************************************************************************************/ -#ifdef CONFIG_PHY_DM9161 -static inline void stm232_configdm9161(void) -{ - stm32_configgpio(GPIO_DM9161_RET); - stm32_gpiowrite(GPIO_DM9161_RET, true); -} -# else -# define stm232_configdm9161() -#endif - /************************************************************************************ * Public Functions ************************************************************************************/ @@ -93,10 +83,6 @@ void stm32_boardinitialize(void) } #endif - /* Configure the DM9161 PHY reset pin and take it out of reset */ - - stm232_configdm9161(); - /* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not * disabled, and 3) the weak function stm32_usbinitialize() has been brought * into the build. diff --git a/configs/cloudctrl/src/up_phyinit.c b/configs/cloudctrl/src/up_phyinit.c new file mode 100644 index 0000000000..114c9f07bf --- /dev/null +++ b/configs/cloudctrl/src/up_phyinit.c @@ -0,0 +1,71 @@ +/************************************************************************************ + * configs/cloudctrl/src/up_phyinit.c + * arch/arm/src/board/up_phyinit.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Darcy Gong + * + * 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 "stm32_gpio.h" +#include "stm32_eth.h" + +#include "cloudctrl-internal.h" + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +#if defined(CONFIG_PHY_DM9161) && defined(CONFIG_STM32_PHYINIT) +int stm32_phy_boardinitialize(int intf) +{ + /* Configure the DM9161 PHY reset pin and take it out of reset */ + + stm32_configgpio(GPIO_DM9161_RET); + stm32_gpiowrite(GPIO_DM9161_RET, true); + return 0; +} +#endif + diff --git a/configs/ez80f910200kitg/README.txt b/configs/ez80f910200kitg/README.txt index 2bac3c5db8..222a25db1f 100644 --- a/configs/ez80f910200kitg/README.txt +++ b/configs/ez80f910200kitg/README.txt @@ -107,4 +107,8 @@ available: CONFIG_APPS_DIR="..\apps" + NOTE: If you need to change the toolchain path used in Make.defs, + you will need to use the short 8.3 filenames to avoid spaces. On + my change C:\PROGRA~1\ is C:\PROGRA~2\ is C:\Program Files (x86)\ + Check out any README.txt files in these s. diff --git a/tools/README.txt b/tools/README.txt index efe8ad68f3..68b85dc4f3 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -403,30 +403,6 @@ unlink.sh script so that it uses the NTFS mklink command. But I have never tried that -prebuild.py ------------ - - This is a Python script contributed by Darcy Gong that automates many - build actions: - - Nuttx configure utils v 0.3 - usage: tools/prebuild.py [-abcdfhmr] [-b boardname] [-l number]\n'%(program_name) - -c, --clean : Will execute "make clean" command. - -d, --distclean : Will execute "make distclean" command. - -l, --cleanlevel : Will execute "make clean"(value of 1) or "make distclean"(value of 2) command. - -f, --fixcfg : The configuration correction nuttx.cfg defconfig configuration items. - -a, --auto : Equivalent parameters -d and -f. - -b, --boardname : The boardname configuration. - -r, --mkromfs : Make Romfs. - -m, --make : Make now. - -h, --help : Help Message. - - example:' - usage 1 : tools/prebuild.py -b fire-stm32v2/nsh - usage 2 : tools/prebuild.py -f -b fire-stm32v2/nsh - usage 3 : tools/prebuild.py -a -b fire-stm32v2/nsh - usage 4 : tools/prebuild.py -l 1 -f -b fire-stm32v2/nsh - mkimage.sh ---------- diff --git a/tools/incdir.sh b/tools/incdir.sh index 181fb1fa29..1e862aae12 100755 --- a/tools/incdir.sh +++ b/tools/incdir.sh @@ -65,6 +65,7 @@ while [ ! -z "$1" ]; do echo " Enable script debug" echo " -h" echo " Shows this help text and exits." + exit 0 ;; * ) break; diff --git a/tools/prebuild.py b/tools/prebuild.py deleted file mode 100644 index 34fed09b6b..0000000000 --- a/tools/prebuild.py +++ /dev/null @@ -1,256 +0,0 @@ -#!/usr/bin/python - -import os -import sys,getopt -import commands -import ConfigParser -import socket -import fcntl -import struct -import re - -class Enum(object): - def __init__(self, *keys): - self.__dict__.update(zip(keys, range(len(keys)))) - -enum_parse_tag = Enum('tag','item') -enum_config = Enum('std','ext') - -def put_file_contents(filename,data=''): - if not os.path.isfile(filename): - return '' - try: - f = open(filename,'w') - contents = f.write(data) - f.close() - except IOError: - print 'file open or write err!' - -def fix_nuttx_cfg_value(key,val): - #if key == "CONFIG_NSH_IPADDR": - if re.search(r"_IPADDR$", key): - return '%s=%s\n'%(key,get_local_ip(50,2)) - #elif key == "CONFIG_NSH_DRIPADDR": - elif re.search(r"_DRIPADDR$", key): - return '%s=%s\n'%(key,get_local_ip(1,2)) - else: - return '%s=%s\n'%(key,val) - -def fix_nuttx_config(cfg,fix_cfgs): - result = '' - for line in cfg.readlines(): - line = line.strip() - if line.startswith('#'): - result += line+'\n' - continue - elif len(line) == 0: - result += '\n' - continue - elif line.count('=') > 0 : - #print line - it = line.find('=') - key = line[0:it].strip() - val = line[it + 1:].strip() - if fix_cfgs.has_key(key): - result += fix_nuttx_cfg_value(key, fix_cfgs.pop(key)) - else: - result += line+'\n' - else: - result += line+'\n' - #fix_cfgs = {} - #print fix_cfgs.viewitems() - if (len(fix_cfgs.keys())>0): - result += '\n\n####################################################\n\n' - for key in fix_cfgs.keys(): - result += fix_nuttx_cfg_value(key, fix_cfgs.pop(key)) - return result - - -def usage(): - program_name = sys.argv[0] - print 'Nuttx configure utils v 0.3\n' - print ' usage: %s [-abcdfhmr] [-b boardname] [-l number]\n'%(program_name) - print ' -c, --clean : Will execute "make clean" command.' - print ' -d, --distclean : Will execute "make distclean" command.' - print ' -l, --cleanlevel : Will execute "make clean"(value of 1) or "make distclean"(value of 2) command.' - print ' -f, --fixcfg : The configuration correction nuttx.cfg defconfig configuration items.' - print ' -a, --auto : Equivalent parameters -d and -f.' - print ' -b, --boardname : The boardname configuration.' - print ' -r, --mkromfs : Make Romfs.' - print ' -m, --make : Make now.' - print ' -h, --help : Help Message.' - print '\n example:' - print ' usage 1 : %s -b fire-stm32v2/nsh'%(program_name) - print ' usage 2 : %s -f -b fire-stm32v2/nsh'%(program_name) - print ' usage 3 : %s -a -b fire-stm32v2/nsh'%(program_name) - print ' usage 4 : %s -l 1 -f -b fire-stm32v2/nsh'%(program_name) - -def fix_config(boardname,fix_cfgs): - cfg_path = './configs/%s/defconfig'%boardname - if (os.path.isfile(cfg_path)): - try: - cfg = open(cfg_path, "r") - contents = fix_nuttx_config(cfg,fix_cfgs) - cfg.close() - #print contents - put_file_contents(cfg_path,contents) - except IOError: - print 'nuttx config open err!' - return '' - -def fix_root_config(fix_cfgs): - cfg_path = '.config' - if (os.path.isfile(cfg_path)): - try: - cfg = open(cfg_path, "r") - contents = fix_nuttx_config(cfg,fix_cfgs) - cfg.close() - #print contents - put_file_contents(cfg_path,contents) - except IOError: - print 'nuttx config open err!' - return '' - -def get_local_ipn(ifname): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - ip = fcntl.ioctl(s.fileno(), - 0x8915, # SIOCGIFADDR - struct.pack('256s', ifname[:15]))[20:24] - return ip - -def get_local_ip(id=-1,mode=1): - ip = get_local_ipn('eth0') - if (id < 0): - id = ord(ip[3]) - ipr = ord(ip[0])<<24|ord(ip[1])<<16|ord(ip[2])<<8|(id & 0xFF) - if mode == 1 : - return socket.inet_ntoa(struct.pack('>L', ipr)) - if mode == 2 : - return "0x%x"%ipr - else: - return ipr - -def get_ip_address(ifname): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( - s.fileno(), - 0x8915, # SIOCGIFADDR - struct.pack('256s', ifname[:15]) - )[20:24]) - -def config(cfg={}): - output = '' - fix_cfgs = {} - if cfg.clearlevel == 2: - print "make distclean apps_distclean" - output = commands.getoutput("make distclean apps_distclean") - elif cfg.clearlevel == 1: - print "make clean apps_clean" - output = commands.getoutput("make clean apps_clean") - - ini = ConfigParser.ConfigParser() - ini.optionxform = str - cfgf = 'nuttx_cfg.py' - #if not(os.path.isfile(cfgf)): - #fp = open(cfgf,'w') - #fp.write('# is nuttx config\n[info]\nlast=') - #fp.close() - #cfgf = open(cfgf,'rw') - ini.readfp(open(cfgf)) - lastfile = ini.get('info','last') - if (cmp(lastfile,cfg.boardname) != 0): - if ((cfg.boardname.strip() !='')): - lastfile = cfg.boardname - ini.set('info','last',lastfile) - ini.write(open(cfgf, "w")) - if cfg.usefix: - #print lastfile - if ini.has_section('defconfig'): - opts = ini.items('defconfig') - for item in opts: - fix_cfgs[item[0]] = item[1] - if ini.has_section(lastfile): - opts = ini.items(lastfile) - for item in opts: - fix_cfgs[item[0]] = item[1] - #print fix_cfgs - #fix_config(boardname,fix_cfgs) - - output = commands.getoutput("cd tools;./configure.sh %s;cd .."%lastfile) - print "tools/configure.sh %s"%lastfile - if cfg.usefix: - fix_root_config(fix_cfgs) - print "fix .config file" - if cfg.mkromfs: - if (os.path.isfile("./rcS.template")): - print "tools/mkromfsimg.sh ." - #output = commands.getoutput("tools/mkromfs.sh .") - os.system("tools/mkromfsimg.sh .") - bpath = "configs/%s/include"%(lastfile.split('/')[0]) - if (not os.path.exists(bpath)): - print "mkdir -p %s"%(bpath) - #commands.getoutput("mkdir -pv %s"%(bpath)) - os.system("mkdir -pv %s"%(bpath)) - if (not os.path.exists(bpath)): - print "[ERROR] no %s"%(bpath) - if (os.path.isfile("nsh_romfsimg.h")): - print "cp nsh_romfsimg.h %s/nsh_romfsimg.h"%(bpath) - #output = commands.getoutput("cp nsh_romfsimg.h include/arch/board/nsh_romfsimg.h") - os.system("cp nsh_romfsimg.h %s/nsh_romfsimg.h"%(bpath)) - if cfg.make: - os.system("sleep 3") - print "make" - os.system("make") - if '' != output.strip(): - print output - -class cfgobj(): - usefix = False - mkromfs = False - make = False - clearlevel = 0 - boardname = '' - -def main(): - try: - opts, args = getopt.getopt(sys.argv[1:], "dcb:hal:frm", - ["dictclean","clean","board=", "auto", "cleanlevel=", - "help","fixcfg","mkromfs","make"]) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - #cfg = {"usefix":False,"mkromfs":False,"make":False,"clearlevel":0,"boardname":'' } - cfg = cfgobj() - for o, v in opts: - if o in ("-a","--auto"): - cfg.clearlevel = 2 - cfg.usefix = True - cfg.mkromfs = True - cfg.make = True - if o in ("-c","--clean"): - cfg.clearlevel = 1 - if o in ("-d","--distclean"): - cfg.clearlevel = 2 - if o in ("-l","--cleanlevel"): - if v == '1': - cfg.clearlevel = 1 - elif v == '2': - cfg.clearlevel = 2 - else: - cfg.clearlevel = 0 - if o in ("-b","--board"): - cfg.boardname = v - if o in ("-f","--fixcfg"): - cfg.usefix = True - if o in ("-r","--mkromfs"): - cfg.mkromfs = True - if o in ("-m","--make"): - cfg.make = True - if o in ("-h", "--help"): - usage() - sys.exit() - config(cfg) - -if __name__ == "__main__": - main()