Browse Source

0.8.106

* fix bootloop with CMT and NRF on ESP32 #1566 #1562
pull/1584/head
lumapu 1 year ago
parent
commit
2d19138463
  1. 3
      src/CHANGES.md
  2. 7
      src/app.cpp
  3. 4
      src/app.h
  4. 61
      src/hm/NrfRadio.h
  5. 2
      src/hm/hmInverter.h
  6. 2
      src/hm/radio.h
  7. 4
      src/hms/cmt2300a.h
  8. 8
      src/hms/hmsRadio.h
  9. 10
      src/plugins/Display/Display.h
  10. 4
      src/web/RestApi.h

3
src/CHANGES.md

@ -1,5 +1,8 @@
# Development Changes # Development Changes
## 0.8.106 - 2024-04-05
* fix bootloop with CMT and NRF on ESP32 #1566 #1562
## 0.8.105 - 2024-04-05 ## 0.8.105 - 2024-04-05
* cleanup of `defines.h` * cleanup of `defines.h`
* fix compile of esp32-minimal * fix compile of esp32-minimal

7
src/app.cpp

@ -45,9 +45,7 @@ void app::setup() {
esp_task_wdt_reset(); esp_task_wdt_reset();
if(mConfig->nrf.enabled) { mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->nrf);
mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso);
}
#if defined(ESP32) #if defined(ESP32)
if(mConfig->cmt.enabled) { if(mConfig->cmt.enabled) {
mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, mConfig->sys.region); mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, mConfig->sys.region);
@ -141,8 +139,7 @@ void app::setup() {
void app::loop(void) { void app::loop(void) {
esp_task_wdt_reset(); esp_task_wdt_reset();
if(mConfig->nrf.enabled) mNrfRadio.loop();
mNrfRadio.loop();
#if defined(ESP32) #if defined(ESP32)
if(mConfig->cmt.enabled) if(mConfig->cmt.enabled)

4
src/app.h

@ -17,7 +17,7 @@
#include "defines.h" #include "defines.h"
#include "appInterface.h" #include "appInterface.h"
#include "hm/hmSystem.h" #include "hm/hmSystem.h"
#include "hm/hmRadio.h" #include "hm/NrfRadio.h"
#if defined(ESP32) #if defined(ESP32)
#include "hms/hmsRadio.h" #include "hms/hmsRadio.h"
#endif #endif
@ -409,7 +409,7 @@ class app : public IApp, public ah::Scheduler {
void notAvailChanged(void); void notAvailChanged(void);
HmSystemType mSys; HmSystemType mSys;
HmRadio<> mNrfRadio; NrfRadio<> mNrfRadio;
Communication mCommunication; Communication mCommunication;
bool mShowRebootRequest = false; bool mShowRebootRequest = false;

61
src/hm/hmRadio.h → src/hm/NrfRadio.h

@ -8,8 +8,9 @@
#include <RF24.h> #include <RF24.h>
#include "SPI.h" #include "SPI.h"
#include "radio.h" #include "Radio.h"
#include "../config/config.h" #include "../config/config.h"
#include "../config/settings.h"
#if defined(SPI_HAL) #if defined(SPI_HAL)
#include "nrfHal.h" #include "nrfHal.h"
#endif #endif
@ -28,10 +29,10 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// HM Radio class // HM Radio class
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <uint8_t IRQ_PIN = DEF_NRF_IRQ_PIN, uint8_t CE_PIN = DEF_NRF_CE_PIN, uint8_t CS_PIN = DEF_NRF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW, uint8_t SCLK_PIN = DEF_NRF_SCLK_PIN, uint8_t MOSI_PIN = DEF_NRF_MOSI_PIN, uint8_t MISO_PIN = DEF_NRF_MISO_PIN, uint32_t DTU_SN = 0x81001765> template <uint32_t DTU_SN = 0x81001765>
class HmRadio : public Radio { class NrfRadio : public Radio {
public: public:
HmRadio() { NrfRadio() {
mDtuSn = DTU_SN; mDtuSn = DTU_SN;
mIrqRcvd = false; mIrqRcvd = false;
#if defined(SPI_HAL) #if defined(SPI_HAL)
@ -40,12 +41,18 @@ class HmRadio : public Radio {
mNrf24.reset(new RF24(CE_PIN, CS_PIN, SPI_SPEED)); mNrf24.reset(new RF24(CE_PIN, CS_PIN, SPI_SPEED));
#endif #endif
} }
~HmRadio() {} ~NrfRadio() {}
void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN) { void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgNrf24_t *cfg) {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup")); DPRINTLN(DBG_VERBOSE, F("NrfRadio::setup"));
pinMode(irq, INPUT_PULLUP); mCfg = cfg;
//uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN
if(!mCfg->enabled)
return;
pinMode(mCfg->pinIrq, INPUT_PULLUP);
mSerialDebug = serialDebug; mSerialDebug = serialDebug;
mPrivacyMode = privacyMode; mPrivacyMode = privacyMode;
@ -56,7 +63,7 @@ class HmRadio : public Radio {
#ifdef ESP32 #ifdef ESP32
#if defined(SPI_HAL) #if defined(SPI_HAL)
mNrfHal.init(mosi, miso, sclk, cs, ce, SPI_SPEED); mNrfHal.init(mCfg->pinMosi, mCfg->pinMiso, mCfg->pinSclk, mCfg->pinCs, mCfg->pinCe, SPI_SPEED);
mNrf24.reset(new RF24(&mNrfHal)); mNrf24.reset(new RF24(&mNrfHal));
#else #else
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
@ -64,7 +71,7 @@ class HmRadio : public Radio {
#else #else
mSpi.reset(new SPIClass(VSPI)); mSpi.reset(new SPIClass(VSPI));
#endif #endif
mSpi->begin(sclk, miso, mosi, cs); mSpi->begin(mCfg->pinSclk, mCfg->pinMiso, mCfg->pinMosi, mCfg->pinCs);
#endif #endif
#else #else
//the old ESP82xx cannot freely place their SPI pins //the old ESP82xx cannot freely place their SPI pins
@ -75,7 +82,7 @@ class HmRadio : public Radio {
#if defined(SPI_HAL) #if defined(SPI_HAL)
mNrf24->begin(); mNrf24->begin();
#else #else
mNrf24->begin(mSpi.get(), ce, cs); mNrf24->begin(mSpi.get(), mCfg->pinCe, mCfg->pinCs);
#endif #endif
mNrf24->setRetries(3, 15); // wait 3*250 = 750us, 16 * 250us -> 4000us = 4ms mNrf24->setRetries(3, 15); // wait 3*250 = 750us, 16 * 250us -> 4000us = 4ms
@ -99,21 +106,24 @@ class HmRadio : public Radio {
} }
// returns true if communication is active // returns true if communication is active
bool loop(void) override { void loop(void) {
if(!mCfg->enabled)
return;
if (!mIrqRcvd && !mNRFisInRX) if (!mIrqRcvd && !mNRFisInRX)
return false; // first quick check => nothing to do at all here return; // first quick check => nothing to do at all here
if(NULL == mLastIv) // prevent reading on NULL object! if(NULL == mLastIv) // prevent reading on NULL object!
return false; return;
if(!mIrqRcvd) { // no news from nRF, check timers if(!mIrqRcvd) { // no news from nRF, check timers
if ((millis() - mTimeslotStart) < innerLoopTimeout) if ((millis() - mTimeslotStart) < innerLoopTimeout)
return true; // nothing to do, still waiting return; // nothing to do, still waiting
if (mRadioWaitTime.isTimeout()) { // timeout reached! if (mRadioWaitTime.isTimeout()) { // timeout reached!
mNRFisInRX = false; mNRFisInRX = false;
rx_ready = false; rx_ready = false;
return false; return;
} }
// otherwise switch to next RX channel // otherwise switch to next RX channel
@ -132,7 +142,7 @@ class HmRadio : public Radio {
mNrf24->setChannel(mRfChLst[tempRxChIdx]); mNrf24->setChannel(mRfChLst[tempRxChIdx]);
isRxInit = false; isRxInit = false;
return true; // communicating, but changed RX channel return; // communicating, but changed RX channel
} else { } else {
// here we got news from the nRF // here we got news from the nRF
mIrqRcvd = false; mIrqRcvd = false;
@ -145,7 +155,7 @@ class HmRadio : public Radio {
if(mNRFisInRX) { if(mNRFisInRX) {
DPRINTLN(DBG_WARN, F("unexpected tx irq!")); DPRINTLN(DBG_WARN, F("unexpected tx irq!"));
return false; return;
} }
mNRFisInRX = true; mNRFisInRX = true;
@ -181,18 +191,23 @@ class HmRadio : public Radio {
} }
} }
rx_ready = false; // reset rx_ready = false; // reset
return mNRFisInRX; return;
} }
} }
return false; return;
} }
bool isChipConnected(void) const override { bool isChipConnected(void) const override {
if(!mCfg->enabled)
return false;
return mNrf24->isChipConnected(); return mNrf24->isChipConnected();
} }
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override { void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
if(!mCfg->enabled)
return;
DPRINT_IVID(DBG_INFO, iv->id); DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("sendControlPacket cmd: ")); DBGPRINT(F("sendControlPacket cmd: "));
DBGHEXLN(cmd); DBGHEXLN(cmd);
@ -279,13 +294,14 @@ class HmRadio : public Radio {
} }
uint8_t getDataRate(void) const { uint8_t getDataRate(void) const {
if(!mNrf24->isChipConnected()) if(!isChipConnected())
return 3; // unknown return 3; // unknown
return mNrf24->getDataRate(); return mNrf24->getDataRate();
} }
bool isPVariant(void) const { bool isPVariant(void) const {
return mNrf24->isPVariant(); if(!isChipConnected())
return mNrf24->isPVariant();
} }
private: private:
@ -413,6 +429,7 @@ class HmRadio : public Radio {
} }
uint64_t mDtuRadioId = 0ULL; uint64_t mDtuRadioId = 0ULL;
cfgNrf24_t *mCfg = nullptr;
const uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz const uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz
uint8_t mTxChIdx = 0; uint8_t mTxChIdx = 0;
uint8_t mRxChIdx = 0; uint8_t mRxChIdx = 0;

2
src/hm/hmInverter.h

@ -22,7 +22,7 @@
#include <functional> #include <functional>
#include "../config/settings.h" #include "../config/settings.h"
#include "radio.h" #include "Radio.h"
/** /**
* For values which are of interest and not transmitted by the inverter can be * For values which are of interest and not transmitted by the inverter can be
* calculated automatically. * calculated automatically.

2
src/hm/radio.h

@ -33,7 +33,7 @@ class Radio {
virtual uint16_t getBaseFreqMhz() { return 0; } virtual uint16_t getBaseFreqMhz() { return 0; }
virtual uint16_t getBootFreqMhz() { return 0; } virtual uint16_t getBootFreqMhz() { return 0; }
virtual std::pair<uint16_t,uint16_t> getFreqRangeMhz(void) { return std::make_pair(0, 0); } virtual std::pair<uint16_t,uint16_t> getFreqRangeMhz(void) { return std::make_pair(0, 0); }
virtual bool loop(void) = 0; virtual void loop(void) = 0;
Radio() : mTxBuf{} {} Radio() : mTxBuf{} {}

4
src/hms/cmt2300a.h

@ -6,7 +6,7 @@
#ifndef __CMT2300A_H__ #ifndef __CMT2300A_H__
#define __CMT2300A_H__ #define __CMT2300A_H__
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL) #if defined(SPI_HAL)
#include "cmtHal.h" #include "cmtHal.h"
#else #else
#include "esp32_3wSpi.h" #include "esp32_3wSpi.h"
@ -545,7 +545,7 @@ class Cmt2300a {
} }
private: private:
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL) #if defined(SPI_HAL)
cmtHal mSpi; cmtHal mSpi;
#else #else
esp32_3wSpi mSpi; esp32_3wSpi mSpi;

8
src/hms/hmsRadio.h

@ -7,7 +7,7 @@
#define __HMS_RADIO_H__ #define __HMS_RADIO_H__
#include "cmt2300a.h" #include "cmt2300a.h"
#include "../hm/radio.h" #include "../hm/Radio.h"
//#define CMT_SWITCH_CHANNEL_CYCLE 5 //#define CMT_SWITCH_CHANNEL_CYCLE 5
@ -24,16 +24,16 @@ class CmtRadio : public Radio {
mTxBuf.fill(0); mTxBuf.fill(0);
} }
bool loop() override { void loop() override {
mCmt.loop(); mCmt.loop();
if((!mIrqRcvd) && (!mRqstGetRx)) if((!mIrqRcvd) && (!mRqstGetRx))
return false; return;
getRx(); getRx();
if(CmtStatus::SUCCESS == mCmt.goRx()) { if(CmtStatus::SUCCESS == mCmt.goRx()) {
mIrqRcvd = false; mIrqRcvd = false;
mRqstGetRx = false; mRqstGetRx = false;
} }
return false; return;
} }
bool isChipConnected(void) const override { bool isChipConnected(void) const override {

10
src/plugins/Display/Display.h

@ -7,7 +7,7 @@
#include <U8g2lib.h> #include <U8g2lib.h>
#include "../../hm/hmSystem.h" #include "../../hm/hmSystem.h"
#include "../../hm/hmRadio.h" #include "../../hm/NrfRadio.h"
#include "../../utils/helper.h" #include "../../utils/helper.h"
#include "../plugin_lang.h" #include "../plugin_lang.h"
#include "Display_Mono.h" #include "Display_Mono.h"
@ -25,9 +25,9 @@ class Display {
mMono = NULL; mMono = NULL;
} }
void setup(IApp *app, display_t *cfg, HMSYSTEM *sys, RADIO *hmradio, RADIO *hmsradio, uint32_t *utcTs) { void setup(IApp *app, display_t *cfg, HMSYSTEM *sys, RADIO *nrfRadio, RADIO *hmsradio, uint32_t *utcTs) {
mApp = app; mApp = app;
mHmRadio = hmradio; mNrfRadio = nrfRadio;
mHmsRadio = hmsradio; mHmsRadio = hmsradio;
mCfg = cfg; mCfg = cfg;
mSys = sys; mSys = sys;
@ -149,7 +149,7 @@ class Display {
mDisplayData.totalYieldDay = totalYieldDay; mDisplayData.totalYieldDay = totalYieldDay;
mDisplayData.totalYieldTotal = totalYieldTotal; mDisplayData.totalYieldTotal = totalYieldTotal;
bool nrf_en = mApp->getNrfEnabled(); bool nrf_en = mApp->getNrfEnabled();
bool nrf_ok = nrf_en && mHmRadio->isChipConnected(); bool nrf_ok = nrf_en && mNrfRadio->isChipConnected();
#if defined(ESP32) #if defined(ESP32)
bool cmt_en = mApp->getCmtEnabled(); bool cmt_en = mApp->getCmtEnabled();
bool cmt_ok = cmt_en && mHmsRadio->isChipConnected(); bool cmt_ok = cmt_en && mHmsRadio->isChipConnected();
@ -231,7 +231,7 @@ class Display {
uint32_t *mUtcTs = nullptr; uint32_t *mUtcTs = nullptr;
display_t *mCfg = nullptr; display_t *mCfg = nullptr;
HMSYSTEM *mSys = nullptr; HMSYSTEM *mSys = nullptr;
RADIO *mHmRadio = nullptr; RADIO *mNrfRadio = nullptr;
RADIO *mHmsRadio = nullptr; RADIO *mHmsRadio = nullptr;
uint16_t mRefreshCycle = 0; uint16_t mRefreshCycle = 0;

4
src/web/RestApi.h

@ -40,7 +40,7 @@ class RestApi {
mApp = app; mApp = app;
mSrv = srv; mSrv = srv;
mSys = sys; mSys = sys;
mRadioNrf = (HmRadio<>*)mApp->getRadioObj(true); mRadioNrf = (NrfRadio<>*)mApp->getRadioObj(true);
#if defined(ESP32) #if defined(ESP32)
mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false); mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false);
#endif #endif
@ -1112,7 +1112,7 @@ class RestApi {
private: private:
IApp *mApp = nullptr; IApp *mApp = nullptr;
HMSYSTEM *mSys = nullptr; HMSYSTEM *mSys = nullptr;
HmRadio<> *mRadioNrf = nullptr; NrfRadio<> *mRadioNrf = nullptr;
#if defined(ESP32) #if defined(ESP32)
CmtRadio<> *mRadioCmt = nullptr; CmtRadio<> *mRadioCmt = nullptr;
#endif #endif

Loading…
Cancel
Save