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
3 changes: 2 additions & 1 deletion cores/esp8266/cont_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ int ICACHE_RAM_ATTR cont_check(cont_t* cont) {
return 0;
}

int ICACHE_RAM_ATTR cont_get_free_stack(cont_t* cont) {
// No need for this to be in IRAM, not expected to be IRQ called
int cont_get_free_stack(cont_t* cont) {
uint32_t *head = cont->stack;
int freeWords = 0;

Expand Down
46 changes: 16 additions & 30 deletions cores/esp8266/core_esp8266_postmortem.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,18 @@ extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack,

extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));

// Single, non-inlined copy of pgm_read_byte to save IRAM space (as this is not timing critical)
static char ICACHE_RAM_ATTR iram_read_byte (const char *addr) {
return pgm_read_byte(addr);
}

// Required to output the s_panic_file, it's stored in PMEM
#define ets_puts_P(pstr) \
{ \
char c; \
do { \
c = iram_read_byte(pstr++); \
if (c) ets_putc(c); \
} while (c); \
}

// Place these strings in .text because the SPI interface may be in bad shape during an exception.
// Prints need to use our library function to allow for file and function
// to be safely accessed from flash. This macro encapsulates the snprintf()
// [which by definition will 0-terminate] and dumping to the UART
#define ets_printf_P(str, ...) \
{ \
static const char istr[] ICACHE_RAM_ATTR = (str); \
char mstr[sizeof(str)]; \
for (size_t i=0; i < sizeof(str); i++) mstr[i] = iram_read_byte(&istr[i]); \
ets_printf(mstr, ##__VA_ARGS__); \
char destStr[160]; \
snprintf(destStr, sizeof(destStr), PSTR(str), ##__VA_ARGS__); \
char *c = destStr; \
while (*c) { \
ets_putc(*(c++)); \
} \
}

void __wrap_system_restart_local() {
Expand All @@ -110,18 +100,14 @@ void __wrap_system_restart_local() {
ets_install_putc1(&uart_write_char_d);

if (s_panic_line) {
ets_printf_P("\nPanic ");
ets_puts_P(s_panic_file); // This is in PROGMEM, need special output because ets_printf can't handle ROM parameters
ets_printf_P(":%d %s", s_panic_line, s_panic_func);
ets_printf_P("\nPanic %S:%d %S", s_panic_file, s_panic_line, s_panic_func);
if (s_panic_what) {
ets_printf_P(": Assertion '");
ets_puts_P(s_panic_what); // This is also in PMEM
ets_printf_P("' failed.");
ets_printf_P(": Assertion '%S' failed.", s_panic_what);
}
ets_putc('\n');
}
else if (s_unhandled_exception) {
ets_printf_P("\nUnhandled exception: %s\n", s_unhandled_exception);
ets_printf_P("\nUnhandled exception: %S\n", s_unhandled_exception);
}
else if (s_abort_called) {
ets_printf_P("\nAbort called\n");
Expand Down Expand Up @@ -156,19 +142,19 @@ void __wrap_system_restart_local() {

if (sp > stack_thunk_get_stack_bot() && sp <= stack_thunk_get_stack_top()) {
// BearSSL we dump the BSSL second stack and then reset SP back to the main cont stack
ets_printf_P("\nctx: bearssl \n");
ets_printf_P("\nctx: bearssl\n");
ets_printf_P("sp: %08x end: %08x offset: %04x\n", sp, stack_thunk_get_stack_top(), offset);
print_stack(sp + offset, stack_thunk_get_stack_top());
offset = 0; // No offset needed anymore, the exception info was stored in the bssl stack
sp = stack_thunk_get_cont_sp();
}

if (sp > cont_stack_start && sp < cont_stack_end) {
ets_printf_P("\nctx: cont \n");
ets_printf_P("\nctx: cont\n");
stack_end = cont_stack_end;
}
else {
ets_printf_P("\nctx: sys \n");
ets_printf_P("\nctx: sys\n");
stack_end = 0x3fffffb0;
// it's actually 0x3ffffff0, but the stuff below ets_run
// is likely not really relevant to the crash
Expand All @@ -192,7 +178,7 @@ void __wrap_system_restart_local() {
}


static void ICACHE_RAM_ATTR print_stack(uint32_t start, uint32_t end) {
static void print_stack(uint32_t start, uint32_t end) {
for (uint32_t pos = start; pos < end; pos += 0x10) {
uint32_t* values = (uint32_t*)(pos);

Expand Down
12 changes: 6 additions & 6 deletions cores/esp8266/core_esp8266_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include <core_version.h>

#define STRHELPER(x) #x
#define STR(x) STRHELPER(x)
#define __STRHELPER(x) #x
#define __STR(x) __STRHELPER(x)
earlephilhower marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
extern "C++"
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace esp8266 {
constexpr
int coreVersionMajor ()
{
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 0);
return conststr::parseNthInteger(__STR(ARDUINO_ESP8266_GIT_DESC), 0);
}

/*
Expand All @@ -120,7 +120,7 @@ int coreVersionMajor ()
constexpr
int coreVersionMinor ()
{
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 1);
return conststr::parseNthInteger(__STR(ARDUINO_ESP8266_GIT_DESC), 1);
}

/*
Expand All @@ -129,7 +129,7 @@ int coreVersionMinor ()
constexpr
int coreVersionRevision ()
{
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 2);
return conststr::parseNthInteger(__STR(ARDUINO_ESP8266_GIT_DESC), 2);
}

/*
Expand All @@ -139,7 +139,7 @@ int coreVersionRevision ()
constexpr
int coreVersionSubRevision ()
{
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 3);
return conststr::parseNthInteger(__STR(ARDUINO_ESP8266_GIT_DESC), 3);
}

/*
Expand Down
5 changes: 3 additions & 2 deletions cores/esp8266/umm_malloc/umm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,9 @@ static unsigned short int umm_assimilate_down( unsigned short int c, unsigned sh
}

/* ------------------------------------------------------------------------- */

void umm_init( void ) {
/* This function called only one time during OS startup after flash is */
/* enabled. No need to keep it in IRAM. */
void ICACHE_FLASH_ATTR umm_init( void ) {
/* init heap pointer and size, and memset it to 0 */
umm_heap = (umm_block *)UMM_MALLOC_CFG__HEAP_ADDR;
umm_numblocks = (UMM_MALLOC_CFG__HEAP_SIZE / sizeof(umm_block));
Expand Down