From 328b24537f17486a39d3bbc44e124ae02df2b74e Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 11 Apr 2021 13:33:27 +0800 Subject: [PATCH 1/7] rak4631: builds but WIP --- boards/wiscore_rak4631.json | 72 ++++++++++ docs/software/rak-wizblock.md | 19 +++ platformio.ini | 13 +- variants/WisCore_RAK4631_Board/variant.cpp | 46 +++++++ variants/WisCore_RAK4631_Board/variant.h | 148 +++++++++++++++++++++ 5 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 boards/wiscore_rak4631.json create mode 100644 variants/WisCore_RAK4631_Board/variant.cpp create mode 100644 variants/WisCore_RAK4631_Board/variant.h diff --git a/boards/wiscore_rak4631.json b/boards/wiscore_rak4631.json new file mode 100644 index 000000000..40c93ff04 --- /dev/null +++ b/boards/wiscore_rak4631.json @@ -0,0 +1,72 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + [ + "0x239A", + "0x8029" + ], + [ + "0x239A", + "0x0029" + ], + [ + "0x239A", + "0x002A" + ], + [ + "0x239A", + "0x802A" + ] + ], + "usb_product": "WisCore RAK4631 Board", + "mcu": "nrf52840", + "variant": "WisCore_RAK4631_Board", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": [ + "bluetooth" + ], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd" + }, + "frameworks": [ + "arduino" + ], + "name": "WisCore RAK4631 Board", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.rakwireless.com", + "vendor": "RAKwireless" +} \ No newline at end of file diff --git a/docs/software/rak-wizblock.md b/docs/software/rak-wizblock.md index b0c79702c..d7a607f8c 100644 --- a/docs/software/rak-wizblock.md +++ b/docs/software/rak-wizblock.md @@ -1,5 +1,7 @@ # RAK Wireless RisBlock +## Docs + https://docs.rakwireless.com/Product-Categories/WisBlock/Quickstart/#wisblock-base-2 GPS module: @@ -17,3 +19,20 @@ Must be installed on the front for the I2C wires to lineup Solar enclosure https://docs.rakwireless.com/Product-Categories/Accessories/RAKBox-B2/Overview/#product-description +## TODO + +* DONE solder header +* DONE attach antenna +* get building (LORA disabled) +* FIX LEDs +* FIX BUTTONs +* FIX I2C assignment +* FIX LORA SPI +* FIX GPS GPIO assignment +* Disable Bluetooth +* Disable LORA +* Boot +* Enable LORA but no TX +* Enable LORA TX +* send in PR to https://github.com/geeksville/WisBlock for boards define +* \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 54777ef17..40fb2ced1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +;default_envs = tbeam ;default_envs = tbeam0.7 ;default_envs = heltec ;default_envs = tlora-v1 @@ -19,6 +19,7 @@ default_envs = tbeam ;default_envs = eink ;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 = rak4631 [common] ; common is not currently used @@ -289,6 +290,16 @@ monitor_speed = 115200 # For experimenting with RAM sizes # board_build.ldscript = linker/nrf52840_s140_sim832.ld +[env:rak4631] +extends = nrf52_base +board = wiscore_rak4631 +# add our variants files to the include and src paths +# define build flags for the TFT_eSPI library +build_flags = ${nrf52_base.build_flags} -Ivariants/WisCore_RAK4631_Board +src_filter = ${nrf52_base.src_filter} +<../variants/eink> +lib_deps = + ${arduino_base.lib_deps} + ; The PPR board [env:ppr] extends = nrf52_base diff --git a/variants/WisCore_RAK4631_Board/variant.cpp b/variants/WisCore_RAK4631_Board/variant.cpp new file mode 100644 index 000000000..b96f6f1cd --- /dev/null +++ b/variants/WisCore_RAK4631_Board/variant.cpp @@ -0,0 +1,46 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include "nrf.h" + +const uint32_t g_ADigitalPinMap[] = + { + // P0 + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); +} diff --git a/variants/WisCore_RAK4631_Board/variant.h b/variants/WisCore_RAK4631_Board/variant.h new file mode 100644 index 000000000..5f133f868 --- /dev/null +++ b/variants/WisCore_RAK4631_Board/variant.h @@ -0,0 +1,148 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_RAK4630_ +#define _VARIANT_RAK4630_ + +#define RAK4630 + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (35) +#define PIN_LED2 (36) + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_GREEN PIN_LED1 +#define LED_BLUE PIN_LED2 + +#define LED_STATE_ON 1 // State when LED is litted + +/* + * Buttons + */ +#define PIN_BUTTON1 11 +#define PIN_BUTTON2 12 +#define PIN_BUTTON3 24 +#define PIN_BUTTON4 25 + +/* + * Analog pins + */ +#define PIN_A0 (5) +#define PIN_A1 (31) +#define PIN_A2 (28) +#define PIN_A3 (29) +#define PIN_A4 (30) +#define PIN_A5 (31) +#define PIN_A6 (0xff) +#define PIN_A7 (0xff) + + static const uint8_t A0 = PIN_A0; + static const uint8_t A1 = PIN_A1; + static const uint8_t A2 = PIN_A2; + static const uint8_t A3 = PIN_A3; + static const uint8_t A4 = PIN_A4; + static const uint8_t A5 = PIN_A5; + static const uint8_t A6 = PIN_A6; + static const uint8_t A7 = PIN_A7; +#define ADC_RESOLUTION 14 + +// Other pins +#define PIN_AREF (2) +#define PIN_NFC1 (9) +#define PIN_NFC2 (10) + + static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX (15) +#define PIN_SERIAL1_TX (16) + +// Connected to Jlink CDC +#define PIN_SERIAL2_RX (8) +#define PIN_SERIAL2_TX (6) + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (45) +#define PIN_SPI_MOSI (44) +#define PIN_SPI_SCK (43) + + static const uint8_t SS = 42; + static const uint8_t MOSI = PIN_SPI_MOSI; + static const uint8_t MISO = PIN_SPI_MISO; + static const uint8_t SCK = PIN_SPI_SCK; + +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (13) +#define PIN_WIRE_SCL (14) + +// QSPI Pins +#define PIN_QSPI_SCK 3 +#define PIN_QSPI_CS 26 +#define PIN_QSPI_IO0 30 +#define PIN_QSPI_IO1 29 +#define PIN_QSPI_IO2 28 +#define PIN_QSPI_IO3 2 + +// On-board QSPI Flash +#define EXTERNAL_FLASH_DEVICES IS25LP080D +#define EXTERNAL_FLASH_USE_QSPI + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif From f9a58b9dd1c4607cb90aa37fed9b694017ac90a9 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 11 Apr 2021 13:52:39 +0800 Subject: [PATCH 2/7] lower brownout threshold to 1.7V --- src/nrf52/main-nrf52.cpp | 257 +++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 129 deletions(-) diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index e5a4aadf7..2c5bcac8b 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -13,174 +13,173 @@ #include "BQ25713.h" #endif - -static inline void debugger_break(void) { - __asm volatile( - "bkpt #0x01\n\t" - "mov pc, lr\n\t"); +static inline void debugger_break(void) +{ + __asm volatile("bkpt #0x01\n\t" + "mov pc, lr\n\t"); } // handle standard gcc assert failures -void __attribute__((noreturn)) -__assert_func(const char *file, int line, const char *func, - const char *failedexpr) { - DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, - failedexpr); - // debugger_break(); FIXME doesn't work, possibly not for segger - while (1) - ; // FIXME, reboot! +void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr) +{ + DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr); + // debugger_break(); FIXME doesn't work, possibly not for segger + while (1) + ; // FIXME, reboot! } -void getMacAddr(uint8_t *dmac) { - ble_gap_addr_t addr; - if (sd_ble_gap_addr_get(&addr) == NRF_SUCCESS) { - memcpy(dmac, addr.addr, 6); - } else { - const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR; - dmac[5] = src[0]; - dmac[4] = src[1]; - dmac[3] = src[2]; - dmac[2] = src[3]; - dmac[1] = src[4]; - dmac[0] = src[5] | - 0xc0; // MSB high two bits get set elsewhere in the bluetooth stack - } +void getMacAddr(uint8_t *dmac) +{ + ble_gap_addr_t addr; + if (sd_ble_gap_addr_get(&addr) == NRF_SUCCESS) { + memcpy(dmac, addr.addr, 6); + } else { + const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR; + dmac[5] = src[0]; + dmac[4] = src[1]; + dmac[3] = src[2]; + dmac[2] = src[3]; + dmac[1] = src[4]; + dmac[0] = src[5] | 0xc0; // MSB high two bits get set elsewhere in the bluetooth stack + } } NRF52Bluetooth *nrf52Bluetooth; static bool bleOn = false; -static const bool useSoftDevice = true; // Set to false for easier debugging +static const bool useSoftDevice = false; // Set to false for easier debugging -void setBluetoothEnable(bool on) { - if (on != bleOn) { - if (on) { - if (!nrf52Bluetooth) { - if (!useSoftDevice) - DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n"); - else { - nrf52Bluetooth = new NRF52Bluetooth(); - nrf52Bluetooth->setup(); +void setBluetoothEnable(bool on) +{ + if (on != bleOn) { + if (on) { + if (!nrf52Bluetooth) { + if (!useSoftDevice) + DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n"); + else { + nrf52Bluetooth = new NRF52Bluetooth(); + nrf52Bluetooth->setup(); + } + } + } else { + if (nrf52Bluetooth) + nrf52Bluetooth->shutdown(); } - } - } else { - if (nrf52Bluetooth) nrf52Bluetooth->shutdown(); + bleOn = on; } - bleOn = on; - } } /** * Override printf to use the SEGGER output library */ -int printf(const char *fmt, ...) { - va_list args; - va_start(args, fmt); - auto res = SEGGER_RTT_vprintf(0, fmt, &args); - va_end(args); - return res; +int printf(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + auto res = SEGGER_RTT_vprintf(0, fmt, &args); + va_end(args); + return res; } -void initBrownout() { - auto vccthresh = POWER_POFCON_THRESHOLD_V28; +void initBrownout() +{ + auto vccthresh = POWER_POFCON_THRESHOLD_V17; - if (useSoftDevice) { - auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled); - assert(err_code == NRF_SUCCESS); + if (useSoftDevice) { + auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled); + assert(err_code == NRF_SUCCESS); - err_code = sd_power_pof_threshold_set(vccthresh); - assert(err_code == NRF_SUCCESS); - } else { - uint32_t pof_flags = POWER_POFCON_POF_Enabled | (vccthresh << POWER_POFCON_THRESHOLD_Pos); - - #ifdef POWER_POFCON_THRESHOLDVDDH_Msk - auto vcchthresh = POWER_POFCON_THRESHOLDVDDH_V27; - pof_flags |= (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos); - #endif - - NRF_POWER->POFCON = pof_flags; - } -} - -void checkSDEvents() { - if (useSoftDevice) { - uint32_t evt; - while (NRF_SUCCESS == sd_evt_get(&evt)) { - switch (evt) { - case NRF_EVT_POWER_FAILURE_WARNING: - recordCriticalError(CriticalErrorCode_Brownout); - break; - - default: - DEBUG_MSG("Unexpected SDevt %d\n", evt); - break; - } + err_code = sd_power_pof_threshold_set(vccthresh); + assert(err_code == NRF_SUCCESS); } - } else { - if (NRF_POWER->EVENTS_POFWARN) - recordCriticalError(CriticalErrorCode_Brownout); - } + // We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice } -void nrf52Loop() { checkSDEvents(); } +void checkSDEvents() +{ + if (useSoftDevice) { + uint32_t evt; + while (NRF_SUCCESS == sd_evt_get(&evt)) { + switch (evt) { + case NRF_EVT_POWER_FAILURE_WARNING: + recordCriticalError(CriticalErrorCode_Brownout); + break; -void nrf52Setup() { - auto why = NRF_POWER->RESETREAS; - // per - // https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html - DEBUG_MSG("Reset reason: 0x%x\n", why); + default: + DEBUG_MSG("Unexpected SDevt %d\n", evt); + break; + } + } + } else { + if (NRF_POWER->EVENTS_POFWARN) + recordCriticalError(CriticalErrorCode_Brownout); + } +} - // Per - // https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse - // This is the recommended setting for Monitor Mode Debugging - NVIC_SetPriority(DebugMonitor_IRQn, 6UL); +void nrf52Loop() +{ + checkSDEvents(); +} + +void nrf52Setup() +{ + auto why = NRF_POWER->RESETREAS; + // per + // https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html + DEBUG_MSG("Reset reason: 0x%x\n", why); + + // Per + // https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse + // This is the recommended setting for Monitor Mode Debugging + NVIC_SetPriority(DebugMonitor_IRQn, 6UL); #ifdef BQ25703A_ADDR - auto *bq = new BQ25713(); - if (!bq->setup()) DEBUG_MSG("ERROR! Charge controller init failed\n"); + auto *bq = new BQ25713(); + if (!bq->setup()) + DEBUG_MSG("ERROR! Charge controller init failed\n"); #endif - // Init random seed - // FIXME - use this to get random numbers - // #include "nrf_rng.h" - // uint32_t r; - // ble_controller_rand_vector_get_blocking(&r, sizeof(r)); - // randomSeed(r); - DEBUG_MSG("FIXME, call randomSeed\n"); - // ::printf("TESTING PRINTF\n"); + // Init random seed + // FIXME - use this to get random numbers + // #include "nrf_rng.h" + // uint32_t r; + // ble_controller_rand_vector_get_blocking(&r, sizeof(r)); + // randomSeed(r); + DEBUG_MSG("FIXME, call randomSeed\n"); + // ::printf("TESTING PRINTF\n"); - initBrownout(); + initBrownout(); } -void cpuDeepSleep(uint64_t msecToWake) { - // FIXME, configure RTC or button press to wake us - // FIXME, power down SPI, I2C, RAMs +void cpuDeepSleep(uint64_t msecToWake) +{ + // FIXME, configure RTC or button press to wake us + // FIXME, power down SPI, I2C, RAMs #ifndef NO_WIRE - Wire.end(); + Wire.end(); #endif - SPI.end(); - // This may cause crashes as debug messages continue to flow. - Serial.end(); + SPI.end(); + // This may cause crashes as debug messages continue to flow. + Serial.end(); #ifdef PIN_SERIAL_RX1 - Serial1.end(); + Serial1.end(); #endif - setBluetoothEnable(false); - // FIXME, use system off mode with ram retention for key state? - // FIXME, use non-init RAM per - // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled + setBluetoothEnable(false); + // FIXME, use system off mode with ram retention for key state? + // FIXME, use non-init RAM per + // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled - auto ok = sd_power_system_off(); - if (ok != NRF_SUCCESS) { - DEBUG_MSG( - "FIXME: Ignoring soft device (EasyDMA pending?) and forcing " - "system-off!\n"); - NRF_POWER->SYSTEMOFF = 1; - } + auto ok = sd_power_system_off(); + if (ok != NRF_SUCCESS) { + DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing " + "system-off!\n"); + NRF_POWER->SYSTEMOFF = 1; + } - // The following code should not be run, because we are off - while (1) { - delay(5000); - DEBUG_MSG("."); - } + // The following code should not be run, because we are off + while (1) { + delay(5000); + DEBUG_MSG("."); + } } \ No newline at end of file From bfdc05154b568510675211a2416f952b893c0289 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 11 Apr 2021 13:53:18 +0800 Subject: [PATCH 3/7] fix redundant segger init --- src/main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c2dd0b21a..e55afc7b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -313,10 +313,6 @@ void setup() SEGGER_RTT_ConfigUpBuffer(SEGGER_STDOUT_CH, NULL, NULL, buflen, mode); #endif -#ifdef USE_SEGGER - SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_TRIM); -#endif - #ifdef DEBUG_PORT if (!radioConfig.preferences.serial_disabled) { consoleInit(); // Set serial baud rate and init our mesh console From f7d199a3be006c1493d53da8499e4211fac864ea Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 11 Apr 2021 13:58:48 +0800 Subject: [PATCH 4/7] rak4631: kinda runs --- .github/workflows/main.yml | 4 +-- bin/upload-to-bootloader.sh | 5 ++-- docs/software/rak-wizblock.md | 6 ++--- variants/WisCore_RAK4631_Board/variant.h | 33 +++++++++++++----------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d71407be2..2ac3451c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,8 +26,8 @@ jobs: run: platformio run -e tbeam - name: Build for heltec run: platformio run -e heltec - - name: Build for lora-relay-v1 - run: platformio run -e lora-relay-v1 + - name: Build for wisblock RAK4631 + run: platformio run -e rak4631 - name: Build for native run: platformio run -e native - name: Integration test diff --git a/bin/upload-to-bootloader.sh b/bin/upload-to-bootloader.sh index ba4b7b48c..95ade3e37 100755 --- a/bin/upload-to-bootloader.sh +++ b/bin/upload-to-bootloader.sh @@ -1,4 +1,5 @@ +set -e echo "Converting to uf2 for NRF52 Adafruit bootloader" -bin/uf2conv.py .pio/build/lora-relay-v2/firmware.hex -f 0xADA52840 -# cp flash.uf2 /media/kevinh/FTH*BOOT/ +bin/uf2conv.py .pio/build/rak4631/firmware.hex -f 0xADA52840 +cp flash.uf2 /media/kevinh/FTH*BOOT/ diff --git a/docs/software/rak-wizblock.md b/docs/software/rak-wizblock.md index d7a607f8c..d400b58fb 100644 --- a/docs/software/rak-wizblock.md +++ b/docs/software/rak-wizblock.md @@ -24,9 +24,9 @@ https://docs.rakwireless.com/Product-Categories/Accessories/RAKBox-B2/Overview/# * DONE solder header * DONE attach antenna * get building (LORA disabled) -* FIX LEDs -* FIX BUTTONs -* FIX I2C assignment +* DONE FIX LEDs +* DONE FIX BUTTONs +* DONE FIX I2C assignment * FIX LORA SPI * FIX GPS GPIO assignment * Disable Bluetooth diff --git a/variants/WisCore_RAK4631_Board/variant.h b/variants/WisCore_RAK4631_Board/variant.h index 5f133f868..b8e52e995 100644 --- a/variants/WisCore_RAK4631_Board/variant.h +++ b/variants/WisCore_RAK4631_Board/variant.h @@ -34,8 +34,7 @@ #include "WVariant.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif // __cplusplus // Number of pins defined in PinDescription array @@ -76,14 +75,14 @@ extern "C" #define PIN_A6 (0xff) #define PIN_A7 (0xff) - static const uint8_t A0 = PIN_A0; - static const uint8_t A1 = PIN_A1; - static const uint8_t A2 = PIN_A2; - static const uint8_t A3 = PIN_A3; - static const uint8_t A4 = PIN_A4; - static const uint8_t A5 = PIN_A5; - static const uint8_t A6 = PIN_A6; - static const uint8_t A7 = PIN_A7; +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; #define ADC_RESOLUTION 14 // Other pins @@ -91,7 +90,7 @@ extern "C" #define PIN_NFC1 (9) #define PIN_NFC2 (10) - static const uint8_t AREF = PIN_AREF; +static const uint8_t AREF = PIN_AREF; /* * Serial interfaces @@ -112,10 +111,10 @@ extern "C" #define PIN_SPI_MOSI (44) #define PIN_SPI_SCK (43) - static const uint8_t SS = 42; - static const uint8_t MOSI = PIN_SPI_MOSI; - static const uint8_t MISO = PIN_SPI_MISO; - static const uint8_t SCK = PIN_SPI_SCK; +static const uint8_t SS = 42; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; /* * Wire Interfaces @@ -137,6 +136,10 @@ extern "C" #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI +// Meshtastic specific flags +#define USE_SIM_RADIO +#define USE_SEGGER + #ifdef __cplusplus } #endif From 7224782d23e9a57454aa9ffc68d4469c605fbfa6 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 11 Apr 2021 15:17:56 +0800 Subject: [PATCH 5/7] rak4631: gps now works --- docs/software/rak-wizblock.md | 17 +++++++++++ platformio.ini | 2 ++ src/gps/GPS.cpp | 15 +++++----- src/main.cpp | 7 +++-- variants/WisCore_RAK4631_Board/variant.h | 36 +++++++++++++++++++++++- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/docs/software/rak-wizblock.md b/docs/software/rak-wizblock.md index d400b58fb..95004c620 100644 --- a/docs/software/rak-wizblock.md +++ b/docs/software/rak-wizblock.md @@ -19,8 +19,19 @@ Must be installed on the front for the I2C wires to lineup Solar enclosure https://docs.rakwireless.com/Product-Categories/Accessories/RAKBox-B2/Overview/#product-description +Base datasheet (for GPIO mapping) +https://docs.rakwireless.com/Product-Categories/WisBlock/RAK5005-O/Datasheet/#specifications + +CPU module carrier (rak4631) +https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/#specifications + ## TODO +> 3V3_S is another 3.3 V power supply, it can be controlled by the MCU in order to disconnect the power sensors during idle periods to save power. 3V3_S is controlled by IO2 pin on the WisBlock Core board. +Set IO2=1, 3V3_S is on. +Set IO2=0, 3V3_S is off. + + * DONE solder header * DONE attach antenna * get building (LORA disabled) @@ -34,5 +45,11 @@ https://docs.rakwireless.com/Product-Categories/Accessories/RAKBox-B2/Overview/# * Boot * Enable LORA but no TX * Enable LORA TX +* Enable bluetooth +* Relase as standard part of build (including UF2s) +* Make this doc into a nice HOWTO: what to order, how to connect (which device in which slots), how to install software +* Setup battery voltage sensing +* Set bluetooth PIN support +* Confirm low power draw * send in PR to https://github.com/geeksville/WisBlock for boards define * \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 40fb2ced1..98772be95 100644 --- a/platformio.ini +++ b/platformio.ini @@ -299,6 +299,8 @@ build_flags = ${nrf52_base.build_flags} -Ivariants/WisCore_RAK4631_Board src_filter = ${nrf52_base.src_filter} +<../variants/eink> lib_deps = ${arduino_base.lib_deps} +debug_tool = jlink +upload_protocol = jlink ; The PPR board [env:ppr] diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index c5c30fcb9..080dd0eea 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -7,7 +7,7 @@ #include // If we have a serial GPS port it will not be null -#ifdef GPS_RX_PIN +#ifdef GPS_SERIAL_NUM HardwareSerial _serial_gps_real(GPS_SERIAL_NUM); HardwareSerial *GPS::_serial_gps = &_serial_gps_real; #elif defined(NRF52840_XXAA) || defined(NRF52833_XXAA) @@ -34,7 +34,8 @@ bool GPS::setupGPS() if (_serial_gps && !didSerialInit) { didSerialInit = true; -#ifdef GPS_RX_PIN +// ESP32 has a special set of parameters vs other arduino ports +#if defined(GPS_RX_PIN) && !defined(NO_ESP32) _serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); #else _serial_gps->begin(GPS_BAUDRATE); @@ -319,8 +320,8 @@ int GPS::prepareDeepSleep(void *unused) #include "NMEAGPS.h" #endif - -GPS* createGps() { +GPS *createGps() +{ #ifdef NO_GPS return nullptr; @@ -329,7 +330,7 @@ GPS* createGps() { #ifdef GPS_TX_PIN // Init GPS - first try ublox UBloxGPS *ublox = new UBloxGPS(); - + if (!ublox->setup()) { DEBUG_MSG("ERROR: No UBLOX GPS found\n"); delete ublox; @@ -344,9 +345,9 @@ GPS* createGps() { // assume NMEA at 9600 baud. DEBUG_MSG("Hoping that NMEA might work\n"); #ifdef HAS_AIR530_GPS - GPS* new_gps = new Air530GPS(); + GPS *new_gps = new Air530GPS(); #else - GPS* new_gps = new NMEAGPS(); + GPS *new_gps = new NMEAGPS(); #endif new_gps->setup(); return new_gps; diff --git a/src/main.cpp b/src/main.cpp index e55afc7b9..547188752 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -427,8 +427,11 @@ void setup() readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) #ifdef GENIEBLOCKS - // gps setup - pinMode(GPS_RESET_N, OUTPUT); + I'm intentionally breaking your build so you see this note. Feel free to revert if not correct. I think you can + removed this code by instead defining PIN_GPS_RESET and use the shared code in GPS.cpp instead. + + // gps setup + pinMode(GPS_RESET_N, OUTPUT); pinMode(GPS_EXTINT, OUTPUT); digitalWrite(GPS_RESET_N, HIGH); digitalWrite(GPS_EXTINT, LOW); diff --git a/variants/WisCore_RAK4631_Board/variant.h b/variants/WisCore_RAK4631_Board/variant.h index b8e52e995..1b782839f 100644 --- a/variants/WisCore_RAK4631_Board/variant.h +++ b/variants/WisCore_RAK4631_Board/variant.h @@ -136,8 +136,42 @@ static const uint8_t SCK = PIN_SPI_SCK; #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI +/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports + RAK5005-O <-> nRF52840 + IO1 <-> P0.17 (Arduino GPIO number 17) + IO2 <-> P1.02 (Arduino GPIO number 34) + IO3 <-> P0.21 (Arduino GPIO number 21) + IO4 <-> P0.04 (Arduino GPIO number 4) + IO5 <-> P0.09 (Arduino GPIO number 9) + IO6 <-> P0.10 (Arduino GPIO number 10) + SW1 <-> P0.01 (Arduino GPIO number 1) + A0 <-> P0.04/AIN2 (Arduino Analog A2 + A1 <-> P0.31/AIN7 (Arduino Analog A7 + SPI_CS <-> P0.26 (Arduino GPIO number 26) + */ + +// RAK4630 LoRa module +#define SX1262_CS (42) +#define SX1262_DIO1 (47) +#define SX1262_BUSY (46) +#define SX1262_RESET (38) +#define SX1262_TXEN (39) +#define SX1262_RXEN (37) +#define SX1262_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3 + +// RAK1910 GPS module +// If using the wisblock GPS module and pluged into Port A on WisBlock base +// IO1 is hooked to PPS (pin 12 on header) = gpio 17 +// IO2 is hooked to GPS RESET = gpio 34, but it can not be used to this because IO2 is ALSO used to control 3V3_S power (1 is on). +// Therefore must be 1 to keep peripherals powered +// Power is on the controllable 3V3_S rail +// #define PIN_GPS_RESET (34) +#define PIN_GPS_EN (34) +#define PIN_GPS_PPS (17) // Pulse per second input from the GPS +#define GPS_RX_PIN PIN_SERIAL1_RX +#define GPS_TX_PIN PIN_SERIAL1_TX + // Meshtastic specific flags -#define USE_SIM_RADIO #define USE_SEGGER #ifdef __cplusplus From 55b38a7b02ca403d84de930fe61bbbd0d1652eb6 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 12 Apr 2021 13:25:55 +0800 Subject: [PATCH 6/7] RAK4631 is almost feature complete --- docs/software/rak-wizblock.md | 24 ++++++----------- proto | 2 +- src/configuration.h | 4 +++ src/main.cpp | 9 ++++--- src/mesh/generated/mesh.pb.h | 1 + src/nrf52/main-nrf52.cpp | 34 ++++++++++++------------ variants/WisCore_RAK4631_Board/variant.h | 3 --- 7 files changed, 36 insertions(+), 41 deletions(-) diff --git a/docs/software/rak-wizblock.md b/docs/software/rak-wizblock.md index 95004c620..7f6b8be48 100644 --- a/docs/software/rak-wizblock.md +++ b/docs/software/rak-wizblock.md @@ -4,13 +4,17 @@ https://docs.rakwireless.com/Product-Categories/WisBlock/Quickstart/#wisblock-base-2 +FIXME - list required, recommended and optional components + GPS module: Supposedly "Install in slot A only" but I think installing on the back would fit better with the OLED. FIXME. https://docs.rakwireless.com/Product-Categories/WisBlock/RAK1910/Overview/#product-description -ST KPS22HB -baro sensor +ST LPS22HB +baro & temp sensor, i2c address 0x5c https://docs.rakwireless.com/Product-Categories/WisBlock/RAK1902/Overview/#product-description +https://www.st.com/en/mems-and-sensors/lps22hb.html +https://www.st.com/resource/en/datasheet/lps22hb.pdf OLED https://docs.rakwireless.com/Product-Categories/WisBlock/RAK1921/Overview/#product-features @@ -27,29 +31,17 @@ https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/#spec ## TODO +* Turn off external 3V3 supply when not using GPS to save power! > 3V3_S is another 3.3 V power supply, it can be controlled by the MCU in order to disconnect the power sensors during idle periods to save power. 3V3_S is controlled by IO2 pin on the WisBlock Core board. Set IO2=1, 3V3_S is on. Set IO2=0, 3V3_S is off. - -* DONE solder header -* DONE attach antenna -* get building (LORA disabled) -* DONE FIX LEDs -* DONE FIX BUTTONs -* DONE FIX I2C assignment -* FIX LORA SPI -* FIX GPS GPIO assignment -* Disable Bluetooth -* Disable LORA -* Boot -* Enable LORA but no TX -* Enable LORA TX * Enable bluetooth * Relase as standard part of build (including UF2s) * Make this doc into a nice HOWTO: what to order, how to connect (which device in which slots), how to install software * Setup battery voltage sensing * Set bluetooth PIN support * Confirm low power draw +* Confirm that OLED works * send in PR to https://github.com/geeksville/WisBlock for boards define * \ No newline at end of file diff --git a/proto b/proto index ff66c5494..6e05f72a1 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit ff66c549498052a1a3cf75f8ad1a66a4adcdc413 +Subproject commit 6e05f72a1a75322bcbea21980386a61b2945fd4f diff --git a/src/configuration.h b/src/configuration.h index f0d3a0a53..1e58b7001 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -409,6 +409,10 @@ along with this program. If not, see . #define HW_VENDOR HardwareModel_PPR +#elif defined(RAK4630) + +#define HW_VENDOR HardwareModel_RAK4631 + #elif NRF52_SERIES #define HW_VENDOR HardwareModel_NRF52_UNKNOWN diff --git a/src/main.cpp b/src/main.cpp index 547188752..c6bebe36f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -427,11 +427,12 @@ void setup() readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) #ifdef GENIEBLOCKS - I'm intentionally breaking your build so you see this note. Feel free to revert if not correct. I think you can - removed this code by instead defining PIN_GPS_RESET and use the shared code in GPS.cpp instead. + Im intentionally breaking your build so you see this note.Feel free to revert if not correct.I think you can + remove this GPS_RESET_N code by instead defining PIN_GPS_RESET and + use the shared code in GPS.cpp instead.- geeksville - // gps setup - pinMode(GPS_RESET_N, OUTPUT); + // gps setup + pinMode(GPS_RESET_N, OUTPUT); pinMode(GPS_EXTINT, OUTPUT); digitalWrite(GPS_RESET_N, HIGH); digitalWrite(GPS_EXTINT, LOW); diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index d31fee6fa..eb771ebab 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -21,6 +21,7 @@ typedef enum _HardwareModel { HardwareModel_TBEAM0p7 = 6, HardwareModel_T_ECHO = 7, HardwareModel_TLORA_V1_1p3 = 8, + HardwareModel_RAK4631 = 9, HardwareModel_LORA_RELAY_V1 = 32, HardwareModel_NRF52840DK = 33, HardwareModel_PPR = 34, diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 2c5bcac8b..abb99042c 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -44,10 +44,23 @@ void getMacAddr(uint8_t *dmac) } } +static void initBrownout() +{ + auto vccthresh = POWER_POFCON_THRESHOLD_V17; + + auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled); + assert(err_code == NRF_SUCCESS); + + err_code = sd_power_pof_threshold_set(vccthresh); + assert(err_code == NRF_SUCCESS); + + // We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice +} + NRF52Bluetooth *nrf52Bluetooth; static bool bleOn = false; -static const bool useSoftDevice = false; // Set to false for easier debugging +static const bool useSoftDevice = true; // Set to false for easier debugging void setBluetoothEnable(bool on) { @@ -59,6 +72,9 @@ void setBluetoothEnable(bool on) else { nrf52Bluetooth = new NRF52Bluetooth(); nrf52Bluetooth->setup(); + + // We delay brownout init until after BLE because BLE starts soft device + initBrownout(); } } } else { @@ -81,20 +97,6 @@ int printf(const char *fmt, ...) return res; } -void initBrownout() -{ - auto vccthresh = POWER_POFCON_THRESHOLD_V17; - - if (useSoftDevice) { - auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled); - assert(err_code == NRF_SUCCESS); - - err_code = sd_power_pof_threshold_set(vccthresh); - assert(err_code == NRF_SUCCESS); - } - // We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice -} - void checkSDEvents() { if (useSoftDevice) { @@ -147,8 +149,6 @@ void nrf52Setup() // randomSeed(r); DEBUG_MSG("FIXME, call randomSeed\n"); // ::printf("TESTING PRINTF\n"); - - initBrownout(); } void cpuDeepSleep(uint64_t msecToWake) diff --git a/variants/WisCore_RAK4631_Board/variant.h b/variants/WisCore_RAK4631_Board/variant.h index 1b782839f..00016d24d 100644 --- a/variants/WisCore_RAK4631_Board/variant.h +++ b/variants/WisCore_RAK4631_Board/variant.h @@ -171,9 +171,6 @@ static const uint8_t SCK = PIN_SPI_SCK; #define GPS_RX_PIN PIN_SERIAL1_RX #define GPS_TX_PIN PIN_SERIAL1_TX -// Meshtastic specific flags -#define USE_SEGGER - #ifdef __cplusplus } #endif From f1376406fa335c6ec40fef41cd87401990337c80 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 12 Apr 2021 13:39:45 +0800 Subject: [PATCH 7/7] Add RAK4631 to build --- bin/build-all.sh | 2 +- docs/software/rak-wizblock.md | 54 +++++++++++++++++++++++------------ version.properties | 2 +- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/bin/build-all.sh b/bin/build-all.sh index 3f52db901..9ad4d58d0 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -8,7 +8,7 @@ BOARDS_ESP32="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec tbeam0.7" #BOARDS_ESP32=tbeam # FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine -BOARDS_NRF52="lora-relay-v1" +BOARDS_NRF52="rak4631" OUTDIR=release/latest diff --git a/docs/software/rak-wizblock.md b/docs/software/rak-wizblock.md index 7f6b8be48..6580ac20d 100644 --- a/docs/software/rak-wizblock.md +++ b/docs/software/rak-wizblock.md @@ -1,4 +1,39 @@ -# RAK Wireless RisBlock +# RAK Wireless RisBlock / RAK 4631 / RAK 4630 + +This is early documentation on how to install/run Meshtastic on the (very slick!) RAK 4631/4630 boards. + +## How to install our binary releases + +### Installing over USB + +You can install our release binaries by "drag-and-drop" onto a special simulated "USB disk" that appears on your computer while the device is in the bootloader. To install: + +1. Enter the bootloader by removing all power (including the battery), then connect the device to USB. For the first 30ish seconds after connection the device will wait in the bootloader (before starting any application that might be loaded) +2. From our relase zip file, drag and drop "firmware-rak4631-xxx.uf2" onto the bootloader "USB drive". The drive will be named "FTH...BOOT" +3. That's it. The device should reboot and start running meshtastic. + +You'll know meshtastic is running because the GREEN LED will flash briefly twice a second. You can now connect to meshtastic via the USB port from the python app or bluetooth to any of the other applications. + +### Installing over Bluetooth + +It is also possible to install/upgrade these boards using bluetooth (using either Android/iOS or Linux). A future version of this document will describe how to do that. + +## TODO + +Some work items still remain... + +* Turn off external 3V3 supply when not using GPS to save power! +> 3V3_S is another 3.3 V power supply, it can be controlled by the MCU in order to disconnect the power sensors during idle periods to save power. 3V3_S is controlled by IO2 pin on the WisBlock Core board. +Set IO2=1, 3V3_S is on. +Set IO2=0, 3V3_S is off. + +* Fix android bug with detecting nrf52 BLE devices +* Make this doc into a nice HOWTO: what to order, how to connect (which device in which slots), how to install software +* Setup battery voltage sensing +* Set bluetooth PIN support +* Confirm low power draw +* Confirm that OLED works +* send in PR to https://github.com/geeksville/WisBlock for boards define ## Docs @@ -28,20 +63,3 @@ https://docs.rakwireless.com/Product-Categories/WisBlock/RAK5005-O/Datasheet/#sp CPU module carrier (rak4631) https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/#specifications - -## TODO - -* Turn off external 3V3 supply when not using GPS to save power! -> 3V3_S is another 3.3 V power supply, it can be controlled by the MCU in order to disconnect the power sensors during idle periods to save power. 3V3_S is controlled by IO2 pin on the WisBlock Core board. -Set IO2=1, 3V3_S is on. -Set IO2=0, 3V3_S is off. - -* Enable bluetooth -* Relase as standard part of build (including UF2s) -* Make this doc into a nice HOWTO: what to order, how to connect (which device in which slots), how to install software -* Setup battery voltage sensing -* Set bluetooth PIN support -* Confirm low power draw -* Confirm that OLED works -* send in PR to https://github.com/geeksville/WisBlock for boards define -* \ No newline at end of file diff --git a/version.properties b/version.properties index 0d06a597c..55d21ed69 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 2 -build = 25 +build = 26