From 52ceb6475893b7d7764d05b2d7b89360fb639f74 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 14 Jan 2016 01:07:57 +0200 Subject: [PATCH] Added "upload_resetmethod" option to Project Configuration File platformio.ini and allowed to change default upload reset method for Espressif development platform // Resolve #444 --- HISTORY.rst | 3 +- docs/platforms/espressif_extra.rst | 41 ++++++++----------------- docs/projectconf.rst | 7 +++++ platformio/__init__.py | 2 +- platformio/builder/main.py | 23 +++++++------- platformio/builder/scripts/espressif.py | 2 +- platformio/telemetry.py | 15 +++++---- 7 files changed, 45 insertions(+), 48 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 66cf804f..d8f23c80 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,7 +9,8 @@ PlatformIO 2.0 * Added SPL-Framework support for Nucleo F401RE board (`issue #453 `_) -* Explained in documentation how to `overwrite upload reset method `_ +* Added ``upload_resetmethod`` option to `Project Configuration File platformio.ini `__ + and allowed to `change default upload reset method `_ for Espressif development platform (`issue #444 `_) * Fixed builder for mbed framework and ST STM32 platform diff --git a/docs/platforms/espressif_extra.rst b/docs/platforms/espressif_extra.rst index 6c8614c0..c2e2fbd1 100644 --- a/docs/platforms/espressif_extra.rst +++ b/docs/platforms/espressif_extra.rst @@ -23,6 +23,19 @@ from :ref:`projectconf` upload_speed = 9600 +Custom Reset Method +------------------- + +See :ref:`projectconf_upload_resetmethod` option from :ref:`projectconf` + +.. code-block:: ini + + [env:esp12e] + platform = espressif + framework = arduino + board = esp12e + upload_resetmethod = ck + .. _platform_espressif_customflash: Custom Flash Size @@ -53,34 +66,6 @@ To override default LD script please use :ref:`projectconf_build_flags` from [env:myenv] build_flags = -Wl,-Tesp8266.flash.4m.ld -Custom Reset Method -------------------- - -To overwrite predefined reset method for uploading please use :ref:`projectconf_extra_script`. -For example, default reset method for ``esp12e`` board is ``nodemcu``. Let's -overwrite it to ``ck``: - -* :ref:`projectconf` - - .. code-block:: ini - - [env:esp12e] - platform = espressif - framework = arduino - board = esp12e - extra_script = extra_script.py - - -* ``extra_script.py`` should be located on the same level as :ref:`projectconf` - - .. code-block:: python - - from SCons.Script import DefaultEnvironment - - env = DefaultEnvironment() - env['BOARD_OPTIONS']['upload']['resetmethod'] = 'ck' - - .. _platform_espressif_uploadfs: Uploading files to file system SPIFFS diff --git a/docs/projectconf.rst b/docs/projectconf.rst index 3564cf9d..38c7036c 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -445,6 +445,13 @@ which "uploader" tool uses when sending firmware to board. Extra flags for uploader. Will be added to the end of uploader command. If you need to override uploader command or base flags please use :ref:`projectconf_extra_script`. +.. _projectconf_upload_resetmethod: + +``upload_resetmethod`` +^^^^^^^^^^^^^^^^^^^^^^ + +Specify reset method for "uploader" tool. This option isn't available for all +development platforms. The only :ref:`platform_espressif` supports it. Library options ~~~~~~~~~~~~~~~ diff --git a/platformio/__init__.py b/platformio/__init__.py index 22b4ead7..6889c332 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (2, 7, "2.dev0") +VERSION = (2, 7, "2.dev1") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/main.py b/platformio/builder/main.py index fd092324..96428dbd 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -56,7 +56,8 @@ commonvars.AddVariables( ("UPLOAD_PORT",), ("UPLOAD_PROTOCOL",), ("UPLOAD_SPEED",), - ("UPLOAD_FLAGS",) + ("UPLOAD_FLAGS",), + ("UPLOAD_RESETMETHOD",) ) DefaultEnvironment( @@ -103,16 +104,16 @@ if "BOARD" in env: except UnknownBoard as e: env.Exit("Error: %s" % str(e)) - if "BOARD_MCU" not in env: - env.Replace(BOARD_MCU="${BOARD_OPTIONS['build']['mcu']}") - if "BOARD_F_CPU" not in env: - env.Replace(BOARD_F_CPU="${BOARD_OPTIONS['build']['f_cpu']}") - if "UPLOAD_PROTOCOL" not in env: - env.Replace( - UPLOAD_PROTOCOL="${BOARD_OPTIONS['upload'].get('protocol', None)}") - if "UPLOAD_SPEED" not in env: - env.Replace( - UPLOAD_SPEED="${BOARD_OPTIONS['upload'].get('speed', None)}") + for k in commonvars.keys(): + if (k in env or + not any([k.startswith("BOARD_"), k.startswith("UPLOAD_")])): + continue + _opt, _val = k.lower().split("_", 1) + if _opt == "board": + _opt = "build" + if _val in env['BOARD_OPTIONS'][_opt]: + env.Replace(**{k: "${BOARD_OPTIONS['%s']['%s']}" % (_opt, _val)}) + if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}): env.Replace( LDSCRIPT_PATH="${BOARD_OPTIONS['build']['ldscript']}" diff --git a/platformio/builder/scripts/espressif.py b/platformio/builder/scripts/espressif.py index 05d498c0..35bc2a36 100644 --- a/platformio/builder/scripts/espressif.py +++ b/platformio/builder/scripts/espressif.py @@ -108,7 +108,7 @@ env.Replace( UPLOADERFLAGS=[ "-vv", - "-cd", "${BOARD_OPTIONS['upload']['resetmethod']}", + "-cd", "$UPLOAD_RESETMETHOD", "-cb", "$UPLOAD_SPEED", "-cp", "$UPLOAD_PORT" ], diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 4ab25564..0a528669 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -302,12 +302,15 @@ def on_exception(e): def _finalize(): timeout = 1000 # msec elapsed = 0 - while elapsed < timeout: - if not MPDataPusher().in_wait(): - break - sleep(0.2) - elapsed += 200 - backup_reports(MPDataPusher().get_items()) + try: + while elapsed < timeout: + if not MPDataPusher().in_wait(): + break + sleep(0.2) + elapsed += 200 + backup_reports(MPDataPusher().get_items()) + except KeyboardInterrupt: + pass def backup_reports(items):