From 9ccd3334aa652134bb035f4e0820fa9f90122ed3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 16 May 2020 09:12:16 -0700 Subject: [PATCH 01/16] add placeholder support for othernet PPR board --- .gitmodules | 2 +- lib/tinyusb | 2 +- src/boards/othernet_ppr/board.h | 58 ++++++++++++++++++++++++++++++++ src/boards/othernet_ppr/board.mk | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/boards/othernet_ppr/board.h create mode 100644 src/boards/othernet_ppr/board.mk diff --git a/.gitmodules b/.gitmodules index 8acbe854..19b22ee9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tinyusb"] path = lib/tinyusb - url = https://github.com/hathach/tinyusb.git + url = https://github.com/meshtastic/tinyusb.git [submodule "lib/nrfx"] path = lib/nrfx url = https://github.com/NordicSemiconductor/nrfx.git diff --git a/lib/tinyusb b/lib/tinyusb index f2b761fe..4f4acb05 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit f2b761fee98cf9d09500e2475861e51c6ee58e61 +Subproject commit 4f4acb058d02d41e15dbb884057b6cab7593cb82 diff --git a/src/boards/othernet_ppr/board.h b/src/boards/othernet_ppr/board.h new file mode 100644 index 00000000..e8133ea4 --- /dev/null +++ b/src/boards/othernet_ppr/board.h @@ -0,0 +1,58 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef PPR_H +#define PPR_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 0 +#define LED_SECONDARY_PIN 1 +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 4 // center +#define BUTTON_2 2 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Othernet" +#define BLEDIS_MODEL "PPR" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define UF2_PRODUCT_NAME "Othernet PPR" +#define UF2_VOLUME_LABEL "PPRBOOT " +#define UF2_BOARD_ID "nRF52840-ppr-v1" +#define UF2_INDEX_URL "https://www.meshtastic.org" + +#endif diff --git a/src/boards/othernet_ppr/board.mk b/src/boards/othernet_ppr/board.mk new file mode 100644 index 00000000..9d29ac69 --- /dev/null +++ b/src/boards/othernet_ppr/board.mk @@ -0,0 +1 @@ +MCU_SUB_VARIANT = nrf52840 From 1d77daa4cb7a64fdb162b39c60bda435e339c12f Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 4 Jun 2020 16:45:31 -0700 Subject: [PATCH 02/16] Place data from .uicrREGOUT0 into UICR.REGOUT0 flash word. Used to set VCC voltage upon power-up. --- linker/nrf52840.ld | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linker/nrf52840.ld b/linker/nrf52840.ld index fcfa425e..bc1adc12 100644 --- a/linker/nrf52840.ld +++ b/linker/nrf52840.ld @@ -41,6 +41,9 @@ MEMORY /** Location in UICR where mbr params page address is stored. */ UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04 + + /** Location in UICR of REGOUT0 (used to set voltage levels for VCC at boot) */ + UICR_REGOUT0(r) : ORIGIN = 0x10001304, LENGTH = 0x04 } SECTIONS @@ -81,6 +84,12 @@ SECTIONS KEEP(*(.uicrMbrParamsPageAddress)) } > UICR_MBR_PARAM_PAGE + /* Write REGOUT0 in UICR. */ + .uicrREGOUT0 : + { + KEEP(*(.uicrREGOUT0)) + } > UICR_REGOUT0 + .dbl_reset(NOLOAD) : { From aba9b5230a7a2e49449b10eccc7b571aee27dc93 Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 4 Jun 2020 16:46:33 -0700 Subject: [PATCH 03/16] Update to lastest bootloader/tinyusb code, set regout0 to correct value --- NOTES-kh.md | 22 ++++++++++++++++++++++ lib/tinyusb | 2 +- src/boards/othernet_ppr/board.h | 9 ++++++++- src/boards/othernet_ppr/pinconfig.c | 22 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 NOTES-kh.md create mode 100644 src/boards/othernet_ppr/pinconfig.c diff --git a/NOTES-kh.md b/NOTES-kh.md new file mode 100644 index 00000000..6a6a8625 --- /dev/null +++ b/NOTES-kh.md @@ -0,0 +1,22 @@ +git submodule update --init --recursive + +npm install --global xpm +xpm install --global @xpack-dev-tools/arm-none-eabi-gcc@latest +Installing globally in '/home/kevinh/opt/xPacks/@xpack-dev-tools/arm-none-eabi-gcc/9.2.1-1.1.1'... + +make BOARD=pca10056 all +make BOARD=othernet_ppr all DEBUG=1 + +pip3 install --user adafruit-nrfutil + +# To program with jlink + +``` + +JLinkExe -device nrf52840_xxaa -if swd -speed 4000 -autoconnect 1 + +objdump -s ./_build/build-othernet_ppr/othernet_ppr_bootloader-0.3.2-108-g718c310-dirty_s140_6.1.1.hex | less + + +nrfjprog -e -f nrf52; nrfjprog -f nrf52 --program ./_build/build-othernet_ppr/othernet_ppr_bootloader-0.3.2-*-dirty_s140_6.1.1.hex +``` diff --git a/lib/tinyusb b/lib/tinyusb index 4f4acb05..4159d4f8 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 4f4acb058d02d41e15dbb884057b6cab7593cb82 +Subproject commit 4159d4f837f655c3918adc2f92cf84a0d011ed7e diff --git a/src/boards/othernet_ppr/board.h b/src/boards/othernet_ppr/board.h index e8133ea4..1a496490 100644 --- a/src/boards/othernet_ppr/board.h +++ b/src/boards/othernet_ppr/board.h @@ -39,7 +39,9 @@ #define BUTTONS_NUMBER 2 #define BUTTON_1 4 // center #define BUTTON_2 2 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_PULL \ + NRF_GPIO_PIN_PULLUP // really should be NOPULL but the bootloader code only + // checks for PULLUP vs PULLDOWN //--------------------------------------------------------------------+ // BLE OTA @@ -50,6 +52,11 @@ //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ + +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 + #define UF2_PRODUCT_NAME "Othernet PPR" #define UF2_VOLUME_LABEL "PPRBOOT " #define UF2_BOARD_ID "nRF52840-ppr-v1" diff --git a/src/boards/othernet_ppr/pinconfig.c b/src/boards/othernet_ppr/pinconfig.c new file mode 100644 index 00000000..70700787 --- /dev/null +++ b/src/boards/othernet_ppr/pinconfig.c @@ -0,0 +1,22 @@ +#include "boards.h" +#include "uf2/configkeys.h" + +__attribute__((used, section(".bootloaderConfig"))) +const uint32_t bootloaderConfig[] = +{ + /* CF2 START */ + CFG_MAGIC0, CFG_MAGIC1, // magic + 5, 100, // used entries, total entries + + 204, 0x100000, // FLASH_BYTES = 0x100000 + 205, 0x40000, // RAM_BYTES = 0x40000 + 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, 0xada52840, // UF2_FAMILY = 0xada52840 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + + 0, 0, 0, 0, 0, 0, 0, 0 + /* CF2 END */ +}; + + __attribute__ ((section(".uicrREGOUT0"))) +volatile uint32_t m_uicr_regout0 = 0xfffffff4; From 0645700910cc360682692dfab52f3d20fde4c230 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 16:35:20 -0700 Subject: [PATCH 04/16] Change SEGGER options to non blocking print. In the previous config if you were printing a lot in your bootloader debug and you didn't have an ICE connected, the boot would stall waiting for the SEGGER to read the print buffer. Better I think to just throw away the oldest contents of the ring buffer if the ICE is not connected. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 627e3ae1..16f55f13 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,7 @@ IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52 ifeq ($(DEBUG), 1) RTT_SRC = lib/SEGGER_RTT - CFLAGS += -ggdb -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL + CFLAGS += -ggdb -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_NO_BLOCK_TRIM IPATH += $(RTT_SRC)/RTT C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c endif From da07b562a9e5f5a46507a15ecd751822a93c2674 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 15 Jun 2020 16:35:48 -0700 Subject: [PATCH 05/16] Do not merge: nasty hacks to make a prototype work --- lib/sdk11/components/libraries/bootloader_dfu/bootloader.c | 2 +- src/main.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 748ccbcc..e7b2e787 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -169,7 +169,7 @@ bool bootloader_app_is_valid(void) success = (image_crc == p_bootloader_settings->bank_0_crc); } - return success; + return true || success; // hack } diff --git a/src/main.c b/src/main.c index 6148298d..e02ef442 100644 --- a/src/main.c +++ b/src/main.c @@ -154,7 +154,7 @@ void softdev_mbr_init(void) //--------------------------------------------------------------------+ int main(void) { - PRINTF("Bootlaoder Start\r\n"); + PRINTF("Bootloader Start\r\n"); // Populate Boot Address and MBR Param into MBR if not already // MBR_BOOTLOADER_ADDR/MBR_PARAM_PAGE_ADDR are used if available, else UICR registers are used @@ -210,6 +210,9 @@ int main(void) if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1; + // kevinh temp hack + dfu_start = 0; + // App mode: register 1st reset and DFU startup (nrf52832) if ( ! (just_start_app || dfu_start || !valid_app) ) { @@ -235,6 +238,7 @@ int main(void) else (*dbl_reset_mem) = 0; + PRINTF("flags dfu_start=%d, valid_app=%d, just_start=%d\r\n", dfu_start, valid_app, just_start_app); if ( dfu_start || !valid_app ) { if ( _ota_dfu ) From d6019ded26bf8b5dd3a9ad7a0ae0231868c8fc13 Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 4 Jun 2020 16:45:31 -0700 Subject: [PATCH 06/16] Place data from .uicrREGOUT0 into UICR.REGOUT0 flash word. Used to set VCC voltage upon power-up. --- linker/nrf52840.ld | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linker/nrf52840.ld b/linker/nrf52840.ld index fcfa425e..bc1adc12 100644 --- a/linker/nrf52840.ld +++ b/linker/nrf52840.ld @@ -41,6 +41,9 @@ MEMORY /** Location in UICR where mbr params page address is stored. */ UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04 + + /** Location in UICR of REGOUT0 (used to set voltage levels for VCC at boot) */ + UICR_REGOUT0(r) : ORIGIN = 0x10001304, LENGTH = 0x04 } SECTIONS @@ -81,6 +84,12 @@ SECTIONS KEEP(*(.uicrMbrParamsPageAddress)) } > UICR_MBR_PARAM_PAGE + /* Write REGOUT0 in UICR. */ + .uicrREGOUT0 : + { + KEEP(*(.uicrREGOUT0)) + } > UICR_REGOUT0 + .dbl_reset(NOLOAD) : { From 9478eb7ed3eebe0cd41a3a137e9673e376ca8a23 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 16 Jun 2020 09:29:46 -0700 Subject: [PATCH 07/16] address comments from review (warn users, also support 833) --- linker/nrf52833.ld | 16 ++++++++++++++++ linker/nrf52840.ld | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/linker/nrf52833.ld b/linker/nrf52833.ld index 46a23dca..4cac961e 100644 --- a/linker/nrf52833.ld +++ b/linker/nrf52833.ld @@ -39,6 +39,16 @@ MEMORY /** Location in UICR where mbr params page address is stored. */ UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04 + + /** Location in UICR of REGOUT0 (used to set voltage levels for VCC at boot) + * + * IMPORTANT NOTE: This controls the voltage provided on the VCC output of the CPU. Changing this value from the default + * can physically damage parts on your board. If using a SWD debugger you should consider connecting the Vref input + * for that debugger to the VCC rail. Think carefully before using this feature. + * Example usage: + * __attribute__ ((section(".uicrREGOUT0"))) volatile uint32_t m_uicr_regout0 = 0xfffffff4; + */ + UICR_REGOUT0(r) : ORIGIN = 0x10001304, LENGTH = 0x04 } SECTIONS @@ -74,6 +84,12 @@ SECTIONS KEEP(*(.uicrMbrParamsPageAddress)) } > UICR_MBR_PARAM_PAGE + /* Write REGOUT0 in UICR. */ + .uicrREGOUT0 : + { + KEEP(*(.uicrREGOUT0)) + } > UICR_REGOUT0 + .dbl_reset(NOLOAD) : { diff --git a/linker/nrf52840.ld b/linker/nrf52840.ld index bc1adc12..dfd11e2d 100644 --- a/linker/nrf52840.ld +++ b/linker/nrf52840.ld @@ -42,7 +42,14 @@ MEMORY /** Location in UICR where mbr params page address is stored. */ UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04 - /** Location in UICR of REGOUT0 (used to set voltage levels for VCC at boot) */ + /** Location in UICR of REGOUT0 (used to set voltage levels for VCC at boot) + * + * IMPORTANT NOTE: This controls the voltage provided on the VCC output of the CPU. Changing this value from the default + * can physically damage parts on your board. If using a SWD debugger you should consider connecting the Vref input + * for that debugger to the VCC rail. Think carefully before using this feature. + * Example usage: + * __attribute__ ((section(".uicrREGOUT0"))) volatile uint32_t m_uicr_regout0 = 0xfffffff4; + */ UICR_REGOUT0(r) : ORIGIN = 0x10001304, LENGTH = 0x04 } From 778d2290780117b296521c98c938a8955aa726eb Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 10 Jul 2020 09:54:49 -0700 Subject: [PATCH 08/16] Add support for RAK815 board from here: https://store.rakwireless.com/products/rak815-hybrid-location-tracker --- src/boards/rak815/board.h | 62 ++++++++++++++++++++++++++++++++++++++ src/boards/rak815/board.mk | 2 ++ 2 files changed, 64 insertions(+) create mode 100644 src/boards/rak815/board.h create mode 100644 src/boards/rak815/board.mk diff --git a/src/boards/rak815/board.h b/src/boards/rak815/board.h new file mode 100644 index 00000000..6885ee7a --- /dev/null +++ b/src/boards/rak815/board.h @@ -0,0 +1,62 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _RAK815_H +#define _RAK815_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 4 +#define LED_PRIMARY_PIN 28 +#define LED_SECONDARY_PIN 29 +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 27 +#define BUTTON_2 24 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 28 +#define TX_PIN_NUMBER 29 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "RAK" +#define BLEDIS_MODEL "RAK815" + +#define UF2_PRODUCT_NAME "RAK815" +#define UF2_INDEX_URL "https://store.rakwireless.com/products/rak815-hybrid-location-tracker" + +#endif // _RAK815_H diff --git a/src/boards/rak815/board.mk b/src/boards/rak815/board.mk new file mode 100644 index 00000000..f932bb80 --- /dev/null +++ b/src/boards/rak815/board.mk @@ -0,0 +1,2 @@ +# nrf52 is nrf52832 +MCU_SUB_VARIANT = nrf52 From 25e3f01fc8f0281a0032f68806d8c70a86a6539d Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 10 Jul 2020 12:10:39 -0700 Subject: [PATCH 09/16] Fix RAK815 LEDs --- src/boards/rak815/board.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boards/rak815/board.h b/src/boards/rak815/board.h index 6885ee7a..a2f7df4c 100644 --- a/src/boards/rak815/board.h +++ b/src/boards/rak815/board.h @@ -28,9 +28,9 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 4 -#define LED_PRIMARY_PIN 28 -#define LED_SECONDARY_PIN 29 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 25 +#define LED_SECONDARY_PIN 26 #define LED_STATE_ON 1 /*------------------------------------------------------------------*/ From 39879280923d0867ce51a04ea120bb8f24326d8e Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 24 Sep 2020 15:00:26 -0700 Subject: [PATCH 10/16] First attempt at TTGO eink bootloader --- src/boards/ttgo_eink/board.h | 65 ++++++++++++++++++++++++++++++++ src/boards/ttgo_eink/board.mk | 1 + src/boards/ttgo_eink/pinconfig.c | 22 +++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/boards/ttgo_eink/board.h create mode 100644 src/boards/ttgo_eink/board.mk create mode 100644 src/boards/ttgo_eink/pinconfig.c diff --git a/src/boards/ttgo_eink/board.h b/src/boards/ttgo_eink/board.h new file mode 100644 index 00000000..6cfe7344 --- /dev/null +++ b/src/boards/ttgo_eink/board.h @@ -0,0 +1,65 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef TTGO_EINK_H +#define TTGO_EINK_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 (32 + 3) +#define BUTTON_2 (32 + 7) // FIXME: no second button lie and say not connected +#define BUTTON_PULL \ + NRF_GPIO_PIN_PULLUP // really should be NOPULL but the bootloader code only + // checks for PULLUP vs PULLDOWN + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "TTGO" +#define BLEDIS_MODEL "eink" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 + +#define UF2_PRODUCT_NAME "TTGO" +#define UF2_VOLUME_LABEL "EinkBoot " +#define UF2_BOARD_ID "ttgo-eink" +#define UF2_INDEX_URL "https://www.meshtastic.org" + +#endif diff --git a/src/boards/ttgo_eink/board.mk b/src/boards/ttgo_eink/board.mk new file mode 100644 index 00000000..9d29ac69 --- /dev/null +++ b/src/boards/ttgo_eink/board.mk @@ -0,0 +1 @@ +MCU_SUB_VARIANT = nrf52840 diff --git a/src/boards/ttgo_eink/pinconfig.c b/src/boards/ttgo_eink/pinconfig.c new file mode 100644 index 00000000..e05b7699 --- /dev/null +++ b/src/boards/ttgo_eink/pinconfig.c @@ -0,0 +1,22 @@ +#include "boards.h" +#include "uf2/configkeys.h" + +__attribute__((used, section(".bootloaderConfig"))) +const uint32_t bootloaderConfig[] = + { + /* CF2 START */ + CFG_MAGIC0, CFG_MAGIC1, // magic + 5, 100, // used entries, total entries + + 204, 0x100000, // FLASH_BYTES = 0x100000 + 205, 0x40000, // RAM_BYTES = 0x40000 + 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, 0xada52840, // UF2_FAMILY = 0xada52840 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + + 0, 0, 0, 0, 0, 0, 0, 0 + /* CF2 END */ +}; + +// We want output pin voltages to be 3.3V +__attribute__((section(".uicrREGOUT0"))) volatile uint32_t m_uicr_regout0 = 0xfffffff5; \ No newline at end of file From f6bfaac47169b299a160153763b73f7c0fc7336c Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 28 Sep 2020 09:03:01 -0700 Subject: [PATCH 11/16] Don't force CONFIG_GPIO_AS_PINRESET on all boards --- Makefile | 4 +++- lib/tinyusb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 16f55f13..52a8b40b 100644 --- a/Makefile +++ b/Makefile @@ -249,7 +249,9 @@ CFLAGS += -Wno-cast-function-type # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 -CFLAGS += -DCONFIG_GPIO_AS_PINRESET + +# We don't want this on all boards +# CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 diff --git a/lib/tinyusb b/lib/tinyusb index 4159d4f8..15397b96 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 4159d4f837f655c3918adc2f92cf84a0d011ed7e +Subproject commit 15397b9656f2dd2ebe5529afd4a9f8cfc4dc12fb From 4f9022df9884933841bfa24647f9eec8df70a56e Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 28 Sep 2020 15:14:37 -0700 Subject: [PATCH 12/16] ttgo_eink bootloader is done (I think) --- .../libraries/bootloader_dfu/bootloader.c | 2 +- src/boards/boards.c | 6 +++++- src/boards/ttgo_eink/board.h | 13 ++++++------- src/main.c | 3 --- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index e7b2e787..748ccbcc 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -169,7 +169,7 @@ bool bootloader_app_is_valid(void) success = (image_crc == p_bootloader_settings->bank_0_crc); } - return true || success; // hack + return success; } diff --git a/src/boards/boards.c b/src/boards/boards.c index e1ab96d3..99e8aa73 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -39,6 +39,10 @@ void neopixel_teardown(void); #endif +#ifndef BUTTON_SENSE +#define BUTTON_SENSE BUTTON_PULL +#endif + //------------- IMPLEMENTATION -------------// void button_init(uint32_t pin) { @@ -54,7 +58,7 @@ void button_init(uint32_t pin) bool button_pressed(uint32_t pin) { - uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0); + uint32_t const active_state = (BUTTON_SENSE == NRF_GPIO_PIN_PULLDOWN ? 1 : 0); return nrf_gpio_pin_read(pin) == active_state; } diff --git a/src/boards/ttgo_eink/board.h b/src/boards/ttgo_eink/board.h index 6cfe7344..4372771e 100644 --- a/src/boards/ttgo_eink/board.h +++ b/src/boards/ttgo_eink/board.h @@ -29,19 +29,18 @@ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 +#define LED_PRIMARY_PIN 13 // red +#define LED_SECONDARY_PIN 15 // blue #define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ #define BUTTONS_NUMBER 2 -#define BUTTON_1 (32 + 3) -#define BUTTON_2 (32 + 7) // FIXME: no second button lie and say not connected -#define BUTTON_PULL \ - NRF_GPIO_PIN_PULLUP // really should be NOPULL but the bootloader code only - // checks for PULLUP vs PULLDOWN +#define BUTTON_1 (32 + 10) +#define BUTTON_2 (0 + 18) // We repurpose the RESET button as button 2 +#define BUTTON_PULL NRF_GPIO_PIN_NOPULL +#define BUTTON_SENSE NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/main.c b/src/main.c index e02ef442..376127d6 100644 --- a/src/main.c +++ b/src/main.c @@ -210,9 +210,6 @@ int main(void) if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1; - // kevinh temp hack - dfu_start = 0; - // App mode: register 1st reset and DFU startup (nrf52832) if ( ! (just_start_app || dfu_start || !valid_app) ) { From 69bd8ebec107022dce81fe16ab4f64d93a12429c Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 29 Sep 2020 12:57:39 -0700 Subject: [PATCH 13/16] protect against buttons showing wrong values at power on --- src/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.c b/src/main.c index 376127d6..51c71631 100644 --- a/src/main.c +++ b/src/main.c @@ -197,6 +197,11 @@ int main(void) led_state(STATE_WRITING_FINISHED); } + // Delay 20ms so that the button capacitors can charge up before + // reading the buttons. Avoids: + // https://devzone.nordicsemi.com/f/nordic-q-a/20698/bootloader-doesn-t-load-application-on-power-on/80742#80742 + NRFX_DELAY_MS(20); + /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ // DFU button pressed dfu_start = dfu_start || button_pressed(BUTTON_DFU); From 4582f7304a1f4383932c897f336fd0926d288ff1 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 14 Oct 2020 16:26:15 +0800 Subject: [PATCH 14/16] first cut of Othernet PPR1 bootloader --- src/boards/boards.c | 5 ++ src/boards/othernet_ppr1/board.h | 69 ++++++++++++++++++++++++++++ src/boards/othernet_ppr1/board.mk | 1 + src/boards/othernet_ppr1/pinconfig.c | 22 +++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/boards/othernet_ppr1/board.h create mode 100644 src/boards/othernet_ppr1/board.mk create mode 100644 src/boards/othernet_ppr1/pinconfig.c diff --git a/src/boards/boards.c b/src/boards/boards.c index 99e8aa73..c948d93e 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -71,6 +71,11 @@ void board_init(void) NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC; NRF_CLOCK->TASKS_LFCLKSTART = 1UL; +#ifdef FORCE_HIGH + nrf_gpio_cfg_output(FORCE_HIGH); + nrf_gpio_pin_write(FORCE_HIGH, 1); +#endif + button_init(BUTTON_DFU); button_init(BUTTON_FRESET); NRFX_DELAY_US(100); // wait for the pin state is stable diff --git a/src/boards/othernet_ppr1/board.h b/src/boards/othernet_ppr1/board.h new file mode 100644 index 00000000..f83f323e --- /dev/null +++ b/src/boards/othernet_ppr1/board.h @@ -0,0 +1,69 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef OTHERNET_PPR1_H +#define OTHERNET_PPR1_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 25 // green +#define LED_SECONDARY_PIN 11 // red +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 5 +#define BUTTON_1 (2) +#define BUTTON_2 (3) +#define BUTTON_3 (4) +#define BUTTON_4 (5) +#define BUTTON_5 (6) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/// This is VUSB_EN, we need it forced high to power VBUS_nRF (hw bug) +#define FORCE_HIGH 21 + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "othernet" +#define BLEDIS_MODEL "ppr1" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 + +#define UF2_PRODUCT_NAME "PPR1" +#define UF2_VOLUME_LABEL "PPR1Boot " +#define UF2_BOARD_ID "othernet-ppr1" +#define UF2_INDEX_URL "https://othernet.is/ppr1" + +#endif diff --git a/src/boards/othernet_ppr1/board.mk b/src/boards/othernet_ppr1/board.mk new file mode 100644 index 00000000..d60ac481 --- /dev/null +++ b/src/boards/othernet_ppr1/board.mk @@ -0,0 +1 @@ +MCU_SUB_VARIANT = nrf52833 diff --git a/src/boards/othernet_ppr1/pinconfig.c b/src/boards/othernet_ppr1/pinconfig.c new file mode 100644 index 00000000..21aa08fa --- /dev/null +++ b/src/boards/othernet_ppr1/pinconfig.c @@ -0,0 +1,22 @@ +#include "boards.h" +#include "uf2/configkeys.h" + +__attribute__((used, section(".bootloaderConfig"))) +const uint32_t bootloaderConfig[] = + { + /* CF2 START */ + CFG_MAGIC0, CFG_MAGIC1, // magic + 5, 100, // used entries, total entries + + 204, 0x80000, // FLASH_BYTES = 0x100000 + 205, 0x20000, // RAM_BYTES = 0x40000 + 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, 0xada52840, // UF2_FAMILY = 0xada52840 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + + 0, 0, 0, 0, 0, 0, 0, 0 + /* CF2 END */ +}; + +// We want output pin voltages to be 3.3V +__attribute__((section(".uicrREGOUT0"))) volatile uint32_t m_uicr_regout0 = 0xfffffff5; \ No newline at end of file From f38f8f43c052ee14f60afd6373c3276501ea7c06 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 16 Oct 2020 07:22:16 +0800 Subject: [PATCH 15/16] Reenable using P0.18 as RESET on all boards --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52a8b40b..6ffde77a 100644 --- a/Makefile +++ b/Makefile @@ -251,7 +251,7 @@ CFLAGS += -Wno-cast-function-type CFLAGS += -D__HEAP_SIZE=0 # We don't want this on all boards -# CFLAGS += -DCONFIG_GPIO_AS_PINRESET +CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 From dd3e0e7be051f8e7a2fb1e3870b6d8cac23e0fdf Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 16 Oct 2020 07:39:36 +0800 Subject: [PATCH 16/16] allow 200ms for caps to charge up to prevent false button readings --- src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 51c71631..b3a41f38 100644 --- a/src/main.c +++ b/src/main.c @@ -197,10 +197,10 @@ int main(void) led_state(STATE_WRITING_FINISHED); } - // Delay 20ms so that the button capacitors can charge up before - // reading the buttons. Avoids: + // Delay 200ms so that the button capacitors can charge up before + // reading the buttons. (100ms was not enough) Avoids: // https://devzone.nordicsemi.com/f/nordic-q-a/20698/bootloader-doesn-t-load-application-on-power-on/80742#80742 - NRFX_DELAY_MS(20); + NRFX_DELAY_MS(200); /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ // DFU button pressed