From ae7bed5acfb4d74fc06ebe187eeac2bbc932fcd5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:04:17 +0100 Subject: [PATCH] Refactor lib RadioLib fixing ESP8266 panic --- lib/lib_rf/RadioLib/src/ArduinoHal.cpp | 3 ++- lib/lib_rf/RadioLib/src/Module.cpp | 12 ++++-------- lib/lib_rf/RadioLib/src/modules/SX126x/SX126x.cpp | 15 +++++---------- lib/lib_rf/RadioLibTasmotaAlert.md | 15 ++++++++++----- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/lib_rf/RadioLib/src/ArduinoHal.cpp b/lib/lib_rf/RadioLib/src/ArduinoHal.cpp index 9c5fd571a..3f7c0c9de 100644 --- a/lib/lib_rf/RadioLib/src/ArduinoHal.cpp +++ b/lib/lib_rf/RadioLib/src/ArduinoHal.cpp @@ -189,7 +189,8 @@ void inline ArduinoHal::noTone(uint32_t pin) { void inline ArduinoHal::yield() { #if !defined(RADIOLIB_YIELD_UNSUPPORTED) - ::yield(); +// ::yield(); + ::delay(0); #endif } diff --git a/lib/lib_rf/RadioLib/src/Module.cpp b/lib/lib_rf/RadioLib/src/Module.cpp index 18b675f43..c46e26e9c 100644 --- a/lib/lib_rf/RadioLib/src/Module.cpp +++ b/lib/lib_rf/RadioLib/src/Module.cpp @@ -289,8 +289,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint } else { uint32_t start = this->hal->millis(); while(this->hal->digitalRead(this->gpioPin)) { -// this->hal->yield(); - this->hal->delay(0); + this->hal->yield(); if(this->hal->millis() - start >= timeout) { RADIOLIB_DEBUG_BASIC_PRINTLN("GPIO pre-transfer timeout, is it connected?"); #if !RADIOLIB_STATIC_ONLY @@ -317,8 +316,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint this->hal->delayMicroseconds(1); uint32_t start = this->hal->millis(); while(this->hal->digitalRead(this->gpioPin)) { -// this->hal->yield(); - this->hal->delay(0); + this->hal->yield(); if(this->hal->millis() - start >= timeout) { RADIOLIB_DEBUG_BASIC_PRINTLN("GPIO post-transfer timeout, is it connected?"); #if !RADIOLIB_STATIC_ONLY @@ -391,13 +389,11 @@ void Module::waitForMicroseconds(uint32_t start, uint32_t len) { } this->TimerFlag = false; while(!this->TimerFlag) { -// this->hal->yield(); - this->hal->delay(0); + this->hal->yield(); } #else while(this->hal->micros() - start < len) { -// this->hal->yield(); - this->hal->delay(0); + this->hal->yield(); } #endif } diff --git a/lib/lib_rf/RadioLib/src/modules/SX126x/SX126x.cpp b/lib/lib_rf/RadioLib/src/modules/SX126x/SX126x.cpp index 2e6b99b10..161a52453 100644 --- a/lib/lib_rf/RadioLib/src/modules/SX126x/SX126x.cpp +++ b/lib/lib_rf/RadioLib/src/modules/SX126x/SX126x.cpp @@ -256,8 +256,7 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for packet transmission or timeout uint32_t start = this->mod->hal->micros(); while(!this->mod->hal->digitalRead(this->mod->getIrq())) { -// this->mod->hal->yield(); - this->mod->hal->delay(0); + this->mod->hal->yield(); if(this->mod->hal->micros() - start > timeout) { finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); @@ -308,8 +307,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { bool softTimeout = false; uint32_t start = this->mod->hal->micros(); while(!this->mod->hal->digitalRead(this->mod->getIrq())) { -// this->mod->hal->yield(); - this->mod->hal->delay(0); + this->mod->hal->yield(); // safety check, the timeout should be done by the radio if(this->mod->hal->micros() - start > timeout) { softTimeout = true; @@ -442,8 +440,7 @@ int16_t SX126x::scanChannel(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin) // wait for channel activity detected or timeout while(!this->mod->hal->digitalRead(this->mod->getIrq())) { -// this->mod->hal->yield(); - this->mod->hal->delay(0); + this->mod->hal->yield(); } // check CAD result @@ -571,8 +568,7 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // wait for BUSY to go low (= PA ramp up done) while(this->mod->hal->digitalRead(this->mod->getGpio())) { -// this->mod->hal->yield(); - this->mod->hal->delay(0); + this->mod->hal->yield(); } return(state); @@ -2119,8 +2115,7 @@ int16_t SX126x::config(uint8_t modem) { // wait for calibration completion this->mod->hal->delay(5); while(this->mod->hal->digitalRead(this->mod->getGpio())) { -// this->mod->hal->yield(); - this->mod->hal->delay(0); + this->mod->hal->yield(); } // check calibration result diff --git a/lib/lib_rf/RadioLibTasmotaAlert.md b/lib/lib_rf/RadioLibTasmotaAlert.md index b820680a0..3ffb450e7 100644 --- a/lib/lib_rf/RadioLibTasmotaAlert.md +++ b/lib/lib_rf/RadioLibTasmotaAlert.md @@ -4,8 +4,13 @@ Action to take in case of new release of RadioLib 20240327 -1 - Remove folder `RadioLib\examples\NonArduino` (Fixes Github vulnerability alerts) -2 - Change in file `RadioLib\src\modules\SX126x\SX126x.cpp` all occurences of ``this->mod->hal->yield();`` into ``this->mod->hal->delay(0);`` (Fixes ESP8266 Panic core_esp8266_main.cpp:133 __yield) -3 - Change in file `RadioLib\src\Module.cpp` all occurences of ``this->hal->yield();`` into ``this->hal->delay(0);`` (Fixes ESP8266 Panic core_esp8266_main.cpp:133 __yield) - - +1 - Remove folder `\lib\lib_rfRadioLib\examples\NonArduino` (Fixes Github vulnerability alerts) +2 - Change in file `\lib\lib_rf\RadioLib\src\ArduinoHal.cpp` below function (Fixes ESP8266 Panic core_esp8266_main.cpp:133 __yield) +``` +void inline ArduinoHal::yield() { + #if !defined(RADIOLIB_YIELD_UNSUPPORTED) +// ::yield(); + ::delay(0); + #endif +} +```