From 4db176867b05826f429a7d7a91dc9cbffb7f1a13 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 5 Jun 2020 11:00:58 -0700 Subject: [PATCH 1/6] WIP - bringup on PPR --- platformio.ini | 4 +--- src/main.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/platformio.ini b/platformio.ini index c51e0954e..c10e7f1ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam ; Note: the github actions CI test build can't yet build NRF52 targets +default_envs = ppr ; Note: the github actions CI test build can't yet build NRF52 targets [common] ; common is not currently used @@ -154,8 +154,6 @@ debug_init_break = [env:nrf52dk] extends = nrf52_base board = nrf52840_dk_modified -lib_deps = - UC1701 ; for temp testing ; The PPR board [env:ppr] diff --git a/src/main.cpp b/src/main.cpp index d7fb21bd1..728cd5bde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,7 +151,8 @@ void setup() #else Wire.begin(); #endif - scanI2Cdevice(); + // i2c still busted on new board + // scanI2Cdevice(); // Buttons & LED #ifdef BUTTON_PIN @@ -180,6 +181,9 @@ void setup() nrf52Setup(); #endif + extern void testLCD(); + // testLCD(); + // Initialize the screen first so we can show the logo while we start up everything else. if (ssd1306_found) screen.setup(); @@ -233,7 +237,7 @@ void setup() new SimRadio(); #endif - if (!rIf->init()) + if (!rIf || !rIf->init()) recordCriticalError(ErrNoRadio); else router.addInterface(rIf); From 71a4cfefd50ae6517e34a7c969fd2479918bf818 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 8 Jun 2020 15:01:55 -0700 Subject: [PATCH 2/6] bringup WIP --- docs/software/nrf52-TODO.md | 10 +++++++++- proto | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 137bcb04e..efa6b3fde 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -2,11 +2,19 @@ ## Misc work items +platform.json + + "framework-arduinoadafruitnrf52": { + "type": "framework", + "optional": true, + "version": "https://github.com/meshtastic/Adafruit_nRF52_Arduino.git" + }, + ## Initial work items Minimum items needed to make sure hardware is good. -- set power UICR per https://devzone.nordicsemi.com/f/nordic-q-a/28562/nrf52840-regulator-configuration +- DONE set power UICR per https://devzone.nordicsemi.com/f/nordic-q-a/28562/nrf52840-regulator-configuration - switch charge controller into / out of performance mode (see 8.3.1 in datasheet) - write UC1701 wrapper - Test hardfault handler for null ptrs (if one isn't already installed) diff --git a/proto b/proto index 9d083d5d4..3ba76bbe4 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 9d083d5d4ff4ef095135b18468004eaba77cb691 +Subproject commit 3ba76bbe4c98ee9c9e422d8dc10844cc9fb5272a From 362d5452d55b81dbd370b0c51633a65539e37385 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 13:31:53 -0700 Subject: [PATCH 3/6] remove unused chip --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index c6a34795f..e7e864b86 100644 --- a/platformio.ini +++ b/platformio.ini @@ -164,7 +164,7 @@ board = ppr lib_deps = ${env.lib_deps} UC1701 - https://github.com/meshtastic/BQ25703A.git + From 82169d4115dad3a53fc2f8d9bb027968628327e0 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 13:32:06 -0700 Subject: [PATCH 4/6] make recent changes work on non ESP hardware --- src/sleep.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sleep.cpp b/src/sleep.cpp index 2dfee04fb..2d3ad4d31 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -129,7 +129,7 @@ static void waitEnterSleep() if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep recordCriticalError(ErrSleepEnterWait); - ESP.restart(); // FIXME - for now we just restart, need to fix bug #167 + assert(0); // FIXME - for now we just restart, need to fix bug #167 break; } } @@ -289,8 +289,6 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r return cause; } -#endif - // not legal on the stock android ESP build @@ -310,4 +308,4 @@ void enableModemSleep() config.light_sleep_enable = false; DEBUG_MSG("Sleep request result %x\n", esp_pm_configure(&config)); } - +#endif From 477c62082db33181f37142bb10002f6ea3520f0b Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 14:38:09 -0700 Subject: [PATCH 5/6] E22 SX1262 module now works! Thanks mostly to an old github comment by @beegee-tokyo the fix was easy (comment here https://github.com/jgromes/RadioLib/issues/12#issuecomment-520450429) We now set DIO3 to 2.4 volts to power the oscillator inside the E22 module (undocumented in the E22 docs) --- src/mesh/RadioLibInterface.h | 10 ++++---- src/mesh/SX1262Interface.cpp | 44 +++++++++++++++++++++++++++++++++++- src/mesh/SX1262Interface.h | 6 +++++ variants/ppr/variant.h | 1 + 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index 6619337ba..5f70d027d 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -91,9 +91,6 @@ class RadioLibInterface : public RadioInterface, private PeriodicTask virtual void startReceive() = 0; private: - /** start an immediate transmit */ - void startSend(MeshPacket *txp); - /** if we have something waiting to send, start a short random timer so we can come check for collision before actually doing * the transmit * @@ -113,7 +110,12 @@ class RadioLibInterface : public RadioInterface, private PeriodicTask /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. virtual bool init(); - + + /** start an immediate transmit + * This method is virtual so subclasses can hook as needed, subclasses should not call directly + */ + virtual void startSend(MeshPacket *txp); + /** * Convert our modemConfig enum into wf, sf, etc... * diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index 69e7f8ee7..628ec995f 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -14,7 +14,19 @@ bool SX1262Interface::init() { RadioLibInterface::init(); - float tcxoVoltage = 0; // None - we use an XTAL +#ifdef SX1262_RXEN // set not rx or tx mode + pinMode(SX1262_RXEN, OUTPUT); + pinMode(SX1262_TXEN, OUTPUT); + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, LOW); +#endif + +#ifndef SX1262_E22 + float tcxoVoltage = 0; // None - we use an XTAL +#else + float tcxoVoltage = + 2.4; // E22 uses DIO3 to power tcxo per https://github.com/jgromes/RadioLib/issues/12#issuecomment-520695575 +#endif bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? applyModemConfig(); @@ -23,6 +35,12 @@ bool SX1262Interface::init() int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); DEBUG_MSG("LORA init result %d\n", res); +#ifdef SX1262_RXEN + // lora.begin assumes Dio2 is RF switch control, which is not true if we are manually controlling RX and TX + if (res == ERR_NONE) + res = lora.setDio2AsRfSwitch(false); +#endif + if (res == ERR_NONE) res = lora.setCRC(SX126X_LORA_CRC_ON); @@ -81,6 +99,11 @@ void SX1262Interface::setStandby() int err = lora.standby(); assert(err == ERR_NONE); +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn off RX and TX power + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, LOW); +#endif + isReceiving = false; // If we were receiving, not any more disableInterrupt(); completeSending(); // If we were sending, not anymore @@ -94,6 +117,19 @@ void SX1262Interface::addReceiveMetadata(MeshPacket *mp) mp->rx_snr = lora.getSNR(); } +/** start an immediate transmit + * We override to turn on transmitter power as needed. + */ +void SX1262Interface::startSend(MeshPacket *txp) +{ +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn on TX power / off RX power + digitalWrite(SX1262_RXEN, LOW); + digitalWrite(SX1262_TXEN, HIGH); +#endif + + RadioLibInterface::startSend(txp); +} + // For power draw measurements, helpful to force radio to stay sleeping // #define SLEEP_ONLY @@ -102,6 +138,12 @@ void SX1262Interface::startReceive() #ifdef SLEEP_ONLY sleep(); #else + +#ifdef SX1262_RXEN // we have RXEN/TXEN control - turn on RX power / off TX power + digitalWrite(SX1262_RXEN, HIGH); + digitalWrite(SX1262_TXEN, LOW); +#endif + setStandby(); // int err = lora.startReceive(); int err = lora.startReceiveDutyCycleAuto(); // We use a 32 bit preamble so this should save some power by letting radio sit in diff --git a/src/mesh/SX1262Interface.h b/src/mesh/SX1262Interface.h index 92b301bfc..1eee86a66 100644 --- a/src/mesh/SX1262Interface.h +++ b/src/mesh/SX1262Interface.h @@ -43,6 +43,12 @@ class SX1262Interface : public RadioLibInterface * Start waiting to receive a message */ virtual void startReceive(); + + /** start an immediate transmit + * We override to turn on transmitter power as needed. + */ + virtual void startSend(MeshPacket *txp); + /** * Add SNR data to received messages */ diff --git a/variants/ppr/variant.h b/variants/ppr/variant.h index 95b2803bd..bbdda3065 100644 --- a/variants/ppr/variant.h +++ b/variants/ppr/variant.h @@ -137,6 +137,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // #define SX1262_ANT_SW (32 + 10) #define SX1262_RXEN (22) #define SX1262_TXEN (24) +#define SX1262_E22 // Indicates this SX1262 is inside of an ebyte E22 module and special config should be done for that // ERC12864-10 LCD #define ERC12864_CS (32 + 4) From 9ad14ad98b01a2c398c54aed9a14d547c3d70e5b Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 14:43:16 -0700 Subject: [PATCH 6/6] Cleanup to merge NR52 support back into mainline --- docs/software/TODO.md | 16 +++++++--------- platformio.ini | 2 +- src/main.cpp | 7 +++---- src/nrf52/main-nrf52.cpp | 6 ------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index e01d525b4..07bfad429 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -1,19 +1,17 @@ # High priority -- why is the net so chatty now? - modem sleep should work if we lower serial rate to 115kb? - device wakes, turns BLE on and phone doesn't notice (while phone was sitting in auto-connect) -- E22 bringup - encryption review findings writeup - turn on modem-sleep mode - https://github.com/espressif/arduino-esp32/issues/1142#issuecomment-512428852 -last EDF release in arduino is: https://github.com/espressif/arduino-esp32/commit/1977370e6fc069e93ffd8818798fbfda27ae7d99 -IDF release/v3.3 46b12a560 -IDF release/v3.3 367c3c09c -https://docs.espressif.com/projects/esp-idf/en/release-v3.3/get-started/linux-setup.html -kevinh@kevin-server:~/development/meshtastic/esp32-arduino-lib-builder$ python /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/build/bootloader/bootloader.bin -cp -a out/tools/sdk/* components/arduino/tools/sdk -cp -ar components/arduino/* ~/.platformio/packages/framework-arduinoespressif32@src-fba9d33740f719f712e9f8b07da6ea13/ + last EDF release in arduino is: https://github.com/espressif/arduino-esp32/commit/1977370e6fc069e93ffd8818798fbfda27ae7d99 + IDF release/v3.3 46b12a560 + IDF release/v3.3 367c3c09c + https://docs.espressif.com/projects/esp-idf/en/release-v3.3/get-started/linux-setup.html + kevinh@kevin-server:~/development/meshtastic/esp32-arduino-lib-builder\$ python /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 /home/kevinh/development/meshtastic/esp32-arduino-lib-builder/build/bootloader/bootloader.bin + cp -a out/tools/sdk/_ components/arduino/tools/sdk + cp -ar components/arduino/_ ~/.platformio/packages/framework-arduinoespressif32@src-fba9d33740f719f712e9f8b07da6ea13/ # Medium priority diff --git a/platformio.ini b/platformio.ini index e7e864b86..f0f63bc31 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = ppr ; Note: the github actions CI test build can't yet build NRF52 targets +default_envs = tbeam ; Note: the github actions CI test build can't yet build NRF52 targets [common] ; common is not currently used diff --git a/src/main.cpp b/src/main.cpp index cfca10a0b..e6820e841 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,7 +153,9 @@ void setup() Wire.begin(); #endif // i2c still busted on new board - // scanI2Cdevice(); +#ifndef ARDUINO_NRF52840_PPR + scanI2Cdevice(); +#endif // Buttons & LED #ifdef BUTTON_PIN @@ -182,9 +184,6 @@ void setup() nrf52Setup(); #endif - extern void testLCD(); - // testLCD(); - // Initialize the screen first so we can show the logo while we start up everything else. if (ssd1306_found) screen.setup(); diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index ce3fe7e31..93798462a 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -59,12 +59,6 @@ void setBluetoothEnable(bool on) } } -#ifdef ARDUINO_NRF52840_PPR -#include "PmuBQ25703A.h" - -PmuBQ25703A pmu; -#endif - void nrf52Setup() {