@@ -156,10 +156,40 @@ void init_done() {
156
156
* Peripherals (except for SPI0 and UART0) are not initialized.
157
157
* This function does not return.
158
158
*/
159
+ /*
160
+ A bit of explanation for this entry point:
161
+
162
+ SYS is the RTOS task/context used by the upperlying system to run its
163
+ administrative tasks (at least WLAN and lwip's receive callbacks and
164
+ Ticker). NONOS-SDK is designed to run users's non-threaded code in
165
+ another specific task/context with its own stack in BSS.
166
+
167
+ Some clever fellows found that the SYS stack was a large and quite unused
168
+ piece of ram that we could use for the user stack, and proposed to use it
169
+ to store the user stack instead of using the users' main memory, thus
170
+ saving around 4KB or ram/heap.
171
+
172
+ A problem arose later, which is that this stack is heavily used by the
173
+ system for some features. One of these features is WPS. We still don't
174
+ know if other features are using this, or if this memory is going to be
175
+ used in future releases.
176
+
177
+ WPS beeing flawed by its poor security, or not beeing used by lots of
178
+ users, it has been decided that we are still going to use that memory for
179
+ the users's stack and disable the use of WPS, with an option to revert
180
+ that back at the user's discretion. This selection can be done by using
181
+ the board generator script. This could be also done by setting up a new
182
+ option in the IDE's Tools menu.
183
+
184
+ The behavior is controlled by the globally NO_EXTRA_4K_HEAP define below.
159
185
160
- /* provided or not by boards.txt */
161
- /* #define NO_EXTRA_4K_HEAP */
186
+ References:
187
+ https://github.com/esp8266/Arduino/pull/4553
188
+ https://github.com/esp8266/Arduino/pull/4622
189
+ https://github.com/esp8266/Arduino/issues/4779
190
+ https://github.com/esp8266/Arduino/pull/4889
162
191
192
+ */
163
193
164
194
#ifdef NO_EXTRA_4K_HEAP
165
195
/* this is the default NONOS-SDK user's heap location */
@@ -169,12 +199,19 @@ cont_t g_cont __attribute__ ((aligned (16)));
169
199
extern " C" void ICACHE_RAM_ATTR app_entry (void )
170
200
{
171
201
#ifdef NO_EXTRA_4K_HEAP
202
+
203
+ /* this is the default NONOS-SDK user's heap location */
172
204
g_pcont = &g_cont;
205
+
173
206
#else
174
- /* Allocate continuation context on this stack, and save pointer to it. */
207
+
208
+ /* Allocate continuation context on this SYS stack,
209
+ and save pointer to it. */
175
210
cont_t s_cont __attribute__ ((aligned (16 )));
176
211
g_pcont = &s_cont;
212
+
177
213
#endif
214
+
178
215
/* Call the entry point of the SDK code. */
179
216
call_user_start ();
180
217
}
0 commit comments