diff --git a/.gitmodules b/.gitmodules index bd80adc1..bc871869 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "lib/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/Makefile b/Makefile index 9ea2c887..6d660c06 100644 --- a/Makefile +++ b/Makefile @@ -295,6 +295,8 @@ endif # Defined Symbol (MACROS) CFLAGS += -D__HEAP_SIZE=0 + +# We don't want this on all boards CFLAGS += -DCONFIG_GPIO_AS_PINRESET # Skip defining CONFIG_NFCT_PINS_AS_GPIOS if the device uses the NFCT. 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 9775e769..15397b96 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 9775e76910d569ec73b8dd946f3fa5fe5414acdb +Subproject commit 15397b9656f2dd2ebe5529afd4a9f8cfc4dc12fb 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 5eec85ed..954ed180 100644 --- a/linker/nrf52840.ld +++ b/linker/nrf52840.ld @@ -41,6 +41,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 @@ -81,6 +91,12 @@ SECTIONS KEEP(*(.uicrMbrParamsPageAddress)) } > UICR_MBR_PARAM_PAGE + /* Write REGOUT0 in UICR. */ + .uicrREGOUT0 : + { + KEEP(*(.uicrREGOUT0)) + } > UICR_REGOUT0 + .dbl_reset(NOLOAD) : { diff --git a/src/boards/boards.c b/src/boards/boards.c index 7a48259a..b409548e 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -43,6 +43,10 @@ void neopixel_teardown(void); #endif +#ifndef BUTTON_SENSE +#define BUTTON_SENSE BUTTON_PULL +#endif + //------------- IMPLEMENTATION -------------// void button_init(uint32_t pin) { @@ -58,7 +62,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; } @@ -71,6 +75,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_ppr/board.h b/src/boards/othernet_ppr/board.h new file mode 100644 index 00000000..1a496490 --- /dev/null +++ b/src/boards/othernet_ppr/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 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 // really should be NOPULL but the bootloader code only + // checks for PULLUP vs PULLDOWN + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Othernet" +#define BLEDIS_MODEL "PPR" + +//--------------------------------------------------------------------+ +// 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" +#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 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; 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 diff --git a/src/boards/rak815/board.h b/src/boards/rak815/board.h new file mode 100644 index 00000000..a2f7df4c --- /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 2 +#define LED_PRIMARY_PIN 25 +#define LED_SECONDARY_PIN 26 +#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 diff --git a/src/boards/ttgo_eink/board.h b/src/boards/ttgo_eink/board.h new file mode 100644 index 00000000..4372771e --- /dev/null +++ b/src/boards/ttgo_eink/board.h @@ -0,0 +1,64 @@ +/* + * 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 // red +#define LED_SECONDARY_PIN 15 // blue +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#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 +//--------------------------------------------------------------------+ +#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