From 8053f285b1f4342c19a32c5e060a1fe14a92f6fb Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 8 Mar 2018 04:37:03 +0100 Subject: [PATCH] provide full version descriptor, displayed in debug mode (#4467) * provide full version descriptor, displayed in debug mode * unix: shows core version like under windows when git is unavailable * store strings in progmem * version string honours NDEBUG * add ARDUINO_ESP8266_GIT_DESC restore ARDUINO_ESP8266_GIT_VER restore global variable "core_version" don't print full version on setDebugOutput(true) set platform.txt version to 2.4.1-pre hide irrelevant boot version fix typo * lwip2: fix disconnection/reconnection issue also: improve version string remove useless message * lwip2: bump tag before 2.4.1 * lwip2: improve netif flags management on git side * full-version string: remove useless NDEBUG in separate source file * do not automatically enable sdk messages along with core messages * automatically reenable sdk messages along with core messages *before* setup not after * check serial port when showing version-string + move sdk messages enabler in hardware serial * + license header * updated and tested windows commands in platform.txt (without git) * updated and tested windows commands in platform.txt (without git) * update package builder accordingly --- cores/esp8266/Esp-version.cpp | 54 +++++++++++++++++++++++++ cores/esp8266/Esp.h | 1 + cores/esp8266/HardwareSerial.cpp | 10 ++++- cores/esp8266/core_esp8266_main.cpp | 4 -- cores/esp8266/core_version.h | 1 + package/build_boards_manager_package.sh | 4 +- platform.txt | 8 ++-- 7 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 cores/esp8266/Esp-version.cpp diff --git a/cores/esp8266/Esp-version.cpp b/cores/esp8266/Esp-version.cpp new file mode 100644 index 0000000000..a60616561c --- /dev/null +++ b/cores/esp8266/Esp-version.cpp @@ -0,0 +1,54 @@ +/* + Esp.cpp - ESP8266-specific APIs + Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + 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 St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include // LWIP_VERSION_* +#include // LWIP_HASH_STR (lwip2) + +#define STRHELPER(x) #x +#define STR(x) STRHELPER(x) // stringifier + +static const char arduino_esp8266_git_ver [] PROGMEM = STR(ARDUINO_ESP8266_GIT_DESC); +#if LWIP_VERSION_MAJOR != 1 +static const char lwip2_version [] PROGMEM = "/lwIP:" STR(LWIP_VERSION_MAJOR) "." STR(LWIP_VERSION_MINOR) "." STR(LWIP_VERSION_REVISION); +#endif + +String EspClass::getFullVersion() +{ + return String(F("SDK:")) + system_get_sdk_version() + + F("/Core:") + FPSTR(arduino_esp8266_git_ver) +#if LWIP_VERSION_MAJOR == 1 + + F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION) +#else + + FPSTR(lwip2_version) +#endif +#if LWIP_VERSION_IS_DEVELOPMENT + + F("-dev") +#endif +#if LWIP_VERSION_IS_RC + + F("rc") + String(LWIP_VERSION_RC) +#endif +#ifdef LWIP_HASH_STR + + "(" + F(LWIP_HASH_STR) + ")" +#endif + ; +} diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index e5d3a5f909..43842a6ae7 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -108,6 +108,7 @@ class EspClass { const char * getSdkVersion(); String getCoreVersion(); + String getFullVersion(); uint8_t getBootVersion(); uint8_t getBootMode(); diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index f2465be5a6..e5b0d79a8c 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -29,7 +29,7 @@ #include #include "Arduino.h" #include "HardwareSerial.h" - +#include "Esp.h" HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _rx_size(256) @@ -39,6 +39,14 @@ void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode m { end(); _uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size); +#if defined(DEBUG_ESP_PORT) && !defined(NDEBUG) + if (this == &DEBUG_ESP_PORT) + { + setDebugOutput(true); + println(); + println(ESP.getFullVersion()); + } +#endif } void HardwareSerial::end() diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 25a4f3f24f..4a96eeec51 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -115,9 +115,6 @@ static void loop_wrapper() { preloop_update_frequency(); if(!setup_done) { setup(); -#ifdef DEBUG_ESP_PORT - DEBUG_ESP_PORT.setDebugOutput(true); -#endif setup_done = true; } loop(); @@ -150,7 +147,6 @@ void init_done() { system_set_os_print(1); gdb_init(); do_global_ctors(); - printf("\n%08x\n", core_version); esp_schedule(); } diff --git a/cores/esp8266/core_version.h b/cores/esp8266/core_version.h index 09e384c1fd..e4556d7e03 100644 --- a/cores/esp8266/core_version.h +++ b/cores/esp8266/core_version.h @@ -1,4 +1,5 @@ #define ARDUINO_ESP8266_GIT_VER 0x00000000 +#define ARDUINO_ESP8266_GIT_DESC unspecified // ARDUINO_ESP8266_RELEASE is defined for released versions as a string containing the version name, i.e. "2_3_0_RC1" // ARDUINO_ESP8266_RELEASE is used in the core internally. Please use ESP.getCoreVersion() function instead. diff --git a/package/build_boards_manager_package.sh b/package/build_boards_manager_package.sh index d5434b5ea8..32d4f9a004 100755 --- a/package/build_boards_manager_package.sh +++ b/package/build_boards_manager_package.sh @@ -81,13 +81,15 @@ $SED 's/runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}\/tools\/ $SED 's/runtime.tools.esptool.path={runtime.platform.path}\/tools\/esptool//g' | \ $SED 's/tools.esptool.path={runtime.platform.path}\/tools\/esptool/tools.esptool.path=\{runtime.tools.esptool.path\}/g' | \ $SED 's/tools.mkspiffs.path={runtime.platform.path}\/tools\/mkspiffs/tools.mkspiffs.path=\{runtime.tools.mkspiffs.path\}/g' |\ -$SED 's/recipe.hooks.core.prebuild.1.pattern.*//g' \ +$SED 's/recipe.hooks.core.prebuild.1.pattern.*//g' |\ +$SED 's/recipe.hooks.core.prebuild.2.pattern.*//g' \ > $outdir/platform.txt # Put core version and short hash of git version into core_version.h ver_define=`echo $plain_ver | tr "[:lower:].\055" "[:upper:]_"` echo Ver define: $ver_define echo \#define ARDUINO_ESP8266_GIT_VER 0x`git rev-parse --short=8 HEAD 2>/dev/null` >$outdir/cores/esp8266/core_version.h +echo \#define ARDUINO_ESP8266_GIT_DESC `git describe --tags 2>/dev/null` >>$outdir/cores/esp8266/core_version.h echo \#define ARDUINO_ESP8266_RELEASE_$ver_define >>$outdir/cores/esp8266/core_version.h echo \#define ARDUINO_ESP8266_RELEASE \"$ver_define\" >>$outdir/cores/esp8266/core_version.h diff --git a/platform.txt b/platform.txt index 351279111b..d59921932f 100644 --- a/platform.txt +++ b/platform.txt @@ -6,7 +6,7 @@ # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification name=ESP8266 Modules -version=2.5.0 +version=2.4.1-pre runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf runtime.tools.esptool.path={runtime.platform.path}/tools/esptool @@ -71,8 +71,10 @@ compiler.elf2hex.extra_flags= ## generate file with git version number ## needs bash, git, and echo recipe.hooks.core.prebuild.1.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_VER 0x`git --git-dir {runtime.platform.path}/.git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff` >{build.path}/core/core_version.h" -## windows-compatible version may be added later -recipe.hooks.core.prebuild.1.pattern.windows= +recipe.hooks.core.prebuild.2.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_DESC `cd {runtime.platform.path}; git describe --tags 2>/dev/null || echo unix-{version}` >>{build.path}/core/core_version.h" +## windows-compatible version without git +recipe.hooks.core.prebuild.1.pattern.windows=cmd.exe /c mkdir {build.path}\core & (echo #define ARDUINO_ESP8266_GIT_VER 0x00000000 & echo #define ARDUINO_ESP8266_GIT_DESC win-{version} ) > {build.path}\core\core_version.h +recipe.hooks.core.prebuild.2.pattern.windows= ## Compile c files recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"