From f543a69022de16664e8a429b6ee73d0163da0f6e Mon Sep 17 00:00:00 2001 From: DalesLandNet Date: Tue, 13 Jul 2021 11:34:45 +0100 Subject: [PATCH] [Issue #79] ESP32- Core panic when using in conjunction with the "preferences" library. --- src/SDI12.cpp | 8 ++++---- src/SDI12_boards.cpp | 2 +- src/SDI12_boards.h | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/SDI12.cpp b/src/SDI12.cpp index 58e1d5c..31d1105 100644 --- a/src/SDI12.cpp +++ b/src/SDI12.cpp @@ -874,7 +874,7 @@ String SDI12::addCRCResponse(String &resp) { } char * SDI12::addCRCResponse(char *resp) { - char *crcStr[3] = {0}; + char crcStr[3] = {0}; uint16_t crc = 0; for(int i = 0; i < strlen(resp); i++) { @@ -979,12 +979,12 @@ takes to either a HIGH vs a LOW, and helps maintain a constant timing. the ISR is instructed to call handleInterrupt() when they trigger. */ // 7.1 - Passes off responsibility for the interrupt to the active object. -void SDI12::handleInterrupt(){ +void USE_INSTRUCTION_RAM SDI12::handleInterrupt(){ if (_activeObject) _activeObject->receiveISR(); } // 7.2 - Creates a blank slate of bits for an incoming character -void SDI12::startChar() +void USE_INSTRUCTION_RAM SDI12::startChar() { rxState = 0; // got a start bit rxMask = 0x01; // 0b00000001, bit mask, lsb first @@ -992,7 +992,7 @@ void SDI12::startChar() } // startChar // 7.3 - The actual interrupt service routine -void SDI12::receiveISR() +void USE_INSTRUCTION_RAM SDI12::receiveISR() { sdi12timer_t thisBitTCNT = READTIME; // time of this data transition (plus ISR latency) diff --git a/src/SDI12_boards.cpp b/src/SDI12_boards.cpp index d3eacae..1298c7f 100644 --- a/src/SDI12_boards.cpp +++ b/src/SDI12_boards.cpp @@ -228,7 +228,7 @@ SDI12Timer::SDI12Timer(){} void SDI12Timer::configSDI12TimerPrescale(void) { } void SDI12Timer::resetSDI12TimerPrescale(void) { } - sdi12timer_t SDI12Timer::SDI12TimerRead(void) + sdi12timer_t USE_INSTRUCTION_RAM SDI12Timer::SDI12TimerRead(void) { // Its a one microsecond clock but we want 64uS ticks so divide by 64 i.e. right shift 6 return((sdi12timer_t) (micros() >> 6)); diff --git a/src/SDI12_boards.h b/src/SDI12_boards.h index 542a005..7dcd054 100644 --- a/src/SDI12_boards.h +++ b/src/SDI12_boards.h @@ -14,6 +14,14 @@ sensors. This library provides a general software solution, without requiring typedef uint8_t sdi12timer_t; #endif +#if defined(ESP32) +#define USE_INSTRUCTION_RAM IRAM_ATTR +#elif defined(ESP8266) +#define USE_INSTRUCTION_RAM ICACHE_RAM_ATTR +#else +#define USE_INSTRUCTION_RAM +#endif + class SDI12Timer { public: