diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 52ba57857b..ba878b5679 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -156,11 +156,59 @@ void init_done() { * Peripherals (except for SPI0 and UART0) are not initialized. * This function does not return. */ +/* + A bit of explanation for this entry point: + + SYS is the SDK task/context used by the upperlying system to run its + administrative tasks (at least WLAN and lwip's receive callbacks and + Ticker). NONOS-SDK is designed to run user's non-threaded code in + another specific task/context with its own stack in BSS. + + Some clever fellows found that the SYS stack was a large and quite unused + piece of ram that we could use for the user's stack instead of using user's + main memory, thus saving around 4KB on ram/heap. + + A problem arose later, which is that this stack can heavily be used by + the SDK for some features. One of these features is WPS. We still don't + know if other features are using this, or if this memory is going to be + used in future SDK releases. + + 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. + + References: + https://github.com/esp8266/Arduino/pull/4553 + https://github.com/esp8266/Arduino/pull/4622 + https://github.com/esp8266/Arduino/issues/4779 + https://github.com/esp8266/Arduino/pull/4889 + +*/ + +#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) { - /* Allocate continuation context on this stack, and save pointer to it. */ +#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(); } diff --git a/doc/faq/readme.rst b/doc/faq/readme.rst index 2f469ddda2..e21f83b707 100644 --- a/doc/faq/readme.rst +++ b/doc/faq/readme.rst @@ -40,6 +40,22 @@ entering an issue report, please perform initial troubleshooting. `Read more `__. +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`` + +Why can't I use 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: + +``./tools/boards.txt.py --allowWPS --allgen`` + This Arduino library doesn't work on ESP. How do I make it work? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 1d8cadfdb1..730b52886a 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -571,6 +571,9 @@ 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); /** @@ -650,7 +653,7 @@ void wifi_wps_status_cb(wps_cb_status 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 f08c179b5b..f94ba0a4d3 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -26,6 +26,7 @@ #include "ESP8266WiFiType.h" #include "ESP8266WiFiGeneric.h" +#include "user_interface.h" class ESP8266WiFiSTAClass { @@ -92,7 +93,13 @@ 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(); + } +#endif bool beginSmartConfig(); bool stopSmartConfig(); diff --git a/platform.txt b/platform.txt index 429cea6ec2..69b2d6536c 100644 --- a/platform.txt +++ b/platform.txt @@ -25,6 +25,7 @@ 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 @@ -32,7 +33,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} -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} {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.S.cmd=xtensa-lx106-elf-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls @@ -43,7 +44,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} -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} {build.noextra4kheap} -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 7da8dac54e..b79dc21933 100755 --- a/tools/boards.txt.py +++ b/tools/boards.txt.py @@ -1236,6 +1236,9 @@ def all_boards (): if nofloat: print id + '.build.float=' + if noextra4kheap: + print id + '.build.noextra4kheap=-DNO_EXTRA_4K_HEAP' + print '' if boardsgen: @@ -1253,11 +1256,8 @@ def package (): if packagegen: pkgfname_read = pkgfname + '.orig' - # check if backup already exists if os.path.isfile(pkgfname_read): - print "package file is in the way, please move it" - print " %s" % pkgfname_read - sys.exit(1) + os.remove(pkgfname_read) os.rename(pkgfname, pkgfname_read) # read package file @@ -1333,6 +1333,8 @@ 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 "" @@ -1376,6 +1378,7 @@ def usage (name,ret): led_default = 2 led_max = 16 nofloat = False +noextra4kheap = False ldgen = False ldshow = False boardsgen = False @@ -1391,6 +1394,7 @@ def usage (name,ret): try: opts, args = getopt.getopt(sys.argv[1:], "h", [ "help", "lwip=", "led=", "speed=", "board=", "customspeed=", "nofloat", + "noextra4kheap", "allowWPS", "ld", "ldgen", "boards", "boardsgen", "package", "packagegen", "doc", "docgen", "allgen"] ) except getopt.GetoptError as err: @@ -1434,6 +1438,9 @@ def usage (name,ret): elif o in ("--nofloat"): nofloat=True + elif o in ("--noextra4kheap", "--allowWPS"): + noextra4kheap=True + elif o in ("--ldshow"): ldshow = True diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 4d12133b1e..d2a4152ef7 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -575,13 +575,27 @@ enum wps_cb_status { WPS_CB_ST_UNK, }; +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); - -typedef void (*wps_st_cb_t)(int status); 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);