From 1f88f28f8c8a2b75f5edd934855722c9bdf16cc4 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 8 Aug 2018 17:28:35 +0200 Subject: [PATCH 01/13] Automatic stack location selection (SYS or HEAP), remove unnecessary board generator option --- cores/esp8266/cont.h | 6 ++ .../core_esp8266_app_entry_noextra4k.cpp | 38 +++++++++ cores/esp8266/core_esp8266_main.cpp | 37 ++++---- cores/esp8266/coredecls.h | 6 ++ .../ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp | 84 +++++++++++++++++++ libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 84 ------------------- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 14 ++-- .../src/WiFiClientSecureBearSSL.cpp | 4 +- .../extra4kchecker/extra4kchecker.ino | 42 ++++++++++ platform.txt | 5 +- tools/boards.txt.py | 8 +- tools/sdk/include/user_interface.h | 14 ---- 12 files changed, 206 insertions(+), 136 deletions(-) create mode 100644 cores/esp8266/core_esp8266_app_entry_noextra4k.cpp create mode 100644 libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp create mode 100644 libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino diff --git a/cores/esp8266/cont.h b/cores/esp8266/cont.h index 46daad1007..1fe2cb634b 100644 --- a/cores/esp8266/cont.h +++ b/cores/esp8266/cont.h @@ -45,6 +45,12 @@ typedef struct cont_ { unsigned* struct_start; } cont_t; +/* Not static, used in core_esp8266_postmortem.c. + * Placed into noinit section because we assign value to this variable + * before .bss is zero-filled, and need to preserve the value. + */ +extern cont_t* g_pcont __attribute__((section(".noinit"))); + // Initialize the cont_t structure before calling cont_run void cont_init(cont_t*); diff --git a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp new file mode 100644 index 0000000000..5f4210762b --- /dev/null +++ b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp @@ -0,0 +1,38 @@ +/* + * This is the original app_entry() not providing extra 4K heap, but allowing + * the use of WPS. + * + * see comments in core_esp8266_main.cpp's app_entry() + * + */ + +#include +#include "cont.h" +#include "coredecls.h" + +// calls to this function must *always* be inlined +void disable_extra4k_at_link_time (void) +{ + /* + * does nothing + * allows overriding the core_esp8266_main.cpp's app_entry() + * by this one below, at link time + * + */ +} + +/* the following code is linked only if a call to the above function is made somewhere */ + +extern "C" void call_user_start(); + +/* this is the default NONOS-SDK user's heap location */ +static cont_t g_cont __attribute__ ((aligned (16))); + +extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) +{ + /* this is the default NONOS-SDK user's heap location */ + g_pcont = &g_cont; + + /* Call the entry point of the SDK code. */ + call_user_start(); +} diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index ba878b5679..f64d60079c 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -175,10 +175,15 @@ void init_done() { WPS beeing flawed by its poor security, or not beeing used by lots of users, it has been decided that we are still going to use that memory for - user's stack and disable the use of WPS, with an option to revert that - back at the user's discretion. This selection can be done with the - global define NO_EXTRA_4K_HEAP. An option has been added to the board - generator script. + user's stack and disable the use of WPS. + + app_entry() jumps to app_entry_custom() defined as "weakref" calling + itself a weak customizable function, allowing to use another one when + this is required (see core_esp8266_app_entry_noextra4k.cpp, used by WPS). + + (note: setting app_entry() itself as "weak" is not sufficient and always + ends up with the other "noextra4k" one linked, maybe because it has a + default value in linker scripts). References: https://github.com/esp8266/Arduino/pull/4553 @@ -188,31 +193,25 @@ void init_done() { */ -#ifdef NO_EXTRA_4K_HEAP -/* this is the default NONOS-SDK user's heap location */ -cont_t g_cont __attribute__ ((aligned (16))); -#endif - -extern "C" void ICACHE_RAM_ATTR app_entry(void) +extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) __attribute__((weak)); +extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) { -#ifdef NO_EXTRA_4K_HEAP - - /* this is the default NONOS-SDK user's heap location */ - g_pcont = &g_cont; - -#else - /* Allocate continuation context on this SYS stack, and save pointer to it. */ cont_t s_cont __attribute__((aligned(16))); g_pcont = &s_cont; -#endif - /* Call the entry point of the SDK code. */ call_user_start(); } +static void ICACHE_RAM_ATTR app_entry_custom (void) __attribute__((weakref("app_entry_redefinable"))); + +extern "C" void ICACHE_RAM_ATTR app_entry (void) +{ + return app_entry_custom(); +} + extern "C" void user_init(void) { struct rst_info *rtc_info_ptr = system_get_rst_info(); memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo)); diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 9e06419ca4..5212c84211 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -8,11 +8,17 @@ extern "C" { // TODO: put declarations here, get rid of -Wno-implicit-function-declaration + extern bool timeshift64_is_set; +void esp_yield(); +void esp_schedule(); void tune_timeshift64 (uint64_t now_us); void settimeofday_cb (void (*cb)(void)); +// calls to this function must *always* be inlined +void disable_extra4k_at_link_time (void) __attribute__((noinline)); + #ifdef __cplusplus } #endif diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp new file mode 100644 index 0000000000..5b99b187b0 --- /dev/null +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp @@ -0,0 +1,84 @@ + +#include "ESP8266WiFi.h" +#include "ESP8266WiFiGeneric.h" +#include "ESP8266WiFiSTA.h" + +void wifi_wps_status_cb(wps_cb_status status); + +/** + * WPS config + * so far only WPS_TYPE_PBC is supported (SDK 1.2.0) + * @return ok + */ +bool beginWPSConfig(void) { + + if(!WiFi.enableSTA(true)) { + // enable STA failed + return false; + } + + WiFi.disconnect(); + + DEBUGV("wps begin\n"); + + if(!wifi_wps_disable()) { + DEBUGV("wps disable failed\n"); + return false; + } + + // so far only WPS_TYPE_PBC is supported (SDK 1.2.0) + if(!wifi_wps_enable(WPS_TYPE_PBC)) { + DEBUGV("wps enable failed\n"); + return false; + } + + if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) { + DEBUGV("wps cb failed\n"); + return false; + } + + if(!wifi_wps_start()) { + DEBUGV("wps start failed\n"); + return false; + } + + esp_yield(); + // will return here when wifi_wps_status_cb fires + + return true; +} + +/** + * WPS callback + * @param status wps_cb_status + */ +void wifi_wps_status_cb(wps_cb_status status) { + DEBUGV("wps cb status: %d\r\n", status); + switch(status) { + case WPS_CB_ST_SUCCESS: + if(!wifi_wps_disable()) { + DEBUGV("wps disable failed\n"); + } + wifi_station_connect(); + break; + case WPS_CB_ST_FAILED: + DEBUGV("wps FAILED\n"); + break; + case WPS_CB_ST_TIMEOUT: + DEBUGV("wps TIMEOUT\n"); + break; + case WPS_CB_ST_WEP: + DEBUGV("wps WEP\n"); + break; + case WPS_CB_ST_UNK: + DEBUGV("wps UNKNOWN\n"); + if(!wifi_wps_disable()) { + DEBUGV("wps disable failed\n"); + } + break; + } + // TODO user function to get status + + esp_schedule(); // resume the beginWPSConfig function +} + diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 730b52886a..5f2c2c3b05 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -571,90 +571,6 @@ int32_t ESP8266WiFiSTAClass::RSSI(void) { // -------------------------------------------------- STA remote configure ----------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------- -#ifdef NO_EXTRA_4K_HEAP -/* NO_EXTRA_4K_HEAP's description in cores/esp8266/core_esp8266_main.cpp */ - -void wifi_wps_status_cb(wps_cb_status status); - -/** - * WPS config - * so far only WPS_TYPE_PBC is supported (SDK 1.2.0) - * @return ok - */ -bool ESP8266WiFiSTAClass::beginWPSConfig(void) { - - if(!WiFi.enableSTA(true)) { - // enable STA failed - return false; - } - - disconnect(); - - DEBUGV("wps begin\n"); - - if(!wifi_wps_disable()) { - DEBUGV("wps disable failed\n"); - return false; - } - - // so far only WPS_TYPE_PBC is supported (SDK 1.2.0) - if(!wifi_wps_enable(WPS_TYPE_PBC)) { - DEBUGV("wps enable failed\n"); - return false; - } - - if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) { - DEBUGV("wps cb failed\n"); - return false; - } - - if(!wifi_wps_start()) { - DEBUGV("wps start failed\n"); - return false; - } - - esp_yield(); - // will return here when wifi_wps_status_cb fires - - return true; -} - -/** - * WPS callback - * @param status wps_cb_status - */ -void wifi_wps_status_cb(wps_cb_status status) { - DEBUGV("wps cb status: %d\r\n", status); - switch(status) { - case WPS_CB_ST_SUCCESS: - if(!wifi_wps_disable()) { - DEBUGV("wps disable failed\n"); - } - wifi_station_connect(); - break; - case WPS_CB_ST_FAILED: - DEBUGV("wps FAILED\n"); - break; - case WPS_CB_ST_TIMEOUT: - DEBUGV("wps TIMEOUT\n"); - break; - case WPS_CB_ST_WEP: - DEBUGV("wps WEP\n"); - break; - case WPS_CB_ST_UNK: - DEBUGV("wps UNKNOWN\n"); - if(!wifi_wps_disable()) { - DEBUGV("wps disable failed\n"); - } - break; - } - // TODO user function to get status - - esp_schedule(); // resume the beginWPSConfig function -} - -#endif // NO_EXTRA_4K_HEAP - bool ESP8266WiFiSTAClass::_smartConfigStarted = false; bool ESP8266WiFiSTAClass::_smartConfigDone = false; diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index f94ba0a4d3..9ce10297c2 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -27,7 +27,9 @@ #include "ESP8266WiFiType.h" #include "ESP8266WiFiGeneric.h" #include "user_interface.h" +#include "coredecls.h" // disable_extra4k_at_link_time() +extern bool beginWPSConfig(void); class ESP8266WiFiSTAClass { // ---------------------------------------------------------------------------------------------- @@ -93,14 +95,12 @@ class ESP8266WiFiSTAClass { public: -#ifdef NO_EXTRA_4K_HEAP - bool beginWPSConfig(void); -#else - inline bool beginWPSConfig(void) __attribute__((always_inline)) { - return WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool(); + inline bool beginWPSConfig(void) __attribute__((always_inline)) + { + disable_extra4k_at_link_time(); // this call must always be inlined + return ::beginWPSConfig(); } -#endif - + bool beginSmartConfig(); bool stopSmartConfig(); bool smartConfigDone(); diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index 890d86c8e3..0e28295520 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -1260,13 +1260,13 @@ bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) { extern "C" { #include - extern cont_t g_cont; + extern cont_t *g_pcont; extern size_t br_esp8266_stack_proxy_usage(); void _BearSSLCheckStack(const char *fcn, const char *file, int line) { static int cnt = 0; register uint32_t *sp asm("a1"); - int freestack = 4 * (sp - g_cont.stack); + int freestack = 4 * (sp - g_pcont->stack); int freeheap = ESP.getFreeHeap(); static int laststack, lastheap, laststack2; if ((laststack != freestack) || (lastheap != freeheap) || (laststack2 != (int)br_esp8266_stack_proxy_usage())) { diff --git a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino new file mode 100644 index 0000000000..d679de10bd --- /dev/null +++ b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino @@ -0,0 +1,42 @@ + +/* + This is a debugging / validation test only + + It demonstrates the effect of calling + disable_extra4k_at_link_time() + + Currently only WPS is using that call + + released to public domain +*/ + +#include +#include + +#define USE_WPS 0 // try me with 0 or 1 + +extern cont_t* g_pcont; + +void setup() { + + Serial.begin(115200); + Serial.setDebugOutput(true); + WiFi.mode(WIFI_STA); + bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; + Serial.printf("\nUsing sys stack: %s\ncont: %p (USER:0x3ffe SYS:0x3fff)\n" + "check https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map)\n", + sysstack ? "YES" : "NO", + g_pcont); + + Serial.printf("FreeHeap: %d (~52112 without WPS, ~46832 with)\n", ESP.getFreeHeap()); + +#if USE_WPS + Serial.printf("starting WPS...\n"); + Serial.printf("wps: %d\n", WiFi.beginWPSConfig()); +#else + Serial.printf("done\n"); +#endif +} + +void loop() { +} diff --git a/platform.txt b/platform.txt index 69b2d6536c..429cea6ec2 100644 --- a/platform.txt +++ b/platform.txt @@ -25,7 +25,6 @@ build.vtable_flags=-DVTABLES_IN_FLASH build.float=-u _printf_float -u _scanf_float build.led= -build.noextra4kheap= compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/ compiler.sdk.path={runtime.platform.path}/tools/sdk @@ -33,7 +32,7 @@ compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core" compiler.c.cmd=xtensa-lx106-elf-gcc -compiler.c.flags=-c {compiler.warning_flags} {build.noextra4kheap} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections +compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections compiler.S.cmd=xtensa-lx106-elf-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls @@ -44,7 +43,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc compiler.cpp.cmd=xtensa-lx106-elf-g++ -compiler.cpp.flags=-c {compiler.warning_flags} {build.noextra4kheap} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections +compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections compiler.as.cmd=xtensa-lx106-elf-as diff --git a/tools/boards.txt.py b/tools/boards.txt.py index fe60838a35..221e6bfdc7 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -1275,9 +1275,6 @@ def all_boards (): if nofloat: print(id + '.build.float=') - if noextra4kheap: - print(id + '.build.noextra4kheap=-DNO_EXTRA_4K_HEAP') - print('') if boardsgen: @@ -1372,8 +1369,6 @@ def usage (name,ret): print(" --speed s - change default serial speed") print(" --customspeed s - new serial speed for all boards") print(" --nofloat - disable float support in printf/scanf") - print(" --noextra4kheap - disable extra 4k heap (will enable WPS)") - print(" --allowWPS - synonym for --noextra4kheap") print("") print(" mandatory option (at least one):") print("") @@ -1417,7 +1412,6 @@ def usage (name,ret): led_default = 2 led_max = 16 nofloat = False -noextra4kheap = False ldgen = False ldshow = False boardsgen = False @@ -1478,7 +1472,7 @@ def usage (name,ret): nofloat=True elif o in ("--noextra4kheap", "--allowWPS"): - noextra4kheap=True + print('option ' + o + ' is now useless') elif o in ("--ldshow"): ldshow = True diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index d2a4152ef7..a7733a9548 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -577,25 +577,11 @@ enum wps_cb_status { typedef void (*wps_st_cb_t)(int status); -#ifdef NO_EXTRA_4K_HEAP -/* check cores/esp8266/core_esp8266_main.cpp for comments about this */ - bool wifi_wps_enable(WPS_TYPE_t wps_type); bool wifi_wps_disable(void); bool wifi_wps_start(void); bool wifi_set_wps_cb(wps_st_cb_t cb); -#else - -bool WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool (); -#define wifi_wps_enable(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool() -#define wifi_wps_disable() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool() -#define wifi_wps_start() WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool() -#define wifi_set_wps_cb(...) WPS_is_unavailable_in_this_configuration__Please_check_FAQ_or_board_generator_tool() - -#endif - - typedef void (*freedom_outside_cb_t)(uint8 status); int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb); void wifi_unregister_send_pkt_freedom_cb(void); From 60d3b4eff9723dc96e229c9ea18524aa7dd9d7fb Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 8 Aug 2018 17:47:08 +0200 Subject: [PATCH 02/13] documentation updates --- cores/esp8266/coredecls.h | 1 - doc/faq/a05-board-generator.rst | 2 -- doc/faq/readme.rst | 16 ++++++++++------ libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 5212c84211..9665fdc2fb 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -8,7 +8,6 @@ extern "C" { // TODO: put declarations here, get rid of -Wno-implicit-function-declaration - extern bool timeshift64_is_set; void esp_yield(); diff --git a/doc/faq/a05-board-generator.rst b/doc/faq/a05-board-generator.rst index 4aea17df8c..d68b9b1d1f 100644 --- a/doc/faq/a05-board-generator.rst +++ b/doc/faq/a05-board-generator.rst @@ -48,8 +48,6 @@ As of today you can: * increase available flash space by disabling floats in ``*printf`` functions -* enable WPS which is now disabled by default (at the cost of a smaller heap by ~4KB) - * change led pin ``LED_BUILTIN`` for the two generic boards * change the default lwIP version (1.4 or 2) diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 2ed3743a50..b4ff2659e6 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -46,22 +46,26 @@ How can I get some extra KBs in flash ? * Using ``*printf()`` with floats is enabled by default. Some KBs of flash can be saved by using the option ``--nofloat`` with the boards generator: - ``./tools/boards.txt.py --nofloat --allgen`` + ``./tools/boards.txt.py --nofloat --boardsgen`` * Use the debug level option ``NoAssert-NDEBUG`` (in the Tools menu) `Read more `__. -Why can't I use WPS ? -~~~~~~~~~~~~~~~~~~~~~ +About WPS +~~~~~~~~~ -WPS is disabled by default, this offers an extra 4KB in ram/heap. To enable -WPS (and lose 4KB of useable ram), use this boards generator option: +In release 2.4.2 only, WPS is disabled by default. To enable WPS, use this +boards generator option: -``./tools/boards.txt.py --allowWPS --allgen`` +``./tools/boards.txt.py --allowWPS --boardsgen`` `Read more `__. +From release 2.4.2 and ahead, using WPS will reduce available heap space to +user by around 4.5KB. In other words, from release 2.4.2 without using WPS, +an extra ~4.5KB is available in user's heap space. + This Arduino library doesn't work on ESP. How do I make it work? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index 9ce10297c2..22bf10c519 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -100,7 +100,7 @@ class ESP8266WiFiSTAClass { disable_extra4k_at_link_time(); // this call must always be inlined return ::beginWPSConfig(); } - + bool beginSmartConfig(); bool stopSmartConfig(); bool smartConfigDone(); From 05b2aeeb203c0e0f8be05a992557f866d4f8dfb1 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 14:39:06 +0200 Subject: [PATCH 03/13] dot_a_linkage=true --- libraries/ArduinoOTA/library.properties | 1 + libraries/DNSServer/library.properties | 1 + libraries/EEPROM/library.properties | 1 + libraries/ESP8266AVRISP/library.properties | 1 + libraries/ESP8266HTTPClient/library.properties | 1 + libraries/ESP8266HTTPUpdateServer/library.properties | 1 + libraries/ESP8266NetBIOS/library.properties | 1 + libraries/ESP8266WebServer/library.properties | 1 + libraries/ESP8266WiFi/library.properties | 1 + libraries/ESP8266WiFiMesh/library.properties | 1 + libraries/ESP8266httpUpdate/library.properties | 1 + libraries/Ethernet/library.properties | 1 + libraries/GDBStub/library.properties | 1 + libraries/Hash/library.properties | 1 + libraries/SD/library.properties | 1 + libraries/SPI/library.properties | 1 + libraries/SPISlave/library.properties | 1 + libraries/Servo/library.properties | 1 + libraries/Ticker/library.properties | 1 + libraries/Wire/library.properties | 1 + libraries/esp8266/library.properties | 1 + platform.txt | 6 ++++-- tests/device/libraries/BSTest/library.properties | 1 + 23 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libraries/ArduinoOTA/library.properties b/libraries/ArduinoOTA/library.properties index 1c72335c81..18bf6a52fd 100644 --- a/libraries/ArduinoOTA/library.properties +++ b/libraries/ArduinoOTA/library.properties @@ -7,3 +7,4 @@ paragraph=With this library you can enable your sketch to be upgraded over netwo category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/DNSServer/library.properties b/libraries/DNSServer/library.properties index 71f0ae5440..fc9f0f7fa1 100644 --- a/libraries/DNSServer/library.properties +++ b/libraries/DNSServer/library.properties @@ -7,3 +7,4 @@ paragraph=This library implements a simple DNS server. category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/EEPROM/library.properties b/libraries/EEPROM/library.properties index 3a638c4a32..de05c4f3de 100644 --- a/libraries/EEPROM/library.properties +++ b/libraries/EEPROM/library.properties @@ -7,3 +7,4 @@ paragraph= category=Data Storage url=http://arduino.cc/en/Reference/EEPROM architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266AVRISP/library.properties b/libraries/ESP8266AVRISP/library.properties index 70fa3cf8e5..59f581a546 100644 --- a/libraries/ESP8266AVRISP/library.properties +++ b/libraries/ESP8266AVRISP/library.properties @@ -7,3 +7,4 @@ paragraph=This library allows programming 8-bit AVR ICSP targets via TCP over Wi category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266HTTPClient/library.properties b/libraries/ESP8266HTTPClient/library.properties index a63eb5717b..af2cf8ddf8 100644 --- a/libraries/ESP8266HTTPClient/library.properties +++ b/libraries/ESP8266HTTPClient/library.properties @@ -7,3 +7,4 @@ paragraph= category=Communication url=https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266HTTPUpdateServer/library.properties b/libraries/ESP8266HTTPUpdateServer/library.properties index 5fd9988715..23ced5a862 100644 --- a/libraries/ESP8266HTTPUpdateServer/library.properties +++ b/libraries/ESP8266HTTPUpdateServer/library.properties @@ -7,3 +7,4 @@ paragraph=The library accepts HTTP post requests to the /update url, and updates category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266NetBIOS/library.properties b/libraries/ESP8266NetBIOS/library.properties index 510f9937c9..b72e43dcf8 100644 --- a/libraries/ESP8266NetBIOS/library.properties +++ b/libraries/ESP8266NetBIOS/library.properties @@ -7,3 +7,4 @@ paragraph=With this library you can connect to your ESP from Windows using a sho category=Communication url=http://www.xpablo.cz/?p=751#more-751 architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266WebServer/library.properties b/libraries/ESP8266WebServer/library.properties index 4dd12d3ba6..73e33ab14f 100644 --- a/libraries/ESP8266WebServer/library.properties +++ b/libraries/ESP8266WebServer/library.properties @@ -7,3 +7,4 @@ paragraph=The library supports HTTP GET and POST requests, provides argument par category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266WiFi/library.properties b/libraries/ESP8266WiFi/library.properties index 3db731e8ed..35aae4ccf8 100644 --- a/libraries/ESP8266WiFi/library.properties +++ b/libraries/ESP8266WiFi/library.properties @@ -7,3 +7,4 @@ paragraph=With this library you can instantiate Servers, Clients and send/receiv category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266WiFiMesh/library.properties b/libraries/ESP8266WiFiMesh/library.properties index 5dc4dec11a..70dff32590 100644 --- a/libraries/ESP8266WiFiMesh/library.properties +++ b/libraries/ESP8266WiFiMesh/library.properties @@ -7,3 +7,4 @@ paragraph=The library sets up a Mesh Node which acts as a router, creating a Mes category=Communication url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/ESP8266httpUpdate/library.properties b/libraries/ESP8266httpUpdate/library.properties index 94a8499b89..f94d2102fe 100644 --- a/libraries/ESP8266httpUpdate/library.properties +++ b/libraries/ESP8266httpUpdate/library.properties @@ -7,3 +7,4 @@ paragraph= category=Data Processing url=https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266httpUpdate architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/Ethernet/library.properties b/libraries/Ethernet/library.properties index 17fcae1003..00320f2acc 100644 --- a/libraries/Ethernet/library.properties +++ b/libraries/Ethernet/library.properties @@ -7,3 +7,4 @@ paragraph=With this library you can use the Arduino Ethernet (shield or board) t category=Communication url=http://www.arduino.cc/en/Reference/Ethernet architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/GDBStub/library.properties b/libraries/GDBStub/library.properties index 0ede834fdd..28a69deef6 100644 --- a/libraries/GDBStub/library.properties +++ b/libraries/GDBStub/library.properties @@ -7,3 +7,4 @@ paragraph=GDB server stub helps debug crashes when JTAG isn't an option. category=Uncategorized url=https://github.com/espressif/esp-gdbstub architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/Hash/library.properties b/libraries/Hash/library.properties index 81c8bba77d..82ce85b1d9 100644 --- a/libraries/Hash/library.properties +++ b/libraries/Hash/library.properties @@ -7,3 +7,4 @@ paragraph= category=Data Processing url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/SD/library.properties b/libraries/SD/library.properties index 40891c831a..42a1602564 100644 --- a/libraries/SD/library.properties +++ b/libraries/SD/library.properties @@ -7,3 +7,4 @@ paragraph=Once an SD memory card is connected to the SPI interfare of the Arduin category=Data Storage url=http://www.arduino.cc/en/Reference/SD architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/SPI/library.properties b/libraries/SPI/library.properties index 46f7d47f33..950045187f 100644 --- a/libraries/SPI/library.properties +++ b/libraries/SPI/library.properties @@ -7,3 +7,4 @@ paragraph= category=Signal Input/Output url=http://arduino.cc/en/Reference/SPI architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/SPISlave/library.properties b/libraries/SPISlave/library.properties index 50d81f3fb8..bca1281dd2 100644 --- a/libraries/SPISlave/library.properties +++ b/libraries/SPISlave/library.properties @@ -7,3 +7,4 @@ paragraph= category=Signal Input/Output url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/Servo/library.properties b/libraries/Servo/library.properties index d19ef5886d..df32b66167 100644 --- a/libraries/Servo/library.properties +++ b/libraries/Servo/library.properties @@ -7,3 +7,4 @@ paragraph=This library can control a great number of servos.
It makes caref category=Device Control url=http://arduino.cc/en/Reference/Servo architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/Ticker/library.properties b/libraries/Ticker/library.properties index 9261ad22dd..a759351e4c 100644 --- a/libraries/Ticker/library.properties +++ b/libraries/Ticker/library.properties @@ -7,3 +7,4 @@ paragraph= category=Timing url= architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/Wire/library.properties b/libraries/Wire/library.properties index 19eb0f43a7..c8f4ae1d85 100644 --- a/libraries/Wire/library.properties +++ b/libraries/Wire/library.properties @@ -7,3 +7,4 @@ paragraph= category=Signal Input/Output url=http://arduino.cc/en/Reference/Wire architectures=esp8266 +dot_a_linkage=true diff --git a/libraries/esp8266/library.properties b/libraries/esp8266/library.properties index 15b1a31486..6e1cc8aded 100644 --- a/libraries/esp8266/library.properties +++ b/libraries/esp8266/library.properties @@ -7,3 +7,4 @@ paragraph= category=Other url= architectures=esp8266 +dot_a_linkage=true diff --git a/platform.txt b/platform.txt index 429cea6ec2..83e1d72bf2 100644 --- a/platform.txt +++ b/platform.txt @@ -91,10 +91,12 @@ recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.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}" ## Create archives -recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}" +#recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}" +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" +#recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" "-L{build.path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" ## Create eeprom recipe.objcopy.eep.pattern= diff --git a/tests/device/libraries/BSTest/library.properties b/tests/device/libraries/BSTest/library.properties index cd65913497..f2399ca939 100644 --- a/tests/device/libraries/BSTest/library.properties +++ b/tests/device/libraries/BSTest/library.properties @@ -7,3 +7,4 @@ paragraph= category=Uncategorized url= architectures=esp8266 +dot_a_linkage=true From 6ed54ee5ad55f9dfbcbc0b667a84f40c68946e33 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 14:39:57 +0200 Subject: [PATCH 04/13] WIP: fixes from @igrr's review --- cores/esp8266/cont.h | 8 ++++ .../core_esp8266_app_entry_noextra4k.cpp | 3 +- cores/esp8266/core_esp8266_postmortem.c | 2 - cores/esp8266/coredecls.h | 2 + .../ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp | 38 +++++++++++++++---- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 13 +++---- .../src/WiFiClientSecureBearSSL.cpp | 2 - .../extra4kchecker/extra4kchecker.ino | 2 - 8 files changed, 48 insertions(+), 22 deletions(-) diff --git a/cores/esp8266/cont.h b/cores/esp8266/cont.h index 1fe2cb634b..13b51babe6 100644 --- a/cores/esp8266/cont.h +++ b/cores/esp8266/cont.h @@ -27,6 +27,10 @@ #define CONT_STACKSIZE 4096 #endif +#ifdef __cplusplus +extern "C" { +#endif + typedef struct cont_ { void (*pc_ret)(void); unsigned* sp_ret; @@ -74,4 +78,8 @@ int cont_get_free_stack(cont_t* cont); // continuation stack bool cont_can_yield(cont_t* cont); +#ifdef __cplusplus +} +#endif + #endif /* CONT_H_ */ diff --git a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp index 5f4210762b..1aa380459d 100644 --- a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp +++ b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp @@ -10,7 +10,7 @@ #include "cont.h" #include "coredecls.h" -// calls to this function must *always* be inlined +// callers to this function must *always* be inlined void disable_extra4k_at_link_time (void) { /* @@ -30,7 +30,6 @@ static cont_t g_cont __attribute__ ((aligned (16))); extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) { - /* this is the default NONOS-SDK user's heap location */ g_pcont = &g_cont; /* Call the entry point of the SDK code. */ diff --git a/cores/esp8266/core_esp8266_postmortem.c b/cores/esp8266/core_esp8266_postmortem.c index 3878cf1b9d..d0d5cbbf33 100644 --- a/cores/esp8266/core_esp8266_postmortem.c +++ b/cores/esp8266/core_esp8266_postmortem.c @@ -32,8 +32,6 @@ extern void __real_system_restart_local(); -extern cont_t* g_pcont; - // These will be pointers to PROGMEM const strings static const char* s_panic_file = 0; static int s_panic_line = 0; diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 9665fdc2fb..4465fa8153 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -8,6 +8,8 @@ extern "C" { // TODO: put declarations here, get rid of -Wno-implicit-function-declaration +#include // g_pcont declaration + extern bool timeshift64_is_set; void esp_yield(); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp index 5b99b187b0..ebfabc08cc 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp @@ -1,23 +1,48 @@ +/* + ESP8266WiFiSTA-WPS.cpp - WiFi library for esp8266 + + Copyright (c) 2014 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 + + Reworked on 28 Dec 2015 by Markus Sattler + + */ + #include "ESP8266WiFi.h" #include "ESP8266WiFiGeneric.h" #include "ESP8266WiFiSTA.h" -void wifi_wps_status_cb(wps_cb_status status); - /** * WPS config * so far only WPS_TYPE_PBC is supported (SDK 1.2.0) * @return ok */ -bool beginWPSConfig(void) { +bool ESP8266WiFiSTAClass::beginWPSConfig(void) { + + // SYS ram is used by WPS, let's configure user stack inside user's HEAP + disable_extra4k_at_link_time(); if(!WiFi.enableSTA(true)) { // enable STA failed return false; } - WiFi.disconnect(); + disconnect(); DEBUGV("wps begin\n"); @@ -32,7 +57,7 @@ bool beginWPSConfig(void) { return false; } - if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) { + if(!wifi_set_wps_cb((wps_st_cb_t) &WPSStatusCB)) { DEBUGV("wps cb failed\n"); return false; } @@ -52,7 +77,7 @@ bool beginWPSConfig(void) { * WPS callback * @param status wps_cb_status */ -void wifi_wps_status_cb(wps_cb_status status) { +void ESP8266WiFiSTAClass::WPSStatusCB(wps_cb_status status) { DEBUGV("wps cb status: %d\r\n", status); switch(status) { case WPS_CB_ST_SUCCESS: @@ -81,4 +106,3 @@ void wifi_wps_status_cb(wps_cb_status status) { esp_schedule(); // resume the beginWPSConfig function } - diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index 22bf10c519..fc103713ee 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -87,20 +87,19 @@ class ESP8266WiFiSTAClass { protected: - static bool _useStaticIp; + static bool _useStaticIp; // ---------------------------------------------------------------------------------------------- // ------------------------------------ STA remote configure ----------------------------------- // ---------------------------------------------------------------------------------------------- - public: + protected: + + static void WPSStatusCB(wps_cb_status status); - inline bool beginWPSConfig(void) __attribute__((always_inline)) - { - disable_extra4k_at_link_time(); // this call must always be inlined - return ::beginWPSConfig(); - } + public: + bool beginWPSConfig(void); bool beginSmartConfig(); bool stopSmartConfig(); bool smartConfigDone(); diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index 0e28295520..595f2ce87a 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -1259,8 +1259,6 @@ bool WiFiClientSecure::loadPrivateKey(Stream& stream, size_t size) { // SSL debugging which should focus on the WiFiClientBearSSL objects. extern "C" { -#include - extern cont_t *g_pcont; extern size_t br_esp8266_stack_proxy_usage(); void _BearSSLCheckStack(const char *fcn, const char *file, int line) { diff --git a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino index d679de10bd..44c7cff444 100644 --- a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino +++ b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino @@ -15,8 +15,6 @@ #define USE_WPS 0 // try me with 0 or 1 -extern cont_t* g_pcont; - void setup() { Serial.begin(115200); From 6f7286ea0cf350b6506d8bb3a2325e03a0153b0c Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 14:49:24 +0200 Subject: [PATCH 05/13] (WIP) one more pass - need to recheck weak,alias at the light of the new building process - need to convert the example to host test --- cores/esp8266/coredecls.h | 2 -- libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp | 1 + libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 1 - libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp | 1 + .../esp8266/examples/extra4kchecker/extra4kchecker.ino | 10 +++++++--- platform.txt | 2 -- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 4465fa8153..39cedf557c 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -16,8 +16,6 @@ void esp_yield(); void esp_schedule(); void tune_timeshift64 (uint64_t now_us); void settimeofday_cb (void (*cb)(void)); - -// calls to this function must *always* be inlined void disable_extra4k_at_link_time (void) __attribute__((noinline)); #ifdef __cplusplus diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp index ebfabc08cc..854410d154 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp @@ -26,6 +26,7 @@ #include "ESP8266WiFi.h" #include "ESP8266WiFiGeneric.h" #include "ESP8266WiFiSTA.h" +#include "coredecls.h" // disable_extra4k_at_link_time() /** * WPS config diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index fc103713ee..52714684df 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -27,7 +27,6 @@ #include "ESP8266WiFiType.h" #include "ESP8266WiFiGeneric.h" #include "user_interface.h" -#include "coredecls.h" // disable_extra4k_at_link_time() extern bool beginWPSConfig(void); diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index 595f2ce87a..f946ae6ef1 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -41,6 +41,7 @@ extern "C" { #include "lwip/netif.h" #include "include/ClientContext.h" #include "c_types.h" +#include "coredecls.h" namespace BearSSL { diff --git a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino index 44c7cff444..e8130d0aa5 100644 --- a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino +++ b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino @@ -28,12 +28,16 @@ void setup() { Serial.printf("FreeHeap: %d (~52112 without WPS, ~46832 with)\n", ESP.getFreeHeap()); -#if USE_WPS + #if USE_WPS + Serial.printf("starting WPS...\n"); Serial.printf("wps: %d\n", WiFi.beginWPSConfig()); -#else + + #else + Serial.printf("done\n"); -#endif + + #endif } void loop() { diff --git a/platform.txt b/platform.txt index 83e1d72bf2..a319e4f6f6 100644 --- a/platform.txt +++ b/platform.txt @@ -91,11 +91,9 @@ recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.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}" ## Create archives -#recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}" recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects -#recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/arduino.ar" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" "-L{build.path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" ## Create eeprom From 12f412dc3c117f10ed15b2edc91cd95228e00ce1 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 14:55:39 +0200 Subject: [PATCH 06/13] clean (wip'ed) declaration --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index 52714684df..aea4c68601 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -28,8 +28,6 @@ #include "ESP8266WiFiGeneric.h" #include "user_interface.h" -extern bool beginWPSConfig(void); - class ESP8266WiFiSTAClass { // ---------------------------------------------------------------------------------------------- // ---------------------------------------- STA function ---------------------------------------- From 3259bbc8144ef2458be759e5799e254884ce9d56 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 16:01:20 +0200 Subject: [PATCH 07/13] removed example, added device tests --- .../extra4kchecker/extra4kchecker.ino | 44 ------------------- .../libraries/BSTest/library.properties | 1 - .../test_stack_in_heap/test_stack_in_heap.ino | 24 ++++++++++ .../test_stack_in_sys/test_stack_in_sys.ino | 21 +++++++++ 4 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino create mode 100644 tests/device/test_stack_in_heap/test_stack_in_heap.ino create mode 100644 tests/device/test_stack_in_sys/test_stack_in_sys.ino diff --git a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino b/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino deleted file mode 100644 index e8130d0aa5..0000000000 --- a/libraries/esp8266/examples/extra4kchecker/extra4kchecker.ino +++ /dev/null @@ -1,44 +0,0 @@ - -/* - This is a debugging / validation test only - - It demonstrates the effect of calling - disable_extra4k_at_link_time() - - Currently only WPS is using that call - - released to public domain -*/ - -#include -#include - -#define USE_WPS 0 // try me with 0 or 1 - -void setup() { - - Serial.begin(115200); - Serial.setDebugOutput(true); - WiFi.mode(WIFI_STA); - bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; - Serial.printf("\nUsing sys stack: %s\ncont: %p (USER:0x3ffe SYS:0x3fff)\n" - "check https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map)\n", - sysstack ? "YES" : "NO", - g_pcont); - - Serial.printf("FreeHeap: %d (~52112 without WPS, ~46832 with)\n", ESP.getFreeHeap()); - - #if USE_WPS - - Serial.printf("starting WPS...\n"); - Serial.printf("wps: %d\n", WiFi.beginWPSConfig()); - - #else - - Serial.printf("done\n"); - - #endif -} - -void loop() { -} diff --git a/tests/device/libraries/BSTest/library.properties b/tests/device/libraries/BSTest/library.properties index f2399ca939..cd65913497 100644 --- a/tests/device/libraries/BSTest/library.properties +++ b/tests/device/libraries/BSTest/library.properties @@ -7,4 +7,3 @@ paragraph= category=Uncategorized url= architectures=esp8266 -dot_a_linkage=true diff --git a/tests/device/test_stack_in_heap/test_stack_in_heap.ino b/tests/device/test_stack_in_heap/test_stack_in_heap.ino new file mode 100644 index 0000000000..02cb11e9f1 --- /dev/null +++ b/tests/device/test_stack_in_heap/test_stack_in_heap.ino @@ -0,0 +1,24 @@ +#include + +BS_ENV_DECLARE(); + +#include +#include + +void setup() +{ + Serial.begin(115200); + BS_RUN(Serial); +} + +TEST_CASE("stack in user's HEAP ram", "[bs]") +{ + bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; + CHECK(!sysstack); +} + +void loop () +{ + // WPS I link you ! + WiFi.beginWPSConfig(); +} diff --git a/tests/device/test_stack_in_sys/test_stack_in_sys.ino b/tests/device/test_stack_in_sys/test_stack_in_sys.ino new file mode 100644 index 0000000000..6a1595c5ad --- /dev/null +++ b/tests/device/test_stack_in_sys/test_stack_in_sys.ino @@ -0,0 +1,21 @@ +#include + +BS_ENV_DECLARE(); + +#include + +void setup() +{ + Serial.begin(115200); + BS_RUN(Serial); +} + +TEST_CASE("stack in SYS ram", "[bs]") +{ + bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; + CHECK(sysstack); +} + +void loop () +{ +} From 446220b82b706bf4a677222ceb9b1fe98dddab4f Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 9 Aug 2018 16:03:49 +0200 Subject: [PATCH 08/13] minimize commits footprint --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index aea4c68601..d7ade712dd 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -28,6 +28,7 @@ #include "ESP8266WiFiGeneric.h" #include "user_interface.h" + class ESP8266WiFiSTAClass { // ---------------------------------------------------------------------------------------------- // ---------------------------------------- STA function ---------------------------------------- From c64f994100761dd19c5f4e2623eb93ea1cd3a8c3 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 9 Aug 2018 23:42:51 +0200 Subject: [PATCH 09/13] boards gen: deprecated option --- tools/boards.txt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/boards.txt.py b/tools/boards.txt.py index 221e6bfdc7..6fc9c787b7 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -1472,7 +1472,7 @@ def usage (name,ret): nofloat=True elif o in ("--noextra4kheap", "--allowWPS"): - print('option ' + o + ' is now useless') + print('option ' + o + ' is now deprecated, without effect, and will be removed') elif o in ("--ldshow"): ldshow = True From cdba9b4751c45e704a8c3279d62d92d9f4bd543a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 10 Aug 2018 12:00:57 +0200 Subject: [PATCH 10/13] some comment updates and fixes from @devyte's review --- cores/esp8266/core_esp8266_app_entry_noextra4k.cpp | 1 - cores/esp8266/core_esp8266_main.cpp | 2 +- libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp | 6 ++++-- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h | 4 ---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp index 1aa380459d..f2f9bffa32 100644 --- a/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp +++ b/cores/esp8266/core_esp8266_app_entry_noextra4k.cpp @@ -10,7 +10,6 @@ #include "cont.h" #include "coredecls.h" -// callers to this function must *always* be inlined void disable_extra4k_at_link_time (void) { /* diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index f64d60079c..137559b738 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -183,7 +183,7 @@ void init_done() { (note: setting app_entry() itself as "weak" is not sufficient and always ends up with the other "noextra4k" one linked, maybe because it has a - default value in linker scripts). + default ENTRY(app_entry) value in linker scripts). References: https://github.com/esp8266/Arduino/pull/4553 diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp index 854410d154..c7a92765be 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp @@ -28,6 +28,8 @@ #include "ESP8266WiFiSTA.h" #include "coredecls.h" // disable_extra4k_at_link_time() +static void wifi_wps_status_cb(wps_cb_status status); + /** * WPS config * so far only WPS_TYPE_PBC is supported (SDK 1.2.0) @@ -58,7 +60,7 @@ bool ESP8266WiFiSTAClass::beginWPSConfig(void) { return false; } - if(!wifi_set_wps_cb((wps_st_cb_t) &WPSStatusCB)) { + if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) { DEBUGV("wps cb failed\n"); return false; } @@ -78,7 +80,7 @@ bool ESP8266WiFiSTAClass::beginWPSConfig(void) { * WPS callback * @param status wps_cb_status */ -void ESP8266WiFiSTAClass::WPSStatusCB(wps_cb_status status) { +void wifi_wps_status_cb(wps_cb_status status) { DEBUGV("wps cb status: %d\r\n", status); switch(status) { case WPS_CB_ST_SUCCESS: diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index d7ade712dd..58b76ef5ee 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -91,10 +91,6 @@ class ESP8266WiFiSTAClass { // ------------------------------------ STA remote configure ----------------------------------- // ---------------------------------------------------------------------------------------------- - protected: - - static void WPSStatusCB(wps_cb_status status); - public: bool beginWPSConfig(void); From 67405c18c0dc5dbcd7d8ded7741cc3f819696b96 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 16 Aug 2018 16:10:59 +0200 Subject: [PATCH 11/13] updates from second @igrr's review --- cores/esp8266/cont.h | 6 +----- cores/esp8266/core_esp8266_main.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/cont.h b/cores/esp8266/cont.h index 13b51babe6..c3a36eba11 100644 --- a/cores/esp8266/cont.h +++ b/cores/esp8266/cont.h @@ -49,11 +49,7 @@ typedef struct cont_ { unsigned* struct_start; } cont_t; -/* Not static, used in core_esp8266_postmortem.c. - * Placed into noinit section because we assign value to this variable - * before .bss is zero-filled, and need to preserve the value. - */ -extern cont_t* g_pcont __attribute__((section(".noinit"))); +extern cont_t* g_pcont; // Initialize the cont_t structure before calling cont_run void cont_init(cont_t*); diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index f64d60079c..fe88804f58 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -48,7 +48,7 @@ extern void (*__init_array_end)(void); /* Not static, used in Esp.cpp */ struct rst_info resetInfo; -/* Not static, used in core_esp8266_postmortem.c. +/* Not static, used in core_esp8266_postmortem.c and other places. * Placed into noinit section because we assign value to this variable * before .bss is zero-filled, and need to preserve the value. */ From 8ec3504fe346be8a02b02bc4a56845db12c4a58a Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 16 Aug 2018 16:12:48 +0200 Subject: [PATCH 12/13] updates from second @igrr's review --- doc/faq/readme.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index b4ff2659e6..17d8309ca5 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -55,16 +55,19 @@ How can I get some extra KBs in flash ? About WPS ~~~~~~~~~ -In release 2.4.2 only, WPS is disabled by default. To enable WPS, use this -boards generator option: +From release 2.4.2 and ahead, not using WPS will give an exra ~4.5KB in +heap. + +In release 2.4.2 only, WPS is disabled by default and the board generator is +required to enable it: ``./tools/boards.txt.py --allowWPS --boardsgen`` `Read more `__. -From release 2.4.2 and ahead, using WPS will reduce available heap space to -user by around 4.5KB. In other words, from release 2.4.2 without using WPS, -an extra ~4.5KB is available in user's heap space. +This manual selection is not needed starting from 2.5.0 (and in git +version). WPS is always available, and not using it will give an extra +~4.5KB compared to releases until 2.4.1 included. This Arduino library doesn't work on ESP. How do I make it work? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From eb18c5b1575d2a801a7b91048fbbfa4fb11faa9d Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 16 Aug 2018 23:42:16 +0200 Subject: [PATCH 13/13] remove duplicate -L option --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index a319e4f6f6..9158c3a46d 100644 --- a/platform.txt +++ b/platform.txt @@ -94,7 +94,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.fla recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" "-L{build.path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" ## Create eeprom recipe.objcopy.eep.pattern=