Skip to content

Commit d97e0fb

Browse files
committed
Merge branch 'master' into ssltimeout
2 parents ed0d6fa + a76ef29 commit d97e0fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+814
-475
lines changed

boards.txt

+267
Large diffs are not rendered by default.

bootloaders/eboot/eboot.elf

84 Bytes
Binary file not shown.

cores/esp8266/core_esp8266_main.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ extern "C" uint8_t uart_rx_one_char_block();
424424
#include "flash_hal.h"
425425
#endif
426426

427+
extern "C" void user_rf_pre_init();
428+
427429
extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
428430
{
429431
const char *flash_map_str = NULL;
@@ -623,16 +625,26 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
623625
uart_rx_one_char_block(); // Someone said hello - repeat message
624626
} while(true);
625627
}
628+
/*
629+
The function user_rf_pre_init() is no longer called from SDK 3.0 and up.
630+
The SDK manual and release notes skipped this detail. The 2023 ESP-FAQ
631+
hints at the change with "* Call system_phy_set_powerup_option(3) in
632+
function user_pre_init or user_rf_pre_init"
633+
https://docs.espressif.com/_/downloads/espressif-esp-faq/en/latest/pdf/#page=14
634+
635+
Add call to user_rf_pre_init(), so we can still perform early calls like
636+
system_phy_set_rfoption(rf_mode), system_phy_set_powerup_option(2), etc.
637+
638+
Placement, should this be at the beginning or end of user_pre_init()?
639+
By the end, we have registered the PHY_DATA partition; however, PHY_DATA
640+
read occurs after return and before user_init() is called.
641+
*/
642+
user_rf_pre_init();
626643
}
627644
#endif // #if (NONOSDK >= (0x30000))
628645

629646
extern "C" void user_init(void) {
630647

631-
#if (NONOSDK >= (0x30000))
632-
extern void user_rf_pre_init();
633-
user_rf_pre_init(); // Stop spoofing logic
634-
#endif
635-
636648
struct rst_info *rtc_info_ptr = system_get_rst_info();
637649
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
638650

cores/esp8266/core_esp8266_phy.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ extern int IRAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t
320320
return __real_spi_flash_read(addr, dst, size);
321321
}
322322

323+
#if (NONOSDK >= (0x30000))
324+
spoof_init_data = false;
325+
#endif
323326
memcpy(dst, phy_init_data, sizeof(phy_init_data));
324327
((uint8_t*)dst)[107] = __get_adc_mode();
325328
return 0;
@@ -340,13 +343,13 @@ extern int __get_adc_mode(void)
340343
extern void __run_user_rf_pre_init(void) __attribute__((weak));
341344
extern void __run_user_rf_pre_init(void)
342345
{
343-
return; // default do noting
346+
return; // default do nothing
344347
}
345348

346349
#if (NONOSDK >= (0x30000))
347350
void sdk3_begin_phy_data_spoof(void)
348351
{
349-
spoof_init_data = true;
352+
spoof_init_data = true;
350353
}
351354
#else
352355
uint32_t user_rf_cal_sector_set(void)
@@ -359,7 +362,9 @@ uint32_t user_rf_cal_sector_set(void)
359362
void user_rf_pre_init()
360363
{
361364
// *((volatile uint32_t*) 0x60000710) = 0;
365+
#if (NONOSDK < (0x30000))
362366
spoof_init_data = false;
367+
#endif
363368

364369
int rf_mode = __get_rf_mode();
365370
if (rf_mode >= 0) {

cores/esp8266/debug.h

+5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7+
#define _DEBUG_LEAF_FUNCTION(...) __asm__ __volatile__("" ::: "a0", "memory")
8+
79
#ifdef DEBUG_ESP_CORE
810
#define DEBUGV(fmt, ...) ::printf((PGM_P)PSTR(fmt), ##__VA_ARGS__)
11+
#define DEBUG_LEAF_FUNCTION _DEBUG_LEAF_FUNCTION
12+
#else
13+
#define DEBUG_LEAF_FUNCTION(...)
914
#endif
1015

1116
#ifndef DEBUGV

doc/Troubleshooting/stack_dump.rst

+37-34
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ Example:
1212

1313
Exception (0): epc1=0x402103f4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
1414

15-
ctx: sys
15+
ctx: sys
1616
sp: 3ffffc10 end: 3fffffb0 offset: 01a0
1717

1818
>>>stack>>>
19-
3ffffdb0: 40223e00 3fff6f50 00000010 60000600
20-
3ffffdc0: 00000001 4021f774 3fffc250 4000050c
21-
3ffffdd0: 400043d5 00000030 00000016 ffffffff
22-
3ffffde0: 400044ab 3fffc718 3ffffed0 08000000
23-
3ffffdf0: 60000200 08000000 00000003 00000000
24-
3ffffe00: 0000ffff 00000001 04000002 003fd000
25-
3ffffe10: 3fff7188 000003fd 3fff2564 00000030
26-
3ffffe20: 40101709 00000008 00000008 00000020
27-
3ffffe30: c1948db3 394c5e70 7f2060f2 c6ba0c87
28-
3ffffe40: 3fff7058 00000001 40238d41 3fff6ff0
29-
3ffffe50: 3fff6f50 00000010 60000600 00000020
30-
3ffffe60: 402301a8 3fff7098 3fff7014 40238c77
31-
3ffffe70: 4022fb6c 40230ebe 3fff1a5b 3fff6f00
32-
3ffffe80: 3ffffec8 00000010 40231061 3fff0f90
33-
3ffffe90: 3fff6848 3ffed0c0 60000600 3fff6ae0
34-
3ffffea0: 3fff0f90 3fff0f90 3fff6848 3fff6d40
35-
3ffffeb0: 3fff28e8 40101233 d634fe1a fffeffff
36-
3ffffec0: 00000001 00000000 4022d5d6 3fff6848
37-
3ffffed0: 00000002 4000410f 3fff2394 3fff6848
38-
3ffffee0: 3fffc718 40004a3c 000003fd 3fff7188
39-
3ffffef0: 3fffc718 40101510 00000378 3fff1a5b
40-
3fffff00: 000003fd 4021d2e7 00000378 000003ff
41-
3fffff10: 00001000 4021d37d 3fff2564 000003ff
42-
3fffff20: 000003fd 60000600 003fd000 3fff2564
43-
3fffff30: ffffff00 55aa55aa 00000312 0000001c
44-
3fffff40: 0000001c 0000008a 0000006d 000003ff
45-
3fffff50: 4021d224 3ffecf90 00000000 3ffed0c0
46-
3fffff60: 00000001 4021c2e9 00000003 3fff1238
47-
3fffff70: 4021c071 3ffecf84 3ffecf30 0026a2b0
48-
3fffff80: 4021c0b6 3fffdab0 00000000 3fffdcb0
49-
3fffff90: 3ffecf40 3fffdab0 00000000 3fffdcc0
50-
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
19+
3ffffdb0: 40223e00 3fff6f50 00000010 60000600
20+
3ffffdc0: 00000001 4021f774 3fffc250 4000050c
21+
3ffffdd0: 400043d5 00000030 00000016 ffffffff
22+
3ffffde0: 400044ab 3fffc718 3ffffed0 08000000
23+
3ffffdf0: 60000200 08000000 00000003 00000000
24+
3ffffe00: 0000ffff 00000001 04000002 003fd000
25+
3ffffe10: 3fff7188 000003fd 3fff2564 00000030
26+
3ffffe20: 40101709 00000008 00000008 00000020
27+
3ffffe30: c1948db3 394c5e70 7f2060f2 c6ba0c87
28+
3ffffe40: 3fff7058 00000001 40238d41 3fff6ff0
29+
3ffffe50: 3fff6f50 00000010 60000600 00000020
30+
3ffffe60: 402301a8 3fff7098 3fff7014 40238c77
31+
3ffffe70: 4022fb6c 40230ebe 3fff1a5b 3fff6f00
32+
3ffffe80: 3ffffec8 00000010 40231061 3fff0f90
33+
3ffffe90: 3fff6848 3ffed0c0 60000600 3fff6ae0
34+
3ffffea0: 3fff0f90 3fff0f90 3fff6848 3fff6d40
35+
3ffffeb0: 3fff28e8 40101233 d634fe1a fffeffff
36+
3ffffec0: 00000001 00000000 4022d5d6 3fff6848
37+
3ffffed0: 00000002 4000410f 3fff2394 3fff6848
38+
3ffffee0: 3fffc718 40004a3c 000003fd 3fff7188
39+
3ffffef0: 3fffc718 40101510 00000378 3fff1a5b
40+
3fffff00: 000003fd 4021d2e7 00000378 000003ff
41+
3fffff10: 00001000 4021d37d 3fff2564 000003ff
42+
3fffff20: 000003fd 60000600 003fd000 3fff2564
43+
3fffff30: ffffff00 55aa55aa 00000312 0000001c
44+
3fffff40: 0000001c 0000008a 0000006d 000003ff
45+
3fffff50: 4021d224 3ffecf90 00000000 3ffed0c0
46+
3fffff60: 00000001 4021c2e9 00000003 3fff1238
47+
3fffff70: 4021c071 3ffecf84 3ffecf30 0026a2b0
48+
3fffff80: 4021c0b6 3fffdab0 00000000 3fffdcb0
49+
3fffff90: 3ffecf40 3fffdab0 00000000 3fffdcc0
50+
3fffffa0: 40000f49 40000f49 3fffdab0 40000f49
5151
<<<stack<<<
5252

5353
The first number after ``Exception`` gives the cause of the reset. a
@@ -57,7 +57,10 @@ the hex after are the stack dump.
5757
Decode
5858
~~~~~~
5959

60-
It's possible to decode the Stack to readable information. For more info see the `Esp Exception Decoder <https://github.com/me-no-dev/EspExceptionDecoder>`__ tool.
60+
It's possible to decode the Stack to readable information.
61+
You can get a copy and read about the `Esp Exception Decoder <https://github.com/me-no-dev/EspExceptionDecoder>`__ tool.
62+
63+
For a troubleshooting example using the Exception Decoder Tool, read `FAQ: My ESP Crashes <../faq/a02-my-esp-crashes.rst#exception-decoder>`__.
6164

6265
.. figure:: ESP_Exception_Decoderp.png
6366
:alt: ESP Exception Decoder

doc/faq/a02-my-esp-crashes.rst

+77-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ My ESP crashes running some code. How to troubleshoot it?
1111
- `Exception <#exception>`__
1212
- `Watchdog <#watchdog>`__
1313
- `Exception Decoder <#exception-decoder>`__
14+
- `Improving Exception Decoder Results <#improving-exception-decoder-results>`__
1415
- `Other Common Causes for Crashes <#other-causes-for-crashes>`__
1516
- `If at the Wall, Enter an Issue
1617
Report <#if-at-the-wall-enter-an-issue-report>`__
@@ -236,6 +237,7 @@ If you don't have any code for troubleshooting, use the example below:
236237

237238
void loop(){}
238239

240+
239241
Enable the Out-Of-Memory (*OOM*) debug option (in the *Tools > Debug Level*
240242
menu), compile/flash/upload this code to your ESP (Ctrl+U) and start Serial
241243
Monitor (Ctrl+Shift+M). You should shortly see ESP restarting every couple
@@ -270,31 +272,92 @@ Decoder <https://github.com/me-no-dev/EspExceptionDecoder>`__ you can
270272
track down where the module is crashing whenever you see the stack trace
271273
dropped. The same procedure applies to crashes caused by exceptions.
272274

273-
Note: To decode the exact line of code where the application
275+
Note, to decode the exact line of code where the application
274276
crashed, you need to use ESP Exception Decoder in context of sketch
275277
you have just loaded to the module for diagnosis. Decoder is not
276278
able to correctly decode the stack trace dropped by some other
277279
application not compiled and loaded from your Arduino IDE.
278280

279281

282+
Improving Exception Decoder Results
283+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284+
285+
Due to the limited resources on the device, our default compiler optimizations
286+
focus on creating the smallest code size (``.bin`` file). The GCC compiler's
287+
option ``-Os`` contains the base set of optimizations used. This set is fine for
288+
release but not ideal for debugging.
289+
290+
Our view of a crash is often the `Stack Dump <../Troubleshooting/stack_dump.rst>`__
291+
which gets copy/pasted into an Exception Decoder.
292+
For some situations, the optimizer doesn't write caller return addresses to the
293+
stack. When we crash, the list of functions called is missing. And when the
294+
crash occurs in a leaf function, there is seldom if ever any evidence of who
295+
called.
296+
297+
With the ``-Os`` option, functions called once are inlined into the calling
298+
function. A chain of these functions can optimize down to the calling function.
299+
When the crash occurs in one of these chain functions, the actual location in
300+
the source code is no longer available.
301+
302+
When you select ``Debug Optimization: Lite`` on the Arduino IDE Tools menu, it
303+
turns off ``optimize-sibling-calls``. Turning off this optimization allows more
304+
caller addresses to be written to the stack, improving the results from the
305+
Exception Decoder. Without this option, the callers involved in the crash may be
306+
missing from the Decoder results. Because of the limited stack space, there is
307+
the remote possibility that removing this optimization could lead to more
308+
frequent stack overflows. You only want to do this in a debug setting. This
309+
option does not help the chained function issue.
310+
311+
When you select ``Debug Optimization: Optimum``, you get an even more complete
312+
stack trace. For example, chained function calls may show up. This selection
313+
uses the compiler option ``-Og``. GCC considers this the ideal optimization for
314+
the "edit-compile-debug cycle" ... "producing debuggable code." You can read the
315+
specifics at `GCC's Optimize Options <https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html>`__
316+
317+
When global optimization creates build size issues or stack overflow issues,
318+
select ``Debug Optimization: None``, and use a targeted approach with
319+
``#pragma GCC optimize("Og")`` at the module level. Or, if you want to use a
320+
different set of optimizations, you can set optimizations through build options.
321+
Read more at `Global Build Options <a06-global-build-options.rst>`__.
322+
323+
For non-Arduino IDE build platforms, you may need to research how to add build
324+
options. Some build platforms already use ``-Og`` for debug builds.
325+
326+
A crash in a leaf function may not leave the caller's address on the stack.
327+
The return address can stay in a register for the duration of the call.
328+
Resulting in a crash report identifying the crashing function without a
329+
trace of who called. You can encourage the compiler to save the caller's
330+
return address by adding an inline assembly trick
331+
``__asm__ __volatile__("" ::: "a0", "memory");`` at the beginning of the
332+
function's body. Or instead, for a debug build conditional option, use the
333+
macro ``DEBUG_LEAF_FUNCTION()`` from ``#include <debug.h>``. For compiler
334+
toolchain 3.2.0 and above, the ``-Og`` option is an alternative solution.
335+
336+
In some cases, adding ``#pragma GCC optimize("Og,no-ipa-pure-const")`` to a
337+
module as well as using ``DEBUG_LEAF_FUNCTION()`` in a leaf function were
338+
needed to display a complete call chain. Or use
339+
``#pragma GCC optimize("Os,no-inline,no-optimize-sibling-calls,no-ipa-pure-const")``
340+
if you require optimization ``-Os``.
341+
342+
280343
Other Causes for Crashes
281344
~~~~~~~~~~~~~~~~~~~~~~~~
282345

283346
Interrupt Service Routines
284-
By default, all functions are compiled into flash, which means that the
285-
cache may kick in for that code. However, the cache currently can't be used
286-
during hardware interrupts. That means that, if you use a hardware ISR, such as
287-
attachInterrupt(gpio, myISR, CHANGE) for a GPIO change, the ISR must have the
288-
IRAM_ATTR attribute declared. Not only that, but the entire function tree
347+
By default, all functions are compiled into flash, which means that the
348+
cache may kick in for that code. However, the cache currently can't be used
349+
during hardware interrupts. That means that, if you use a hardware ISR, such as
350+
attachInterrupt(gpio, myISR, CHANGE) for a GPIO change, the ISR must have the
351+
IRAM_ATTR attribute declared. Not only that, but the entire function tree
289352
called from the ISR must also have the IRAM_ATTR declared.
290353
Be aware that every function that has this attribute reduces available memory.
291354

292-
In addition, it is not possible to execute delay() or yield() from an ISR,
355+
In addition, it is not possible to execute delay() or yield() from an ISR,
293356
or do blocking operations, or operations that disable the interrupts, e.g.: read
294357
a DHT.
295358

296359
Finally, an ISR has very high restrictions on timing for the executed code, meaning
297-
that executed code should not take longer than a very few microseconds. It is
360+
that executed code should not take longer than a very few microseconds. It is
298361
considered best practice to set a flag within the ISR, and then from within the loop()
299362
check and clear that flag, and execute code.
300363

@@ -303,16 +366,16 @@ Asynchronous Callbacks
303366
than ISRs, but some restrictions still apply.
304367
It is not possible to execute delay() or yield() from an asynchronous callback.
305368
Timing is not as tight as an ISR, but it should remain below a few milliseconds. This
306-
is a guideline. The hard timing requirements depend on the WiFi configuration and
369+
is a guideline. The hard timing requirements depend on the WiFi configuration and
307370
amount of traffic. In general, the CPU must not be hogged by the user code, as the
308371
longer it is away from servicing the WiFi stack, the more likely that memory corruption
309372
can happen.
310373

311374
Memory, memory, memory
312375
Running out of heap is the **most common cause for crashes**. Because the build process for
313376
the ESP leaves out exceptions (they use memory), memory allocations that fail will do
314-
so silently. A typical example is when setting or concatenating a large String. If
315-
allocation has failed internally, then the internal string copy can corrupt data, and
377+
so silently. A typical example is when setting or concatenating a large String. If
378+
allocation has failed internally, then the internal string copy can corrupt data, and
316379
the ESP will crash.
317380

318381
In addition, doing many String concatenations in sequence, e.g.: using operator+()
@@ -348,9 +411,9 @@ Memory, memory, memory
348411
* If you use std libs like std::vector, make sure to call its ::reserve() method before filling it. This allows allocating only once, which reduces mem fragmentation, and makes sure that there are no empty unused slots left over in the container at the end.
349412

350413
Stack
351-
  The amount of stack in the ESP is tiny at only 4KB. For normal development in large systems, it
414+
  The amount of stack in the ESP is tiny at only 4KB. For normal development in large systems, it
352415
is good practice to use and abuse the stack, because it is faster for allocation/deallocation, the scope of the object is well defined, and deallocation automatically happens in reverse order as allocation, which means no mem fragmentation. However, with the tiny amount of stack available in the ESP, that practice is not really viable, at least not for big objects.
353-
416+
354417
* Large objects that have internally managed memory, such as String, std::string, std::vector, etc, are ok on the stack, because they internally allocate their buffers on the heap.
355418
* Large arrays on the stack, such as uint8_t buffer[2048] should be avoided on the stack and should be dynamically allocated instead (consider smart pointers).
356419
* Objects that have large data members, such as large arrays, should also be avoided on the stack, and should be dynamically allocated (consider smart pointers).
@@ -392,7 +455,7 @@ or `esp8266 / Arduino <https://github.com/esp8266/Arduino>`__ core,
392455
types and versions of O/S, you need to provide exact information on what
393456
your application is about. Only then, people willing to look into your
394457
issue may be able to compare it to a configuration they are familiar with.
395-
If you are lucky, they may even attempt to reproduce your issue on their
458+
If you are lucky, they may even attempt to reproduce your issue on their
396459
own equipment!
397460
This will be far more difficult if you provide only vague details,
398461
so somebody would need to ask you to find out what is really happening.

doc/faq/a06-global-build-options.rst

+6-10
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ their builds.
181181

182182
There are two solutions to this issue:
183183

184-
1. Turn off the “Aggressively Cache Compiled core” feature, by setting
184+
1. Do nothing, and rely on aggressive cache workaround built into the
185+
script.
186+
2. Turn off the “Aggressively Cache Compiled core” feature, by setting
185187
``compiler.cache_core=false``.
186-
2. Rely on the not ideal fail-safe, aggressive cache workaround built
187-
into the script.
188188

189189
Using “compiler.cache_core=false”
190190
---------------------------------
@@ -253,14 +253,10 @@ problem would be cleared after a reboot. Or you can manually cleanup the
253253

254254
**Arduino command-line option overrides**
255255

256-
The script needs to know the working value of ``compiler.cache_core``
257-
that the Arduino IDE uses when building. This script can learn the state
258-
through documented locations; however, the Arduino IDE has two
259-
command-line options that can alter the results the Arduino IDE uses
260-
internally. And, the Arduino IDE does not provide a means for a script
261-
to learn the override value.
256+
If you are building with ``compiler.cache_core=true`` no action is
257+
needed. If ``false`` the script would benefit by knowing that.
262258

263-
These two command-line options are the problem:
259+
When using either of these two command-line options:
264260

265261
::
266262

0 commit comments

Comments
 (0)