diff --git a/bin/install-bootloader.sh b/bin/install-bootloader.sh index 5dde70505..cd03281fb 100755 --- a/bin/install-bootloader.sh +++ b/bin/install-bootloader.sh @@ -2,7 +2,19 @@ set -e +# dependencies +# apt install srecord + BOOTDIR=/home/kevinh/development/meshtastic/Adafruit_nRF52_Bootloader +BOARD=othernet_ppr1 +BOOTVER=0.3.2 +BOOTNUM=125 +BOOTSHA=g4582f73 +SDVER=6.1.1 +PROJ=ppr1 + +# FIXME for nRF52840 use 0xff000 +BOOTSET=0x7f000 nrfjprog --eraseall -f nrf52 @@ -11,12 +23,12 @@ nrfjprog --eraseall -f nrf52 # first 4 bytes should be 0x01 to indicate valid app image # second 4 bytes should be 0x00 to indicate no CRC required for image echo "01 00 00 00 00 00 00 00" | xxd -r -p - >/tmp/bootconf.bin -srec_cat /tmp/bootconf.bin -binary -offset 0xff000 -output /tmp/bootconf.hex -intel +srec_cat /tmp/bootconf.bin -binary -offset $BOOTSET -output /tmp/bootconf.hex -intel echo Generating merged hex file -mergehex -m $BOOTDIR/_build/build-ttgo_eink/ttgo_eink_bootloader-0.3.2-124-g69bd8eb-dirty_s140_6.1.1.hex .pio/build/eink/firmware.hex /tmp/bootconf.hex -o ttgo_eink_full.hex +mergehex -o ${BOARD}_full.hex -m $BOOTDIR/_build/build-$BOARD/${BOARD}_bootloader-$BOOTVER-$BOOTNUM-$BOOTSHA-dirty_s140_$SDVER.hex .pio/build/$PROJ/firmware.hex /tmp/bootconf.hex echo Telling bootloader app region is valid and telling CPU to run -nrfjprog --program ttgo_eink_full.hex -f nrf52 --reset +nrfjprog --program ${BOARD}_full.hex -f nrf52 --reset # nrfjprog --readuicr /tmp/uicr.hex; objdump -s /tmp/uicr.hex | less diff --git a/bin/view-map.sh b/bin/view-map.sh new file mode 100755 index 000000000..badeb0843 --- /dev/null +++ b/bin/view-map.sh @@ -0,0 +1,2 @@ +echo using amap tool to display memory map +amap .pio/build/output.map diff --git a/boards/ppr1.json b/boards/ppr1.json new file mode 100644 index 000000000..6c395b0b4 --- /dev/null +++ b/boards/ppr1.json @@ -0,0 +1,46 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52833_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52833_PPR -DNRF52833_XXAA", + "f_cpu": "64000000L", + "hwids": [["0x239A", "0x4406"]], + "usb_product": "PPR", + "mcu": "nrf52833", + "variant": "ppr", + "variants_dir": "variants", + "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": "nRF52833_xxAA", + "onboard_tools": ["jlink"], + "svd_path": "nrf52833.svd" + }, + "frameworks": ["arduino"], + "name": "Meshtastic PPR1 (Adafruit BSP)", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "require_upload_port": true, + "speed": 115200, + "protocol": "jlink", + "protocols": ["jlink", "nrfjprog", "stlink"] + }, + "url": "https://meshtastic.org/", + "vendor": "Othernet" +} diff --git a/platformio.ini b/platformio.ini index 5397f693c..5e2c701bc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = lora-relay-v2 # 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 = ppr1 # 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 = heltec # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] @@ -234,6 +234,16 @@ lib_deps = ${arduino_base.lib_deps} UC1701 +; The PPR board +[env:ppr1] +extends = nrf52_base +board = ppr1 +build_flags = ${nrf52_base.build_flags} -Ivariants/ppr1 +src_filter = ${nrf52_base.src_filter} +<../variants/ppr1> +lib_deps = + ${arduino_base.lib_deps} + UC1701 + ; Prototype eink/nrf52840/sx1262 device [env:eink] extends = nrf52_base diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 4469fd97e..5d5cb59e8 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -10,7 +10,7 @@ #ifdef GPS_RX_PIN HardwareSerial _serial_gps_real(GPS_SERIAL_NUM); HardwareSerial *GPS::_serial_gps = &_serial_gps_real; -#elif defined(NRF52840_XXAA) +#elif defined(NRF52840_XXAA) || defined(NRF52833_XXAA) // Assume NRF52840 HardwareSerial *GPS::_serial_gps = &Serial1; #else @@ -47,6 +47,12 @@ void GPS::wake() digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE); pinMode(PIN_GPS_WAKE, OUTPUT); #endif + +#ifdef PIN_GPS_RESET + digitalWrite(PIN_GPS_RESET, 0); + pinMode(PIN_GPS_RESET, OUTPUT); +#endif + } diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index a177441a4..86a096137 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -1,6 +1,11 @@ #include "SX1262Interface.h" #include +// Particular boards might define a different max power based on what their hardware can do +#ifndef SX1262_MAX_POWER +#define SX1262_MAX_POWER 22 +#endif + SX1262Interface::SX1262Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi) : RadioLibInterface(cs, irq, rst, busy, spi, &lora), lora(&module) @@ -39,10 +44,10 @@ bool SX1262Interface::init() applyModemConfig(); if (power == 0) - power = 22; + power = SX1262_MAX_POWER; - if (power > 22) // This chip has lower power limits than some - power = 22; + if (power > SX1262_MAX_POWER) // This chip has lower power limits than some + power = SX1262_MAX_POWER; limitPower(); diff --git a/variants/ppr1/variant.cpp b/variants/ppr1/variant.cpp new file mode 100644 index 000000000..7c763037d --- /dev/null +++ b/variants/ppr1/variant.cpp @@ -0,0 +1,43 @@ +/* + 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 "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.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}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); +} diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h new file mode 100644 index 000000000..0e703f4eb --- /dev/null +++ b/variants/ppr1/variant.h @@ -0,0 +1,163 @@ +/* + 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 +*/ + +#pragma once + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +// This board does have a 32khz crystal +#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 (46) +#define NUM_DIGITAL_PINS (46) +#define NUM_ANALOG_INPUTS (0) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (25) +#define PIN_LED2 (11) + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_RED PIN_LED1 +#define LED_GREEN PIN_LED2 + +// FIXME, bluefruit automatically blinks this led while connected. call AdafruitBluefruit::autoConnLed to change this. +#define LED_BLUE LED_GREEN + +#define LED_STATE_ON 1 // State when LED is litted + +/* + * Buttons + */ +#define PIN_BUTTON1 4 // up +#define PIN_BUTTON2 2 // left +#define PIN_BUTTON3 3 // center +#define PIN_BUTTON4 5 // right +#define PIN_BUTTON5 6 // down + +/* + * Analog pins + */ +#define PIN_A0 (0xff) +#define PIN_A1 (0xff) +#define PIN_A2 (0xff) +#define PIN_A3 (0xff) +#define PIN_A4 (0xff) +#define PIN_A5 (0xff) +#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 (0xff) +//#define PIN_NFC1 (9) +//#define PIN_NFC2 (10) + +static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ + +// GPS is on Serial1 +#define PIN_SERIAL1_RX (8) +#define PIN_SERIAL1_TX (9) + +// We intentionally leave this undefined so we don't even try to make a Ublox driver +// #define GPS_TX_PIN PIN_SERIAL1_TX +// #define GPS_RX_PIN PIN_SERIAL1_RX + +#define PIN_GPS_RESET 29 // active high? +#define PIN_GPS_PPS 28 +#define PIN_GPS_WAKE 7 // GPS_EN active high? + +#define PIN_VUSB_EN 21 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (15) +#define PIN_SPI_MOSI (13) +#define PIN_SPI_SCK (12) + +// static const uint8_t SS = 44; +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 (32 + 2) +#define PIN_WIRE_SCL (32) + +// CUSTOM GPIOs the SX1262 +#define SX1262_CS (0 + 10) // FIXME - we really should define LORA_CS instead +#define SX1262_DIO1 (0 + 20) +#define SX1262_DIO2 (0 + 26) +#define SX1262_BUSY (0 + 19) +#define SX1262_RESET (0 + 17) +#define SX1262_TXEN (0 + 24) +#define SX1262_RXEN (0 + 22) +#define SX1262_E22 // Not really an E22 but this board clones using DIO3 for tcxo control + +// FIXME, to prevent burning out parts I've set the power level super low, because I don't have +// an antenna wired up +#define SX1262_MAX_POWER 1 + +#define LORA_DISABLE_SENDING // Define this to disable transmission for testing (power testing etc...) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +#define USE_SEGGER + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/