diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index d8bf8bb11d..eff43dfdba 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -23,14 +23,23 @@ void ICACHE_RAM_ATTR hexdump(const void *mem, uint32_t len, uint8_t cols) { const uint8_t* src = (const uint8_t*) mem; - os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); + ::printf((PGM_P)F("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)"), (ptrdiff_t)src, len, len); for(uint32_t i = 0; i < len; i++) { if(i % cols == 0) { - os_printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); + ::printf((PGM_P)F("\n[0x%08X] 0x%08X: "), (ptrdiff_t)src, i); yield(); } - os_printf("%02X ", *src); + ::printf((PGM_P)F("%02X "), *src); src++; } os_printf("\n"); } + +#ifndef NDEBUG +void assert_iram (uintptr_t address) { + if (address < 0x40100000 || address >= 0x40110000) { + ::printf((PGM_P)F("all ISR must be in IRAM with ICACHE_RAM_ATTR\r\n")); + panic(); + } +} +#endif diff --git a/cores/esp8266/debug.h b/cores/esp8266/debug.h index fab128253c..abac756832 100644 --- a/cores/esp8266/debug.h +++ b/cores/esp8266/debug.h @@ -29,5 +29,11 @@ void __panic_func(const char* file, int line, const char* func) __attribute__((n } #endif +#ifdef NDEBUG +void assert_iram (uintptr_t iram_function_addr) { } +#else +void assert_iram (uintptr_t iram_function_addr); +#endif +#define check_function_is_in_iram(f) do { assert_iram((intptr_t)f); } while (0) #endif//ARD_DEBUG_H diff --git a/libraries/SPISlave/src/SPISlave.cpp b/libraries/SPISlave/src/SPISlave.cpp index a88915b518..e621cba5d5 100644 --- a/libraries/SPISlave/src/SPISlave.cpp +++ b/libraries/SPISlave/src/SPISlave.cpp @@ -93,18 +93,22 @@ void SPISlaveClass::setStatus(uint32_t status) } void SPISlaveClass::onData(SpiSlaveDataHandler cb) { + check_function_is_in_iram(cb); _data_cb = cb; } void SPISlaveClass::onDataSent(SpiSlaveSentHandler cb) { + check_function_is_in_iram(cb); _data_sent_cb = cb; } void SPISlaveClass::onStatus(SpiSlaveStatusHandler cb) { + check_function_is_in_iram(cb); _status_cb = cb; } void SPISlaveClass::onStatusSent(SpiSlaveSentHandler cb) { + check_function_is_in_iram(cb); _status_sent_cb = cb; }