Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase free IRAM #5499

Merged
merged 10 commits into from
Dec 15, 2018
Merged

Increase free IRAM #5499

merged 10 commits into from
Dec 15, 2018

Conversation

earlephilhower
Copy link
Collaborator

Move system fault handler to flash, use new printf

  • The __wrap_system_restart call has been in flash for quite a while and
    seems to be working fine. There were some support routines that were
    placed in IRAM (mistakenly thinking the wrap_restart caller was also in
    IRAM) which are now moved to flash.
  • Clean up the printf code to use the new stdlib which handles PGM_P
    strings as format and arguments without any difficulty.

Move functions out of IRAM when possible

  • umm_init() is called in OS startup after flash is enabled, and never again.
  • cont_get_free_stack() shouldn't be called from IRQ.

Make STR macro more unique

  • Add double-underscores to some string assistance macros to avoid
    conflicts with user applications.

Earle F. Philhower, III and others added 4 commits December 13, 2018 15:32
umm_init() is called in OS startup after flash is enabled, and never
again.

cont_get_free_stack() shouldn't be called from IRQ.

Don't inline _iram_read_byte() function.
The __wrap_system_restart call has been in flash for quite a while and
seems to be working fine.  There were some support routines that were
placed in IRAM (mistakenly thinking the wrap_restart caller was also in
IRAM) which are now moved to flash.

Clean up the printf code to use the new stdlib which handles PGM_P
strings as format and arguments without any difficulty.
Add double-underscores to some string assistance macros to avoid
conflicts with user applications.
@earlephilhower
Copy link
Collaborator Author

As a simple test, the ESPEasy sketch from #5476 shows:

  • BIN size = 274 bytes saved
  • HEAP = 0 change
  • IRAM = 672 bytes saved

Before merge I need to manually run a fault test for each of the many, many ways the core can crash, just to verify none of the string replacements got broken.

Earle F. Philhower, III added 2 commits December 14, 2018 09:21
Save ~2KB final bin size by using a ets_printf_P function and not
an inline macro.  IRAM and HEAP unaffected.
@earlephilhower
Copy link
Collaborator Author

Latest push reduces, in total:
BIN: 2638 bytes(!)
IRAM: 672
HEAP: 0

Store a copy of the incoming stack pointer in the postmortem in order
to avoid actually changing the SP when a crash happend in BearSSL.
Use the term "Unhandled C++ exception" instead of just "Unhandled
exception" to make it clear such crashes are caused by a C++ throw
and now a system exception.
@earlephilhower
Copy link
Collaborator Author

Tested an uncaught throw, a false assert, a null-reference, a processor exception in an interrupt, and a ROM exception, and they all dumped and decoded fine (when using #5502 toolchain GDB to avoid the dynlink problem).

#include <assert.h>
#include <core_esp8266_waveform.h>

static uint32_t ICACHE_RAM_ATTR boom()
{
  static int cnt=0;
  if (++cnt==100) *(int*)0=1;
  return 10000;
}

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
Serial.printf("hello\n");
//throw(std::runtime_error("oops"));
//assert(1==2);
//*(int*)0=1;
//setTimer1Callback(boom);
os_printf(NULL);
}

void loop() {
}

@devyte
Copy link
Collaborator

devyte commented Dec 15, 2018

Does it make sense to turn those tests into formal device tests?

@earlephilhower
Copy link
Collaborator Author

It may be possible with lots of effort, but doesn't fit into the existing framework at all.

Since your main app code no longer runs when the expected behavior happens, the pass/fail prints can never happen. So can't use the test harness. Some complicated expect jiggery might be doable, but these will not be exact matches (i.e. stack pointer will change slightly, PC address, etc. depending on build).

@earlephilhower earlephilhower merged commit 8e46a33 into esp8266:master Dec 15, 2018
@earlephilhower earlephilhower deleted the iram branch December 15, 2018 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants