From 5b002b860f473be48f04e956dc8a7a4f9f3ce8ad Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 12 Nov 2019 09:31:46 +0100 Subject: [PATCH] cpu/esp8266: reset tool to allow automatic tests --- boards/common/esp8266/Makefile.include | 4 +- cpu/esp8266/Makefile.include | 4 +- dist/tools/esptool/espreset.py | 74 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100755 dist/tools/esptool/espreset.py diff --git a/boards/common/esp8266/Makefile.include b/boards/common/esp8266/Makefile.include index d830ea9a47fae..4f17c06da8a9c 100644 --- a/boards/common/esp8266/Makefile.include +++ b/boards/common/esp8266/Makefile.include @@ -4,5 +4,5 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) include $(RIOTMAKE)/tools/serial.inc.mk # reset tool configuration -RESET ?= esptool.py -RESET_FLAGS ?= --port $(PROG_DEV) --before default_reset run +RESET ?= $(RIOTTOOLS)/esptool/espreset.py +RESET_FLAGS ?= --port $(PROG_DEV) diff --git a/cpu/esp8266/Makefile.include b/cpu/esp8266/Makefile.include index e72b89784a863..a1d8c716bb3e3 100644 --- a/cpu/esp8266/Makefile.include +++ b/cpu/esp8266/Makefile.include @@ -172,7 +172,7 @@ FLASH_FREQ = 26m # FIX configuration, DO NOT CHANGE FLASH_SIZE ?= 1MB FLASHDEPS += preflash -PREFLASHER ?= $(RIOTBASE)/dist/tools/esptool/esptool.py +PREFLASHER ?= $(RIOTTOOLS)/esptool/esptool.py PREFFLAGS = --chip esp8266 elf2image PREFFLAGS += --flash_mode $(FLASH_MODE) --flash_size $(FLASH_SIZE) PREFFLAGS += --flash_freq $(FLASH_FREQ) --version 3 @@ -207,7 +207,7 @@ else export PROGRAMMER_SPEED ?= 460800 FLASHER = $(RIOTBASE)/dist/tools/esptool/esptool.py FFLAGS += --chip esp8266 --port $(PROG_DEV) --baud $(PROGRAMMER_SPEED) - FFLAGS += --before default_reset --after hard_reset write_flash -z + FFLAGS += --before default_reset write_flash -z FFLAGS += --flash_size detect FFLAGS += --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) FFLAGS += 0x0000 $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER) diff --git a/dist/tools/esptool/espreset.py b/dist/tools/esptool/espreset.py new file mode 100755 index 0000000000000..d05e8fd0aa8d9 --- /dev/null +++ b/dist/tools/esptool/espreset.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (C) 2019 Gunar Schorcht +# 2014 Oliver Hahm +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA + + +try: + import configparser +except ImportError: + import ConfigParser as configparser + +import serial +import sys +import time +import argparse + +try: + serial.Serial +except AttributeError: + print("\033[1;37;41m\n") + print("Something went terribly wrong when loading the pyserial package.") + print("There is a good chance that you installed the 'serial' package instead") + print("of 'pyserial'. Try running 'pip uninstall serial && pip install pyserial'") + print("\033[0m") + sys.exit(1) + +# default serial port +defaultport = "/dev/ttyUSB0" + +# default baudrate for serial connection +defaultbaud = 115200 + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="espreset - ESP reset program") + parser.add_argument("-p", "--port", + help="Specifies the serial port to use, default is %s" + % defaultport, + default=defaultport) + parser.add_argument("-b", "--baudrate", + help="Specifies baudrate for the serial port, default " + "is %s" % defaultbaud, + default=defaultbaud) + + args = parser.parse_args() + + ser = serial.Serial(port=args.port, dsrdtr=0, rtscts=0) + ser.baudrate = args.baudrate + # set RST low and GPIO0 high + ser.setRTS(1) + ser.setDTR(0) + # keep the RST line low for 0.1 seconds + time.sleep(0.1) + # set the RST high + ser.setRTS(1) + ser.setDTR(1) + # wait 1 second for boot + time.sleep(1) + sys.exit(0)