Browse Source

0.8.106

* fix bootloop with CMT and NRF on ESP32 #1566 #1562
pull/1584/head
lumapu 10 months 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
## 0.8.106 - 2024-04-05
* fix bootloop with CMT and NRF on ESP32 #1566 #1562
## 0.8.105 - 2024-04-05
* cleanup of `defines.h`
* fix compile of esp32-minimal

7
src/app.cpp

@ -45,9 +45,7 @@ void app::setup() {
esp_task_wdt_reset();
if(mConfig->nrf.enabled) {
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);
}
mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->nrf);
#if defined(ESP32)
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);
@ -141,8 +139,7 @@ void app::setup() {
void app::loop(void) {
esp_task_wdt_reset();
if(mConfig->nrf.enabled)
mNrfRadio.loop();
mNrfRadio.loop();
#if defined(ESP32)
if(mConfig->cmt.enabled)

4
src/app.h

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

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

@ -8,8 +8,9 @@
#include <RF24.h>
#include "SPI.h"
#include "radio.h"
#include "Radio.h"
#include "../config/config.h"
#include "../config/settings.h"
#if defined(SPI_HAL)
#include "nrfHal.h"
#endif
@ -28,10 +29,10 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
//-----------------------------------------------------------------------------
// 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>
class HmRadio : public Radio {
template <uint32_t DTU_SN = 0x81001765>
class NrfRadio : public Radio {
public:
HmRadio() {
NrfRadio() {
mDtuSn = DTU_SN;
mIrqRcvd = false;
#if defined(SPI_HAL)
@ -40,12 +41,18 @@ class HmRadio : public Radio {
mNrf24.reset(new RF24(CE_PIN, CS_PIN, SPI_SPEED));
#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) {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgNrf24_t *cfg) {
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;
mPrivacyMode = privacyMode;
@ -56,7 +63,7 @@ class HmRadio : public Radio {
#ifdef ESP32
#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));
#else
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
@ -64,7 +71,7 @@ class HmRadio : public Radio {
#else
mSpi.reset(new SPIClass(VSPI));
#endif
mSpi->begin(sclk, miso, mosi, cs);
mSpi->begin(mCfg->pinSclk, mCfg->pinMiso, mCfg->pinMosi, mCfg->pinCs);
#endif
#else
//the old ESP82xx cannot freely place their SPI pins
@ -75,7 +82,7 @@ class HmRadio : public Radio {
#if defined(SPI_HAL)
mNrf24->begin();
#else
mNrf24->begin(mSpi.get(), ce, cs);
mNrf24->begin(mSpi.get(), mCfg->pinCe, mCfg->pinCs);
#endif
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
bool loop(void) override {
void loop(void) {
if(!mCfg->enabled)
return;
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!
return false;
return;
if(!mIrqRcvd) { // no news from nRF, check timers
if ((millis() - mTimeslotStart) < innerLoopTimeout)
return true; // nothing to do, still waiting
return; // nothing to do, still waiting
if (mRadioWaitTime.isTimeout()) { // timeout reached!
mNRFisInRX = false;
rx_ready = false;
return false;
return;
}
// otherwise switch to next RX channel
@ -132,7 +142,7 @@ class HmRadio : public Radio {
mNrf24->setChannel(mRfChLst[tempRxChIdx]);
isRxInit = false;
return true; // communicating, but changed RX channel
return; // communicating, but changed RX channel
} else {
// here we got news from the nRF
mIrqRcvd = false;
@ -145,7 +155,7 @@ class HmRadio : public Radio {
if(mNRFisInRX) {
DPRINTLN(DBG_WARN, F("unexpected tx irq!"));
return false;
return;
}
mNRFisInRX = true;
@ -181,18 +191,23 @@ class HmRadio : public Radio {
}
}
rx_ready = false; // reset
return mNRFisInRX;
return;
}
}
return false;
return;
}
bool isChipConnected(void) const override {
if(!mCfg->enabled)
return false;
return mNrf24->isChipConnected();
}
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
if(!mCfg->enabled)
return;
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("sendControlPacket cmd: "));
DBGHEXLN(cmd);
@ -279,13 +294,14 @@ class HmRadio : public Radio {
}
uint8_t getDataRate(void) const {
if(!mNrf24->isChipConnected())
if(!isChipConnected())
return 3; // unknown
return mNrf24->getDataRate();
}
bool isPVariant(void) const {
return mNrf24->isPVariant();
if(!isChipConnected())
return mNrf24->isPVariant();
}
private:
@ -413,6 +429,7 @@ class HmRadio : public Radio {
}
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
uint8_t mTxChIdx = 0;
uint8_t mRxChIdx = 0;

2
src/hm/hmInverter.h

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

2
src/hm/radio.h

@ -33,7 +33,7 @@ class Radio {
virtual uint16_t getBaseFreqMhz() { return 0; }
virtual uint16_t getBootFreqMhz() { return 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{} {}

4
src/hms/cmt2300a.h

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

8
src/hms/hmsRadio.h

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

10
src/plugins/Display/Display.h

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

4
src/web/RestApi.h

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

Loading…
Cancel
Save