From ed589727d62eba3cbcadcb3f7619369fde74e57b Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 9 Jul 2020 19:57:55 -0700 Subject: [PATCH] Update NRF52 build to work again --- boards/nrf52840_dk_modified.json | 2 +- docs/software/ant.md | 14 ++++++++++++++ docs/software/nrf52-TODO.md | 5 +++++ docs/software/rak815.md | 6 ++++++ platformio.ini | 4 ++-- src/BluetoothCommon.h | 8 ++++++++ src/concurrency/Thread.cpp | 31 ++++++++++++++++++++++++++++++- src/concurrency/Thread.h | 15 +++------------ src/configuration.h | 4 ++++ src/esp32/BluetoothUtil.h | 3 --- src/main.cpp | 2 +- src/mesh/MeshService.cpp | 6 ++---- src/nrf52/NRF52Bluetooth.cpp | 6 ++++++ 13 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 docs/software/ant.md create mode 100644 docs/software/rak815.md create mode 100644 src/BluetoothCommon.h diff --git a/boards/nrf52840_dk_modified.json b/boards/nrf52840_dk_modified.json index ce86e09f5..a11ea02c5 100644 --- a/boards/nrf52840_dk_modified.json +++ b/boards/nrf52840_dk_modified.json @@ -8,7 +8,7 @@ "extra_flags": "-DARDUINO_NRF52840_PCA10056 -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [["0x239A", "0x4404"]], - "usb_product": "SimPPR", + "usb_product": "nrf52840dk", "mcu": "nrf52840", "variant": "pca10056-rc-clock", "variants_dir": "variants", diff --git a/docs/software/ant.md b/docs/software/ant.md new file mode 100644 index 000000000..30ea4367a --- /dev/null +++ b/docs/software/ant.md @@ -0,0 +1,14 @@ +# ANT protocol notes + +SD340 terms are reasonable for NRF52 +https://www.thisisant.com/developer/components/nrf52832#tab_protocol_stacks_tab + +Profiles to implement: + +tracker +https://www.thisisant.com/developer/ant-plus/device-profiles/#4365_tab + +ebike +https://www.thisisant.com/developer/ant-plus/device-profiles/#527_tab + +no profile for messaging? diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index d6d91868f..d56bfc262 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -5,8 +5,11 @@ RAM investigation. nRF52832-QFAA 64KB ram, 512KB flash vs nrf52832-QFAB 32KB ram, 512kb flash +nrf52833 128KB RAM nrf52840 256KB RAM, 1MB flash +Manual hacks needed to build (for now): + platform.json "framework-arduinoadafruitnrf52": { @@ -15,6 +18,8 @@ platform.json "version": "https://github.com/meshtastic/Adafruit_nRF52_Arduino.git" }, +kevinh@kevin-server:~/.platformio/packages/framework-arduinoadafruitnrf52/variants$ ln -s ~/development/meshtastic/meshtastic-esp32/variants/* . + ## Initial work items Minimum items needed to make sure hardware is good. diff --git a/docs/software/rak815.md b/docs/software/rak815.md new file mode 100644 index 000000000..719c50f54 --- /dev/null +++ b/docs/software/rak815.md @@ -0,0 +1,6 @@ +# RAK815 + +Notes on trying to get the RAK815 working with meshtastic. + +good tutorial: https://www.hackster.io/naresh-krish/getting-started-with-rak815-tracker-module-and-arduino-1c7bc9 +(includes software serial link - possibly useful for GPS) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 9f73a1aa1..8da3f77dc 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 = nrf52dk ; Note: the github actions CI test build can't yet build NRF52 targets [common] ; common is not currently used @@ -74,7 +74,7 @@ lib_deps = Wire ; explicitly needed here because the AXP202 library forgets to add it https://github.com/meshtastic/arduino-fsm.git https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git - https://github.com/meshtastic/RadioLib.git#6aa38a85856012c99c4e9b4e7cee35e37671a4bc + https://github.com/meshtastic/RadioLib.git#d6b12f7eb0a06bd2414c79b437b25d377e3f603f https://github.com/meshtastic/TinyGPSPlus.git ; Common settings for ESP targes, mixin with extends = esp32_base diff --git a/src/BluetoothCommon.h b/src/BluetoothCommon.h new file mode 100644 index 000000000..5d551d079 --- /dev/null +++ b/src/BluetoothCommon.h @@ -0,0 +1,8 @@ +#pragma once + +/** + * Common lib functions for all platforms that have bluetooth + */ + +/// Given a level between 0-100, update the BLE attribute +void updateBatteryLevel(uint8_t level); \ No newline at end of file diff --git a/src/concurrency/Thread.cpp b/src/concurrency/Thread.cpp index 99dd16300..1e1c7bb63 100644 --- a/src/concurrency/Thread.cpp +++ b/src/concurrency/Thread.cpp @@ -1,7 +1,13 @@ #include "Thread.h" #include "timing.h" +#include -namespace concurrency { +#ifdef ARDUINO_ARCH_ESP32 +#include "esp_task_wdt.h" +#endif + +namespace concurrency +{ void Thread::start(const char *name, size_t stackSize, uint32_t priority) { @@ -14,4 +20,27 @@ void Thread::callRun(void *_this) ((Thread *)_this)->doRun(); } +void Thread::serviceWatchdog() +{ +#ifdef ARDUINO_ARCH_ESP32 + esp_task_wdt_reset(); +#endif +} + +void Thread::startWatchdog() +{ +#ifdef ARDUINO_ARCH_ESP32 + auto r = esp_task_wdt_add(taskHandle); + assert(r == ESP_OK); +#endif +} + +void Thread::stopWatchdog() +{ +#ifdef ARDUINO_ARCH_ESP32 + auto r = esp_task_wdt_delete(taskHandle); + assert(r == ESP_OK); +#endif +} + } // namespace concurrency diff --git a/src/concurrency/Thread.h b/src/concurrency/Thread.h index bc8fe3951..ce72111e9 100644 --- a/src/concurrency/Thread.h +++ b/src/concurrency/Thread.h @@ -1,7 +1,6 @@ #pragma once #include "freertosinc.h" -#include "esp_task_wdt.h" namespace concurrency { @@ -36,17 +35,9 @@ class Thread * * this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog() */ - void serviceWatchdog() { esp_task_wdt_reset(); } - void startWatchdog() - { - auto r = esp_task_wdt_add(taskHandle); - assert(r == ESP_OK); - } - void stopWatchdog() - { - auto r = esp_task_wdt_delete(taskHandle); - assert(r == ESP_OK); - } + void serviceWatchdog(); + void startWatchdog(); + void stopWatchdog(); private: static void callRun(void *_this); diff --git a/src/configuration.h b/src/configuration.h index d0ec7aad3..c36d4a18f 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -62,6 +62,10 @@ along with this program. If not, see . // Standard definitions for NRF52 targets // +// Nop definition for these attributes - not used on NRF52 +#define EXT_RAM_ATTR +#define IRAM_ATTR + #define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth) // We bind to the GPS using variant.h instead for this platform (Serial1) diff --git a/src/esp32/BluetoothUtil.h b/src/esp32/BluetoothUtil.h index 67797a0ce..b1aa77db1 100644 --- a/src/esp32/BluetoothUtil.h +++ b/src/esp32/BluetoothUtil.h @@ -35,8 +35,5 @@ BLECharacteristic *addBLECharacteristic(BLECharacteristic *c); /// Add a characteristic that we will delete when we restart BLEDescriptor *addBLEDescriptor(BLEDescriptor *c); -/// Given a level between 0-100, update the BLE attribute -void updateBatteryLevel(uint8_t level); - /// Any bluetooth objects you allocate _must_ come from this pool if you want to be able to call deinitBLE() extern SimpleAllocator btPool; diff --git a/src/main.cpp b/src/main.cpp index c5823f1b6..e0d1eb021 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ #include "power.h" // #include "rom/rtc.h" #include "DSRRouter.h" -#include "debug.h" +// #include "debug.h" #include "graphics/Screen.h" #include "main.h" #include "sleep.h" diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 645cefc38..38babd904 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -5,14 +5,14 @@ #include "GPS.h" //#include "MeshBluetoothService.h" +#include "../concurrency/Periodic.h" +#include "BluetoothCommon.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here #include "MeshService.h" #include "NodeDB.h" -#include "../concurrency/Periodic.h" #include "PowerFSM.h" #include "main.h" #include "mesh-pb-constants.h" #include "power.h" -#include "BluetoothUtil.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here #include "timing.h" /* @@ -283,8 +283,6 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies) sendToMesh(p); } - - int MeshService::onGPSChanged(void *unused) { // DEBUG_MSG("got gps notify\n"); diff --git a/src/nrf52/NRF52Bluetooth.cpp b/src/nrf52/NRF52Bluetooth.cpp index 22ee69dc2..03e5b8909 100644 --- a/src/nrf52/NRF52Bluetooth.cpp +++ b/src/nrf52/NRF52Bluetooth.cpp @@ -1,6 +1,7 @@ #include "NRF52Bluetooth.h" #include "configuration.h" #include "main.h" +#include "BluetoothCommon.h" #include /* HRM Service Definitions @@ -192,6 +193,11 @@ void NRF52Bluetooth::setup() } } +/// Given a level between 0-100, update the BLE attribute +void updateBatteryLevel(uint8_t level) { + // FIXME - implement +} + /* void loop() {