Skip to content

Commit 85e6809

Browse files
authored
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system (#5018)
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system * enable dot_a_linkage on internal libraries * add device tests * boards generator: deprecate --noextra4k/--allowWPS and fix documentation
1 parent 9f67d83 commit 85e6809

37 files changed

+268
-151
lines changed

Diff for: cores/esp8266/cont.h

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#define CONT_STACKSIZE 4096
2828
#endif
2929

30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
3034
typedef struct cont_ {
3135
void (*pc_ret)(void);
3236
unsigned* sp_ret;
@@ -45,6 +49,8 @@ typedef struct cont_ {
4549
unsigned* struct_start;
4650
} cont_t;
4751

52+
extern cont_t* g_pcont;
53+
4854
// Initialize the cont_t structure before calling cont_run
4955
void cont_init(cont_t*);
5056

@@ -68,4 +74,8 @@ int cont_get_free_stack(cont_t* cont);
6874
// continuation stack
6975
bool cont_can_yield(cont_t* cont);
7076

77+
#ifdef __cplusplus
78+
}
79+
#endif
80+
7181
#endif /* CONT_H_ */

Diff for: cores/esp8266/core_esp8266_app_entry_noextra4k.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This is the original app_entry() not providing extra 4K heap, but allowing
3+
* the use of WPS.
4+
*
5+
* see comments in core_esp8266_main.cpp's app_entry()
6+
*
7+
*/
8+
9+
#include <c_types.h>
10+
#include "cont.h"
11+
#include "coredecls.h"
12+
13+
void disable_extra4k_at_link_time (void)
14+
{
15+
/*
16+
* does nothing
17+
* allows overriding the core_esp8266_main.cpp's app_entry()
18+
* by this one below, at link time
19+
*
20+
*/
21+
}
22+
23+
/* the following code is linked only if a call to the above function is made somewhere */
24+
25+
extern "C" void call_user_start();
26+
27+
/* this is the default NONOS-SDK user's heap location */
28+
static cont_t g_cont __attribute__ ((aligned (16)));
29+
30+
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
31+
{
32+
g_pcont = &g_cont;
33+
34+
/* Call the entry point of the SDK code. */
35+
call_user_start();
36+
}

Diff for: cores/esp8266/core_esp8266_main.cpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern void (*__init_array_end)(void);
4848
/* Not static, used in Esp.cpp */
4949
struct rst_info resetInfo;
5050

51-
/* Not static, used in core_esp8266_postmortem.c.
51+
/* Not static, used in core_esp8266_postmortem.c and other places.
5252
* Placed into noinit section because we assign value to this variable
5353
* before .bss is zero-filled, and need to preserve the value.
5454
*/
@@ -175,10 +175,15 @@ void init_done() {
175175
176176
WPS beeing flawed by its poor security, or not beeing used by lots of
177177
users, it has been decided that we are still going to use that memory for
178-
user's stack and disable the use of WPS, with an option to revert that
179-
back at the user's discretion. This selection can be done with the
180-
global define NO_EXTRA_4K_HEAP. An option has been added to the board
181-
generator script.
178+
user's stack and disable the use of WPS.
179+
180+
app_entry() jumps to app_entry_custom() defined as "weakref" calling
181+
itself a weak customizable function, allowing to use another one when
182+
this is required (see core_esp8266_app_entry_noextra4k.cpp, used by WPS).
183+
184+
(note: setting app_entry() itself as "weak" is not sufficient and always
185+
ends up with the other "noextra4k" one linked, maybe because it has a
186+
default ENTRY(app_entry) value in linker scripts).
182187
183188
References:
184189
https://github.com/esp8266/Arduino/pull/4553
@@ -188,31 +193,25 @@ void init_done() {
188193
189194
*/
190195

191-
#ifdef NO_EXTRA_4K_HEAP
192-
/* this is the default NONOS-SDK user's heap location */
193-
cont_t g_cont __attribute__ ((aligned (16)));
194-
#endif
195-
196-
extern "C" void ICACHE_RAM_ATTR app_entry(void)
196+
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void) __attribute__((weak));
197+
extern "C" void ICACHE_RAM_ATTR app_entry_redefinable(void)
197198
{
198-
#ifdef NO_EXTRA_4K_HEAP
199-
200-
/* this is the default NONOS-SDK user's heap location */
201-
g_pcont = &g_cont;
202-
203-
#else
204-
205199
/* Allocate continuation context on this SYS stack,
206200
and save pointer to it. */
207201
cont_t s_cont __attribute__((aligned(16)));
208202
g_pcont = &s_cont;
209203

210-
#endif
211-
212204
/* Call the entry point of the SDK code. */
213205
call_user_start();
214206
}
215207

208+
static void ICACHE_RAM_ATTR app_entry_custom (void) __attribute__((weakref("app_entry_redefinable")));
209+
210+
extern "C" void ICACHE_RAM_ATTR app_entry (void)
211+
{
212+
return app_entry_custom();
213+
}
214+
216215
extern "C" void user_init(void) {
217216
struct rst_info *rtc_info_ptr = system_get_rst_info();
218217
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));

Diff for: cores/esp8266/core_esp8266_postmortem.c

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
extern void __real_system_restart_local();
3434

35-
extern cont_t* g_pcont;
36-
3735
// These will be pointers to PROGMEM const strings
3836
static const char* s_panic_file = 0;
3937
static int s_panic_line = 0;

Diff for: cores/esp8266/coredecls.h

+5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ extern "C" {
88

99
// TODO: put declarations here, get rid of -Wno-implicit-function-declaration
1010

11+
#include <cont.h> // g_pcont declaration
12+
1113
extern bool timeshift64_is_set;
1214

15+
void esp_yield();
16+
void esp_schedule();
1317
void tune_timeshift64 (uint64_t now_us);
1418
void settimeofday_cb (void (*cb)(void));
19+
void disable_extra4k_at_link_time (void) __attribute__((noinline));
1520

1621
#ifdef __cplusplus
1722
}

Diff for: doc/faq/a05-board-generator.rst

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ As of today you can:
4848

4949
* increase available flash space by disabling floats in ``*printf`` functions
5050

51-
* enable WPS which is now disabled by default (at the cost of a smaller heap by ~4KB)
52-
5351
* change led pin ``LED_BUILTIN`` for the two generic boards
5452

5553
* change the default lwIP version (1.4 or 2)

Diff for: doc/faq/readme.rst

+13-6
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,29 @@ How can I get some extra KBs in flash ?
4646
* Using ``*printf()`` with floats is enabled by default. Some KBs of flash can
4747
be saved by using the option ``--nofloat`` with the boards generator:
4848

49-
``./tools/boards.txt.py --nofloat --allgen``
49+
``./tools/boards.txt.py --nofloat --boardsgen``
5050

5151
* Use the debug level option ``NoAssert-NDEBUG`` (in the Tools menu)
5252

5353
`Read more <a05-board-generator.rst>`__.
5454

55-
Why can't I use WPS ?
56-
~~~~~~~~~~~~~~~~~~~~~
55+
About WPS
56+
~~~~~~~~~
5757

58-
WPS is disabled by default, this offers an extra 4KB in ram/heap. To enable
59-
WPS (and lose 4KB of useable ram), use this boards generator option:
58+
From release 2.4.2 and ahead, not using WPS will give an exra ~4.5KB in
59+
heap.
6060

61-
``./tools/boards.txt.py --allowWPS --allgen``
61+
In release 2.4.2 only, WPS is disabled by default and the board generator is
62+
required to enable it:
63+
64+
``./tools/boards.txt.py --allowWPS --boardsgen``
6265

6366
`Read more <a05-board-generator.rst>`__.
6467

68+
This manual selection is not needed starting from 2.5.0 (and in git
69+
version). WPS is always available, and not using it will give an extra
70+
~4.5KB compared to releases until 2.4.1 included.
71+
6572
This Arduino library doesn't work on ESP. How do I make it work?
6673
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6774

Diff for: libraries/ArduinoOTA/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=With this library you can enable your sketch to be upgraded over netwo
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/DNSServer/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=This library implements a simple DNS server.
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/EEPROM/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=
77
category=Data Storage
88
url=http://arduino.cc/en/Reference/EEPROM
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266AVRISP/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=This library allows programming 8-bit AVR ICSP targets via TCP over Wi
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266HTTPClient/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=
77
category=Communication
88
url=https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266HTTPUpdateServer/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=The library accepts HTTP post requests to the /update url, and updates
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266NetBIOS/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=With this library you can connect to your ESP from Windows using a sho
77
category=Communication
88
url=http://www.xpablo.cz/?p=751#more-751
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266WebServer/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=The library supports HTTP GET and POST requests, provides argument par
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266WiFi/library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=With this library you can instantiate Servers, Clients and send/receiv
77
category=Communication
88
url=
99
architectures=esp8266
10+
dot_a_linkage=true

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiSTA-WPS.cpp

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
ESP8266WiFiSTA-WPS.cpp - WiFi library for esp8266
3+
4+
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
Reworked on 28 Dec 2015 by Markus Sattler
22+
23+
*/
24+
25+
26+
#include "ESP8266WiFi.h"
27+
#include "ESP8266WiFiGeneric.h"
28+
#include "ESP8266WiFiSTA.h"
29+
#include "coredecls.h" // disable_extra4k_at_link_time()
30+
31+
static void wifi_wps_status_cb(wps_cb_status status);
32+
33+
/**
34+
* WPS config
35+
* so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
36+
* @return ok
37+
*/
38+
bool ESP8266WiFiSTAClass::beginWPSConfig(void) {
39+
40+
// SYS ram is used by WPS, let's configure user stack inside user's HEAP
41+
disable_extra4k_at_link_time();
42+
43+
if(!WiFi.enableSTA(true)) {
44+
// enable STA failed
45+
return false;
46+
}
47+
48+
disconnect();
49+
50+
DEBUGV("wps begin\n");
51+
52+
if(!wifi_wps_disable()) {
53+
DEBUGV("wps disable failed\n");
54+
return false;
55+
}
56+
57+
// so far only WPS_TYPE_PBC is supported (SDK 1.2.0)
58+
if(!wifi_wps_enable(WPS_TYPE_PBC)) {
59+
DEBUGV("wps enable failed\n");
60+
return false;
61+
}
62+
63+
if(!wifi_set_wps_cb((wps_st_cb_t) &wifi_wps_status_cb)) {
64+
DEBUGV("wps cb failed\n");
65+
return false;
66+
}
67+
68+
if(!wifi_wps_start()) {
69+
DEBUGV("wps start failed\n");
70+
return false;
71+
}
72+
73+
esp_yield();
74+
// will return here when wifi_wps_status_cb fires
75+
76+
return true;
77+
}
78+
79+
/**
80+
* WPS callback
81+
* @param status wps_cb_status
82+
*/
83+
void wifi_wps_status_cb(wps_cb_status status) {
84+
DEBUGV("wps cb status: %d\r\n", status);
85+
switch(status) {
86+
case WPS_CB_ST_SUCCESS:
87+
if(!wifi_wps_disable()) {
88+
DEBUGV("wps disable failed\n");
89+
}
90+
wifi_station_connect();
91+
break;
92+
case WPS_CB_ST_FAILED:
93+
DEBUGV("wps FAILED\n");
94+
break;
95+
case WPS_CB_ST_TIMEOUT:
96+
DEBUGV("wps TIMEOUT\n");
97+
break;
98+
case WPS_CB_ST_WEP:
99+
DEBUGV("wps WEP\n");
100+
break;
101+
case WPS_CB_ST_UNK:
102+
DEBUGV("wps UNKNOWN\n");
103+
if(!wifi_wps_disable()) {
104+
DEBUGV("wps disable failed\n");
105+
}
106+
break;
107+
}
108+
// TODO user function to get status
109+
110+
esp_schedule(); // resume the beginWPSConfig function
111+
}

0 commit comments

Comments
 (0)