From 4c1b7d48400fa4d8f5f17a691ecabeb96a919424 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 1 May 2021 11:27:37 +0800 Subject: [PATCH] pinelora WIP --- geeksville-private/TODO.md | 1 + platformio.ini | 8 ++++---- proto | 2 +- src/configuration.h | 2 +- src/error.h | 2 +- src/mesh/NodeDB.cpp | 6 ++++++ src/mesh/RadioLibInterface.cpp | 8 +++++++- src/mesh/SX1262Interface.cpp | 32 ++++++++++++++++++++++++++++---- src/mesh/generated/mesh.pb.h | 7 ++++--- 9 files changed, 53 insertions(+), 15 deletions(-) diff --git a/geeksville-private/TODO.md b/geeksville-private/TODO.md index 286551b5..7dbf5b0f 100644 --- a/geeksville-private/TODO.md +++ b/geeksville-private/TODO.md @@ -4,6 +4,7 @@ You probably don't care about this section - skip to the next one. ## before next release +* turn on setTx(timeout) and state = setDioIrqParams(SX126X_IRQ_TX_DONE | SX126X_IRQ_TIMEOUT, SX126X_IRQ_TX_DONE | SX126X_IRQ_TIMEOUT); in sx1262 code * pine64 lora module * nrf52 USB is unreliable while sleeping? * @havealoha fixedposition not working diff --git a/platformio.ini b/platformio.ini index 64d4bddf..881d341b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,9 +16,9 @@ ;default_envs = tlora_v1_3 ;default_envs = tlora-v2 ;default_envs = lora-relay-v1 # nrf board -default_envs = t-echo +;default_envs = t-echo ;default_envs = nrf52840dk-geeksville -;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = rak4631 ;default_envs = rak4630 @@ -72,7 +72,7 @@ lib_deps = 1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib https://github.com/meshtastic/arduino-fsm.git#829e967b8a95c094f73c60ef8dacfe66eae38940 https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git#31015a55e630a2df77d9d714669c621a5bf355ad - https://github.com/meshtastic/RadioLib.git#b022e575f8dce1fb879577ea07f177bc817f5f52 + https://github.com/meshtastic/RadioLib.git#80ed10d689a0568782c5bd152906b0f97d2bce93 https://github.com/meshtastic/TinyGPSPlus.git#f0f47067ef2f67c856475933188251c1ef615e79 https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460 Wire ; explicitly needed here because the AXP202 library forgets to add it @@ -88,7 +88,7 @@ framework = arduino lib_deps = ${env.lib_deps} -build_flags = ${env.build_flags} -Os +build_flags = ${env.build_flags} -Os -DRADIOLIB_GODMODE src_filter = ${env.src_filter} - diff --git a/proto b/proto index 157f9891..d4232f9a 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 157f9891dd35d3087f51e32dc0b103fcb1f0ca7c +Subproject commit d4232f9a8932c1d5ddd76af89c7737f4b287e145 diff --git a/src/configuration.h b/src/configuration.h index b3d76282..63ec177d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -449,7 +449,7 @@ along with this program. If not, see . #define SX1262_DIO1 LORA_DIO1 #define SX1262_BUSY LORA_DIO2 #define SX1262_RESET LORA_RESET -#define SX1262_E22 // Seems to be an E22 clone +// HOPE RFM90 does not have a TCXO therefore not SX1262_E22 #endif #endif diff --git a/src/error.h b/src/error.h index 2ccf1891..0893f02f 100644 --- a/src/error.h +++ b/src/error.h @@ -5,7 +5,7 @@ #include "mesh/generated/mesh.pb.h" // For CriticalErrorCode /// A macro that include filename and line -#define RECORD_CRITICALERROR(code) (code, __LINE__, __FILE__) +#define RECORD_CRITICALERROR(code) recordCriticalError(code, __LINE__, __FILE__) /// Record an error that should be reported via analytics void recordCriticalError(CriticalErrorCode code = CriticalErrorCode_Unspecified, uint32_t address = 0, const char *filename = NULL); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 07706cb4..f6833d86 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -555,4 +555,10 @@ void recordCriticalError(CriticalErrorCode code, uint32_t address, const char *f myNodeInfo.error_code = code; myNodeInfo.error_address = address; myNodeInfo.error_count++; + + // Currently portuino is mostly used for simulation. Make sue the user notices something really bad happend +#ifdef PORTDUINO + DEBUG_MSG("A critical failure occurred, portduino is exiting..."); + exit(2); +#endif } diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 43e347f1..e8c15fbe 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -312,7 +312,13 @@ void RadioLibInterface::startSend(MeshPacket *txp) size_t numbytes = beginSending(txp); int res = iface->startTransmit(radiobuf, numbytes); - assert(res == ERR_NONE); + if(res != ERR_NONE) { + RECORD_CRITICALERROR(CriticalErrorCode_RadioSpiBug); + + // This send failed, but make sure to 'complete' it properly + completeSending(); + startReceive(); // Restart receive mode (because startTransmit failed to put us in xmit mode) + } // Must be done AFTER, starting transmit, because startTransmit clears (possibly stale) interrupt pending register bits enableInterrupt(isrTxLevel0); diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 2a68bca3..0a0f92b5 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -59,6 +59,30 @@ bool SX1262Interface::init() res = lora.setDio2AsRfSwitch(false); #endif +#if 0 + // Read/write a register we are not using (only used for FSK mode) to test SPI comms + uint8_t crcLSB = 0; + int err = lora.readRegister(SX126X_REG_CRC_POLYNOMIAL_LSB, &crcLSB, 1); + if(err != ERR_NONE) + RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + + //if(crcLSB != 0x0f) + // RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + + crcLSB = 0x5a; + err = lora.writeRegister(SX126X_REG_CRC_POLYNOMIAL_LSB, &crcLSB, 1); + if(err != ERR_NONE) + RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + + err = lora.readRegister(SX126X_REG_CRC_POLYNOMIAL_LSB, &crcLSB, 1); + if(err != ERR_NONE) + RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + + if(crcLSB != 0x5a) + RECORD_CRITICALERROR(CriticalErrorCode_SX1262Failure); + // If we got this far register accesses (and therefore SPI comms) are good +#endif + if (res == ERR_NONE) res = lora.setCRC(SX126X_LORA_CRC_ON); @@ -78,15 +102,15 @@ bool SX1262Interface::reconfigure() // configure publicly accessible settings int err = lora.setSpreadingFactor(sf); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); err = lora.setBandwidth(bw); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); err = lora.setCodingRate(cr); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... err = lora.setRxGain(true); @@ -103,7 +127,7 @@ bool SX1262Interface::reconfigure() err = lora.setFrequency(freq); if (err != ERR_NONE) - recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); if (power > 22) // This chip has lower power limits than some power = 22; diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 1df6b463..fda4c5d9 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -47,7 +47,8 @@ typedef enum _CriticalErrorCode { CriticalErrorCode_InvalidRadioSetting = 7, CriticalErrorCode_TransmitFailed = 8, CriticalErrorCode_Brownout = 9, - CriticalErrorCode_SX1262Failure = 10 + CriticalErrorCode_SX1262Failure = 10, + CriticalErrorCode_RadioSpiBug = 11 } CriticalErrorCode; typedef enum _Routing_Error { @@ -217,8 +218,8 @@ typedef struct _ToRadio { #define _Constants_ARRAYSIZE ((Constants)(Constants_DATA_PAYLOAD_LEN+1)) #define _CriticalErrorCode_MIN CriticalErrorCode_None -#define _CriticalErrorCode_MAX CriticalErrorCode_SX1262Failure -#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_SX1262Failure+1)) +#define _CriticalErrorCode_MAX CriticalErrorCode_RadioSpiBug +#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_RadioSpiBug+1)) #define _Routing_Error_MIN Routing_Error_NONE #define _Routing_Error_MAX Routing_Error_NOT_AUTHORIZED