diff --git a/.travis.yml b/.travis.yml index 6cfa869b03..654a3d9cb2 100755 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ git: # that SDK is shortest and add it there. In the case of major re-organizations, # just try to make the builds "about equal in run time" env: - - TRAVIS_TESTS="unix docs translations" TRAVIS_BOARDS="feather_huzzah circuitplayground_express pca10056 pca10059 feather_nrf52832 feather_nrf52840_express" TRAVIS_SDK=arm:nrf:esp8266 + - TRAVIS_TESTS="unix docs translations" TRAVIS_BOARDS="feather_huzzah circuitplayground_express pca10056 pca10059 feather_nrf52832 feather_nrf52840_express makerdiary_nrf52840_mdk" TRAVIS_SDK=arm:nrf:esp8266 - TRAVIS_BOARDS="metro_m0_express metro_m4_express pirkey_m0 trellis_m4_express trinket_m0" TRAVIS_SDK=arm - TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow" TRAVIS_SDK=arm - TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero" TRAVIS_SDK=arm diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 8b84f43df4..a1a6a4d35c 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -300,16 +300,16 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex else ifeq ($(FLASHER), pyocd) flash: $(BUILD)/$(OUTPUT_FILENAME).hex - pyocd-flashtool -t $(MCU_SUB_VARIANT) $< --sector_erase - pyocd-tool -t $(MCU_SUB_VARIANT) erase $(BOOT_SETTING_ADDR) - pyocd-tool -t $(MCU_SUB_VARIANT) write32 $(BOOT_SETTING_ADDR) 0x00000001 - pyocd-tool -t $(MCU_SUB_VARIANT) reset + pyocd-flashtool -t $(MCU_VARIANT) $< --sector_erase + #pyocd-tool -t $(MCU_VARIANT) erase $(BOOT_SETTING_ADDR) + pyocd-tool -t $(MCU_VARIANT) write32 $(BOOT_SETTING_ADDR) 0x00000001 + pyocd-tool -t $(MCU_VARIANT) reset sd: $(BUILD)/$(OUTPUT_FILENAME).hex - pyocd-flashtool -t $(MCU_SUB_VARIANT) --chip_erase - pyocd-flashtool -t $(MCU_SUB_VARIANT) $(SOFTDEV_HEX) - pyocd-flashtool -t $(MCU_SUB_VARIANT) $< --sector_erase - pyocd-tool -t $(MCU_SUB_VARIANT) reset $(BOOT_SETTING_ADDR) + pyocd-flashtool -t $(MCU_VARIANT) --chip_erase + pyocd-flashtool -t $(MCU_VARIANT) $(SOFTDEV_HEX) + pyocd-flashtool -t $(MCU_VARIANT) $< --sector_erase + pyocd-tool -t $(MCU_VARIANT) reset $(BOOT_SETTING_ADDR) endif diff --git a/ports/nrf/README.md b/ports/nrf/README.md index c21bd5d63b..4bd865400b 100644 --- a/ports/nrf/README.md +++ b/ports/nrf/README.md @@ -39,6 +39,7 @@ the following links: * Adafruit [Feather nRF52](boards/feather_nrf52832/README.md): 512KB Flash, 64KB SRAM * Adafruit [Feather nRF52840](boards/feather_nrf52840_express/README.md): 1MB Flash, 256KB SRAM * Nordic PCA10056 see [Feather nRF52840](boards/pca10056/README.md) +* MakerDiary NRF52840 MDK see [its README](boards/makerdiary_nrf52840_mdk/README.md) For all other board targets, see the generic notes below. @@ -80,6 +81,7 @@ pca10040 | s132 | Peripheral and Scanner | [S pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets) feather_nrf52832 | s132 | Peripheral and Scanner | [UART DFU](#dfu-targets) feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader +makerdiary_nrf52840_mdk | s140 | Peripheral and Scanner | pyocd or ARM mbed DAPLink ## Segger Targets diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/README.md b/ports/nrf/boards/makerdiary_nrf52840_mdk/README.md new file mode 100644 index 0000000000..f1ba8151ac --- /dev/null +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/README.md @@ -0,0 +1,102 @@ +# MakerDiary NRF52840 MDK + +Refer to https://github.com/makerdiary/nrf52840-mdk or +https://wiki.makerdiary.com/nrf52840-mdk/ for more details about the device. + +Notably, CircuitPython does not currently support QSPI external flash on NRF +devices, so neither does this port - the 64Mb flash device is not used for +anything. Also, don't confuse this with the 64MiB drive that shows up on your +computer - it's actually part of the MSC driver provided by the DAPLink +debugger, and is inaccessible at all from Python land (this drive is where you +can copy `firmware.hex` if you'd prefer to flash that way as opposed to with +`pyocd`. You'll still have access to 256KB of the onboard flash, however, for +storing your Python files, cat pictures, or whatever. + +It's also interesting to note that all three LEDs and the "user button" on this +device are wired through sinks, not sources, so flip your boolean expectations +when dealing with `digitalio.DigitalInOut` on this device - `my_led.value = +True` turns the LED off! Likewise, the user button will read `False` when +pressed. + +## Installing CircuitPython submodules + +Before you can build, you will need to run the following commands once, which +will install the submodules that are part of the CircuitPython ecosystem, and +build the `mpy-cross` tool: + +``` +$ cd circuitpython +$ git submodule update --init +$ make -C mpy-cross +``` + +You then need to download the SD and Nordic SDK files via: + +> This script relies on `wget`, which must be available from the command line. + +``` +$ cd ports/nrf +$ ./drivers/bluetooth/download_ble_stack.sh +``` + +## Note about bootloaders + +While most Adafruit devices come with (or can easily be flashed with) an +Adafruit-provided bootloader (supporting niceties like UF2 flashing), this +board comes with DAPLink which (apparently?) handles everything from debugging +to programming the device, as well as the boot sequence. What's particularly +awesome about this board is that there is no physical interaction with the board +required to flash new code (read: CircuitPython builds) - the device is _always_ +listening for new firmware uploads (via `pyocd-flashtool`), even if userspace +code is running. + +## Building and Flashing CircuitPython + +You'll need to have [pyocd](https://github.com/mbedmicro/pyOCD) installed as +appropriate for your system. + +```sh +make BOARD=makerdiary_nrf52840_mdk FLASHER=pyocd SD=s140 flash +``` + +This should give you the following (or very similar) output, and you will see +a DFU blinky pattern on one of the board LEDs: + +``` +$ make BOARD=makerdiary_nrf52840_mdk FLASHER=pyocd SD=s140 flash +Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity. +pyocd-flashtool -t nrf52 build-makerdiary_nrf52840_mdk-s140/firmware.hex --sector_erase +INFO:root:DAP SWD MODE initialised +INFO:root:ROM table #0 @ 0xe00ff000 cidr=b105100d pidr=2002c4008 +INFO:root:[0] +WARNING:root:Invalid coresight component, cidr=0x0 +INFO:root:[1] +INFO:root:[2] +WARNING:root:Invalid coresight component, cidr=0x1010101 +INFO:root:[3] +WARNING:root:Invalid coresight component, cidr=0x0 +INFO:root:[4] +INFO:root:[5] +INFO:root:CPU core is Cortex-M4 +INFO:root:FPU present +INFO:root:6 hardware breakpoints, 4 literal comparators +INFO:root:4 hardware watchpoints +[====================] 100% +INFO:root:Programmed 237568 bytes (58 pages) at 14.28 kB/s +#pyocd-tool -t nrf52 erase 0xFF000 +pyocd-tool -t nrf52 write32 0xFF000 0x00000001 +WARNING:root:Invalid coresight component, cidr=0x0 +WARNING:root:Invalid coresight component, cidr=0x1010101 +WARNING:root:Invalid coresight component, cidr=0x0 +pyocd-tool -t nrf52 reset +WARNING:root:Invalid coresight component, cidr=0x0 +WARNING:root:Invalid coresight component, cidr=0x1010101 +WARNING:root:Invalid coresight component, cidr=0x0 +Resetting target +``` + +Alternatively (and untested by me), it's apparently possible to copy +`firmware.hex` to the MSC device provided by DAPLink and flash that way. Refer +to [the upstream +documentation](https://wiki.makerdiary.com/nrf52840-mdk/getting-started/#drag-n-drop-programming) +for details. diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/board.c b/ports/nrf/boards/makerdiary_nrf52840_mdk/board.c new file mode 100644 index 0000000000..a6d050fce2 --- /dev/null +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft 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. + */ + +#include "boards/board.h" +#include "usb.h" + +void board_init(void) { + usb_init(); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.h b/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.h new file mode 100644 index 0000000000..b33fb2dd62 --- /dev/null +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.h @@ -0,0 +1,64 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert 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. + */ + +#define MAKERDIARYNRF52840MDK + +#define MICROPY_HW_BOARD_NAME "MakerDiary nRF52840 MDK" +#define MICROPY_HW_MCU_NAME "nRF52840" +#define MICROPY_PY_SYS_PLATFORM "MakerDiary52840MDK" + +#define MICROPY_QSPI_DATA0 (&pin_P1_05) +#define MICROPY_QSPI_DATA1 (&pin_P1_04) +#define MICROPY_QSPI_DATA2 (&pin_P1_02) +#define MICROPY_QSPI_DATA3 (&pin_P1_01) +#define MICROPY_QSPI_SCK (&pin_P1_03) +#define MICROPY_QSPI_CS (&pin_P1_06) + +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code +#define PORT_HEAP_SIZE (128 * 1024) +// TODO #define CIRCUITPY_INTERNAL_NVM_SIZE 8192 + +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +// TODO #include "external_flash/devices.h" + +#define EXTERNAL_FLASH_DEVICE_COUNT 1 +// Datasheet for when this is implemented: +// http://www.mxic.com.tw/Lists/Datasheet/Attachments/7428/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf +#define EXTERNAL_FLASH_DEVICES MX25R6435F + +#define EXTERNAL_FLASH_QSPI_DUAL + +// TODO include "external_flash/external_flash.h" + +#define BOARD_HAS_CRYSTAL 0 + +#define DEFAULT_UART_BUS_RX (&pin_P0_19) +#define DEFAULT_UART_BUS_TX (&pin_P0_20) diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.mk b/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.mk new file mode 100644 index 0000000000..caf580ec4d --- /dev/null +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/mpconfigboard.mk @@ -0,0 +1,16 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52840 +MCU_CHIP = nrf52840 +SD ?= s140 +SOFTDEV_VERSION ?= 6.1.0 + +BOOT_SETTING_ADDR = 0xFF000 + +ifeq ($(SD),) + LD_FILE = boards/nrf52840_1M_256k.ld +else + LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld +endif + +NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 diff --git a/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c b/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c new file mode 100644 index 0000000000..27f0c67974 --- /dev/null +++ b/ports/nrf/boards/makerdiary_nrf52840_mdk/pins.c @@ -0,0 +1,63 @@ +#include "shared-bindings/board/__init__.h" + +#include "board_busses.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_AIN2), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_AIN3), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_AIN4), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_AIN5), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_AIN6), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_AIN7), MP_ROM_PTR(&pin_P0_31) }, + + { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) }, + + { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, + + { MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P8), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P9), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_P11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_P12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_P13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_P14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_P15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_P16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_P17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_P21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_P25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_P26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_P27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_P28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_P29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_P30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_P31), MP_ROM_PTR(&pin_P0_31) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_CSN), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_P1_01) }, + + { MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_P0_19) }, + + { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_24) }, + + { MP_ROM_QSTR(MP_QSTR_USR_BTN), MP_ROM_PTR(&pin_P1_00) }, +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/tools/build_adafruit_bins.sh b/tools/build_adafruit_bins.sh index 291a1d46e3..51a8778cc0 100755 --- a/tools/build_adafruit_bins.sh +++ b/tools/build_adafruit_bins.sh @@ -25,6 +25,7 @@ grandcentral_m4_express \ hallowing_m0_express \ itsybitsy_m0_express \ itsybitsy_m4_express \ +makerdiary_nrf52840_mdk \ metro_m0_express \ metro_m4_express \ meowmeow \ @@ -82,6 +83,11 @@ for board in $boards; do (( exit_status = exit_status || $? )) temp_filename=ports/nrf/build-$board-s140/firmware.uf2 extension=uf2 + elif [[ $board == "makerdiary_nrf52840_mdk" ]]; then + make $PARALLEL -C ports/nrf TRANSLATION=$language BOARD=$board SD=s140 + (( exit_status = exit_status || $? )) + temp_filename=ports/nrf/build-$board-s140/firmware.hex + extension=hex else time make $PARALLEL -C ports/atmel-samd TRANSLATION=$language BOARD=$board (( exit_status = exit_status || $? ))