From 05547b72ac088764d0d96d3e7121069474f4ff8c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 18 Jun 2018 10:51:04 -0700 Subject: Switch to Feather52s full name to avoid confusion with the nrf52840 later. Fixes #940 --- .travis.yml | 2 +- ports/nrf/boards/feather52/README.md | 196 --------------------- ports/nrf/boards/feather52/board.c | 71 -------- .../nrf/boards/feather52/bootloader/.gitattributes | 2 - ports/nrf/boards/feather52/bootloader/README.md | 9 - .../feather52_bootloader_2.0.1_s132_single.zip | Bin 131786 -> 0 bytes .../feather52_bootloader_5.0.0_s132_single.zip | Bin 159962 -> 0 bytes .../feather52/custom_nrf52832_dfu_app_2.0.1.ld | 44 ----- .../feather52/custom_nrf52832_dfu_app_5.0.0.ld | 44 ----- ports/nrf/boards/feather52/examples/ble_scan.py | 26 --- ports/nrf/boards/feather52/examples/blinky.py | 12 -- ports/nrf/boards/feather52/examples/i2c_scan.py | 20 --- ports/nrf/boards/feather52/examples/pulseio.py | 25 --- ports/nrf/boards/feather52/mpconfigboard.h | 79 --------- ports/nrf/boards/feather52/mpconfigboard.mk | 42 ----- ports/nrf/boards/feather52/mpconfigboard_s132.mk | 4 - ports/nrf/boards/feather52/nrf52_hal_conf.h | 18 -- ports/nrf/boards/feather52/pins.csv | 24 --- ports/nrf/boards/feather52832/README.md | 196 +++++++++++++++++++++ ports/nrf/boards/feather52832/board.c | 71 ++++++++ .../boards/feather52832/bootloader/.gitattributes | 2 + ports/nrf/boards/feather52832/bootloader/README.md | 9 + .../feather52_bootloader_2.0.1_s132_single.zip | Bin 0 -> 131786 bytes .../feather52_bootloader_5.0.0_s132_single.zip | Bin 0 -> 159962 bytes .../feather52832/custom_nrf52832_dfu_app_2.0.1.ld | 44 +++++ .../feather52832/custom_nrf52832_dfu_app_5.0.0.ld | 44 +++++ ports/nrf/boards/feather52832/examples/ble_scan.py | 26 +++ ports/nrf/boards/feather52832/examples/blinky.py | 12 ++ ports/nrf/boards/feather52832/examples/i2c_scan.py | 20 +++ ports/nrf/boards/feather52832/examples/pulseio.py | 25 +++ ports/nrf/boards/feather52832/mpconfigboard.h | 79 +++++++++ ports/nrf/boards/feather52832/mpconfigboard.mk | 42 +++++ .../nrf/boards/feather52832/mpconfigboard_s132.mk | 4 + ports/nrf/boards/feather52832/nrf52_hal_conf.h | 18 ++ ports/nrf/boards/feather52832/pins.csv | 24 +++ tools/build_adafruit_bins.sh | 4 +- 36 files changed, 619 insertions(+), 619 deletions(-) delete mode 100644 ports/nrf/boards/feather52/README.md delete mode 100644 ports/nrf/boards/feather52/board.c delete mode 100644 ports/nrf/boards/feather52/bootloader/.gitattributes delete mode 100644 ports/nrf/boards/feather52/bootloader/README.md delete mode 100644 ports/nrf/boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip delete mode 100644 ports/nrf/boards/feather52/bootloader/feather52_bootloader_5.0.0_s132_single.zip delete mode 100644 ports/nrf/boards/feather52/custom_nrf52832_dfu_app_2.0.1.ld delete mode 100644 ports/nrf/boards/feather52/custom_nrf52832_dfu_app_5.0.0.ld delete mode 100644 ports/nrf/boards/feather52/examples/ble_scan.py delete mode 100644 ports/nrf/boards/feather52/examples/blinky.py delete mode 100644 ports/nrf/boards/feather52/examples/i2c_scan.py delete mode 100644 ports/nrf/boards/feather52/examples/pulseio.py delete mode 100644 ports/nrf/boards/feather52/mpconfigboard.h delete mode 100644 ports/nrf/boards/feather52/mpconfigboard.mk delete mode 100644 ports/nrf/boards/feather52/mpconfigboard_s132.mk delete mode 100644 ports/nrf/boards/feather52/nrf52_hal_conf.h delete mode 100644 ports/nrf/boards/feather52/pins.csv create mode 100644 ports/nrf/boards/feather52832/README.md create mode 100644 ports/nrf/boards/feather52832/board.c create mode 100644 ports/nrf/boards/feather52832/bootloader/.gitattributes create mode 100644 ports/nrf/boards/feather52832/bootloader/README.md create mode 100644 ports/nrf/boards/feather52832/bootloader/feather52_bootloader_2.0.1_s132_single.zip create mode 100644 ports/nrf/boards/feather52832/bootloader/feather52_bootloader_5.0.0_s132_single.zip create mode 100644 ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld create mode 100644 ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld create mode 100644 ports/nrf/boards/feather52832/examples/ble_scan.py create mode 100644 ports/nrf/boards/feather52832/examples/blinky.py create mode 100644 ports/nrf/boards/feather52832/examples/i2c_scan.py create mode 100644 ports/nrf/boards/feather52832/examples/pulseio.py create mode 100644 ports/nrf/boards/feather52832/mpconfigboard.h create mode 100644 ports/nrf/boards/feather52832/mpconfigboard.mk create mode 100644 ports/nrf/boards/feather52832/mpconfigboard_s132.mk create mode 100644 ports/nrf/boards/feather52832/nrf52_hal_conf.h create mode 100644 ports/nrf/boards/feather52832/pins.csv diff --git a/.travis.yml b/.travis.yml index 71ed26ff6..badd78b4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: - TRAVIS_BOARD=pirkey_m0 - TRAVIS_BOARD=trinket_m0 - TRAVIS_BOARD=gemma_m0 - - TRAVIS_BOARD=feather52 + - TRAVIS_BOARD=feather52832 - TRAVIS_BOARD=pca10056 - TRAVIS_TEST=qemu - TRAVIS_TEST=unix diff --git a/ports/nrf/boards/feather52/README.md b/ports/nrf/boards/feather52/README.md deleted file mode 100644 index c98f54614..000000000 --- a/ports/nrf/boards/feather52/README.md +++ /dev/null @@ -1,196 +0,0 @@ -# Setup - -## 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 -``` - -## Installing `nrfutil` - -The Adafruit Bluefruit nRF52 Feather ships with a serial and OTA BLE bootloader -that can be used to flash firmware images over a simple serial connection, -using the on-board USB serial converter. - -If you haven't installed this command-line tool yet, go to the `/libs/nrfutil` -folder (where nrfutil 0.5.2 is installed as a sub-module) and run the following -commands: - -> If you get a 'sudo: pip: command not found' error running 'sudo pip install', -you can install pip via 'sudo easy_install pip' - -``` -$ cd ../../lib/nrfutil -$ sudo pip install -r requirements.txt -$ sudo python setup.py install -``` - -# Building and flashing firmware images - -## Building CircuitPython binaries - -#### REPL over UART (default settings) - -To build a CircuitPython binary with default settings for the -`feather52` target enter: - -> **NOTE:** `BOARD=feather52` is the default option and isn't stricly required. - -``` -$ make BOARD=feather52 V=1 -``` - -#### REPL over BLE UART (AKA 'NUS') - -To build a CircuitPython binary that uses the Nordic UART Service (AKA 'NUS' or -'BLEUART'), modify `/ports/nrf/bluetooth_conf.h` to have the following macro -set to `1` in the `#elif (BLUETOOTH_SD == 132)` section: - -``` -#define MICROPY_PY_BLE_NUS (1) -``` - -... then build as normal, via: - -``` -$ make BOARD=feather52 V=1 -``` - -You can then connect over BLE UART using an application like Bluefruit LE -Connect, available for Android, iOS and OS X, or any other application that -supports the NUS service and allows you to send the corrent EOL sequence. - -## Flashing binaries with `nrfutil` - -### 1. **Update bootloader** to single-bank version - -The Adafruit nRF52 Feather ships, by default, with a **dual-bank** bootloader -that cuts the available flash memory in half in exchange for safer -OTA updates. - -Due to the size of CircuitPython, we must migrate this bootloader to a -**single-bank** version, doubling the amount of flash memory available to us. - -> These commands only need to be run once and will update the SoftDevice and -bootloader from the dual-bank version that ships on Arduino-based Adafruit -Feather52 boards to a single-bank CircuitPython compatible version: - -#### S132 v2.0.1 single-bank (recommended): - -By default s132 v2.0.1 is used when no `SOFTDEV_VERSION` field is passed in: - -``` -$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART boot-flash -``` - -#### S132 v5.0.0 (BLE5, experimental): - -To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader via: - -``` -$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash -``` - -### 2. Generate and flash a CircuitPython DFU .zip package over serial - -The following command will package and flash the CircuitPython binary using the -appropriate bootloader mentionned above. - -This command assumes you have already built a valid circuitpython -image, as described earlier in this readme. - -> The name of the serial port target will vary, depending on your OS. - -``` -$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash -``` - -By default, CircuitPython will build with **BLE** support enabled using -`SD=s132` and the `SOFTDEV_VERSION=2.0.1`. If you wish to specify a different -SD family or version you can enter the optional fields as shown below: - -``` -$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 SOFTDEV_VERSION=5.0.0 dfu-gen dfu-flash -``` - -## Working with CircuitPython - -### Running local files with `ampy` - -[ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy) -is a command-line tool that can be used with the nRF52 Feather to transfer -local python files to the nRF52 for execution, rather than having to enter -the REPL manually, enter paste mode, and paste the code yourself. - -> **IMPORTANT**: You must have `ampy` version **1.0.3** or higher to use `ampy` - with the nRF52. The bootloader on the nRF52 requires a delay between the - HW reset, and the moment when the command sequance is sent to enter raw - mode. This required `-d/--delay` flag was added in release 1.0.3. - - -Save the following file as `test.py`: - -``` -import board -import digitalio -import time - -led = digitalio.DigitalInOut(board.LED2) -led.direction = digitalio.Direction.OUTPUT - -while True: - led.value = True - time.sleep(0.5) - led.value = False - time.sleep(0.5) -``` - -Then run the saved file via ampy, updating the serial port as required: - -``` -$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 run test.py -``` - -This should give you blinky at 1 Hz on LED2 (the blue LED on the nRF52 Feather). - -### Uploading files and libraries with `ampy` - -To upload Python files or pre-compiled CircuitPython libraries to the `lib` folder, -run the following commands: - -> In this example **i2c_device.py** is used, which is part of - [Adafruit_CircuitPython_BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) - -``` -$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 put i2c_device.py lib/i2c_device.py -``` - -To verify that the file was uploaded correctly, you can check the contents of -the `lib` folder with: - -``` -$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 ls /lib -i2c_device.py -``` - -### Suggested libraries - -The following libraries should be installed as a minimum on most new boards: - -- [Adafruit_CircuitPython_BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) -- [Adafruit_CircuitPython_Register](https://github.com/adafruit/Adafruit_CircuitPython_Register/tree/master) diff --git a/ports/nrf/boards/feather52/board.c b/ports/nrf/boards/feather52/board.c deleted file mode 100644 index e0b77437b..000000000 --- a/ports/nrf/boards/feather52/board.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 -#include - -#include "nrf.h" - -#include "boards/board.h" - -// Must match temp register in bootloader -#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] -uint32_t bootloaderVersion = 0; - -void board_init(void) { - // Retrieve bootloader version - bootloaderVersion = BOOTLOADER_VERSION_REGISTER; -} - -// Check the status of the two buttons on CircuitPlayground Express. If both are -// pressed, then boot into user safe mode. -bool board_requests_safe_mode(void) { -// gpio_set_pin_function(PIN_PA14, GPIO_PIN_FUNCTION_OFF); -// gpio_set_pin_direction(PIN_PA14, GPIO_DIRECTION_IN); -// gpio_set_pin_pull_mode(PIN_PA14, GPIO_PULL_DOWN); -// -// gpio_set_pin_function(PIN_PA28, GPIO_PIN_FUNCTION_OFF); -// gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_IN); -// gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN); -// bool safe_mode = gpio_get_pin_level(PIN_PA14) && -// gpio_get_pin_level(PIN_PA28); -// reset_pin(PIN_PA14); -// reset_pin(PIN_PA28); -// return safe_mode; - - return false; -} - -void reset_board(void) { -// uint8_t empty[30]; -// memset(empty, 0, 30); -// digitalio_digitalinout_obj_t neopixel_pin; -// common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23); -// common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false, -// DRIVE_MODE_PUSH_PULL); -// common_hal_neopixel_write(&neopixel_pin, empty, 30); -// common_hal_digitalio_digitalinout_deinit(&neopixel_pin); -} diff --git a/ports/nrf/boards/feather52/bootloader/.gitattributes b/ports/nrf/boards/feather52/bootloader/.gitattributes deleted file mode 100644 index 608f8c345..000000000 --- a/ports/nrf/boards/feather52/bootloader/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Inform git that .zip files should be treated as binary -*.zip binary diff --git a/ports/nrf/boards/feather52/bootloader/README.md b/ports/nrf/boards/feather52/bootloader/README.md deleted file mode 100644 index 434859085..000000000 --- a/ports/nrf/boards/feather52/bootloader/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Adafruit nRF52 Feather Single-Bank Bootloader - -These files contain an implementation of a single-bank bootloader, -which doubles the amount of flash memory available to applications -at the expense of safe over the air updates. - -Two versions are present, based on release **2.0.1** and **5.0.0** -of the Nordic S132 SoftDevice. The SoftDevice is included as poart -of the bootloader binary. diff --git a/ports/nrf/boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip b/ports/nrf/boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip deleted file mode 100644 index 42a83bb90..000000000 Binary files a/ports/nrf/boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip and /dev/null differ diff --git a/ports/nrf/boards/feather52/bootloader/feather52_bootloader_5.0.0_s132_single.zip b/ports/nrf/boards/feather52/bootloader/feather52_bootloader_5.0.0_s132_single.zip deleted file mode 100644 index 2f30a9fd4..000000000 Binary files a/ports/nrf/boards/feather52/bootloader/feather52_bootloader_5.0.0_s132_single.zip and /dev/null differ diff --git a/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_2.0.1.ld b/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_2.0.1.ld deleted file mode 100644 index a1c128e37..000000000 --- a/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_2.0.1.ld +++ /dev/null @@ -1,44 +0,0 @@ -/* - GNU linker script for NRF52 w/ s132 2.0.1 SoftDevice - - MEMORY MAP - ------------------------------------------------------------------------ - START ADDR END ADDR SIZE DESCRIPTION - ---------- ---------- ------- ----------------------------------------- - 0x0007F000..0x0007FFFF ( 4KB) Bootloader Settings - 0x0007E000..0x0007EFFF ( 4KB) Master Boot Record Params - 0x00074000..0x0007DFFF ( 40KB) Serial + OTA Bootloader - - 0x00073000..0x00073FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.) - 0x00072000..0x00072FFF ( 4KB ) User NVM data - 0x00059000..0x00071FFF (100KB) User Filesystem - - 0x0001C000..0x00058FFF (244KB) Application Code - 0x00001000..0x0001BFFF (108KB) SoftDevice - 0x00000000..0x00000FFF (4KB) Master Boot Record -*/ - -/* Specify the memory areas (S132 2.0.1) */ -MEMORY -{ - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */ - FLASH_ISR (rx) : ORIGIN = 0x0001c000, LENGTH = 0x001000 /* sector 0, 4 KiB */ - FLASH_TEXT (rx) : ORIGIN = 0x0001d000, LENGTH = 0x03C000 /* APP - ISR, 240 KiB */ - FLASH_FATFS (r) : ORIGIN = 0x00059000, LENGTH = 0x019000 /* File system 100KB KB */ - RAM (xrw) : ORIGIN = 0x20003000, LENGTH = 0x0D000 /* 52 KiB, give 8KiB headroom for softdevice */ -} - -/* produce a link error if there is not this amount of RAM for these sections */ -_minimum_stack_size = 2K; -_minimum_heap_size = 0 /*16K Circuit Python use static variable for HEAP */; - -/* top end of the stack */ - -/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/ -_estack = ORIGIN(RAM) + LENGTH(RAM); - -/* RAM extents for the garbage collector */ -_ram_end = ORIGIN(RAM) + LENGTH(RAM); -_heap_end = 0x20007000; /* tunable */ - -INCLUDE "boards/common.ld" diff --git a/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_5.0.0.ld b/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_5.0.0.ld deleted file mode 100644 index f9209bf3d..000000000 --- a/ports/nrf/boards/feather52/custom_nrf52832_dfu_app_5.0.0.ld +++ /dev/null @@ -1,44 +0,0 @@ -/* - GNU linker script for NRF52 w/ s132 5.0.0 SoftDevice - - MEMORY MAP - ------------------------------------------------------------------------ - START ADDR END ADDR SIZE DESCRIPTION - ---------- ---------- ------- ----------------------------------------- - 0x0007F000..0x0007FFFF ( 4KB) Bootloader Settings - 0x0007E000..0x0007EFFF ( 4KB) Master Boot Record Params - 0x00074000..0x0007DFFF ( 40KB) Serial + OTA Bootloader - - 0x00073000..0x00073FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.) - 0x00072000..0x00072FFF ( 4KB ) User NVM data - 0x00059000..0x00071FFF ( 100KB) User Filesystem - - 0x00023000..0x00058FFF (216KB) Application Code - 0x00001000..0x00022FFF (136KB) SoftDevice - 0x00000000..0x00000FFF (4KB) Master Boot Record -*/ - -/* Specify the memory areas (S132 5.0.0) */ -MEMORY -{ - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */ - FLASH_ISR (rx) : ORIGIN = 0x00023000, LENGTH = 0x001000 /* sector 0, 4 KiB */ - FLASH_TEXT (rx) : ORIGIN = 0x00024000, LENGTH = 0x036000 /* APP - ISR, 216 KiB */ - FLASH_FATFS (r) : ORIGIN = 0x00059000, LENGTH = 0x019000 /* File system 100KB KB */ - RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */ -} - -/* produce a link error if there is not this amount of RAM for these sections */ -_minimum_stack_size = 2K; -_minimum_heap_size = 0 /*16K Circuit Python use static variable for HEAP */; - -/* top end of the stack */ - -/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/ -_estack = ORIGIN(RAM) + LENGTH(RAM); - -/* RAM extents for the garbage collector */ -_ram_end = ORIGIN(RAM) + LENGTH(RAM); -_heap_end = 0x20007000; /* tunable */ - -INCLUDE "boards/common.ld" diff --git a/ports/nrf/boards/feather52/examples/ble_scan.py b/ports/nrf/boards/feather52/examples/ble_scan.py deleted file mode 100644 index 9cacbe6f4..000000000 --- a/ports/nrf/boards/feather52/examples/ble_scan.py +++ /dev/null @@ -1,26 +0,0 @@ -from ubluepy import Scanner, constants - -def display_scan_results(scan_entries): - for e in scan_entries: - print("ADDR: ", e.addr()) - print("TYPE: ", e.addr_type()) - print("RSSI: ", e.rssi()) - - # Parse the contents of the advertising packet - scan = e.getScanData() - if scan: - for s in scan: - # Convert byte array to hex format string - hex = ' '.join('0x%02X' % b for b in s[2]) - # Display enum value and hex string together - print('\t{}: {}'.format(s[1], hex)) - - # Line break between record sets - print("") - -# Scan 1s for advertising devices in range -s = Scanner() -scan_res = s.scan(1000) - -# Display the scan results -display_scan_results(scan_res) diff --git a/ports/nrf/boards/feather52/examples/blinky.py b/ports/nrf/boards/feather52/examples/blinky.py deleted file mode 100644 index 29cca26d0..000000000 --- a/ports/nrf/boards/feather52/examples/blinky.py +++ /dev/null @@ -1,12 +0,0 @@ -import board -import digitalio -import time - -led = digitalio.DigitalInOut(board.LED2) -led.direction = digitalio.Direction.OUTPUT - -while True: - led.value = True - time.sleep(0.5) - led.value = False - time.sleep(0.5) diff --git a/ports/nrf/boards/feather52/examples/i2c_scan.py b/ports/nrf/boards/feather52/examples/i2c_scan.py deleted file mode 100644 index 8e3ef557d..000000000 --- a/ports/nrf/boards/feather52/examples/i2c_scan.py +++ /dev/null @@ -1,20 +0,0 @@ -import board -import busio - -i2c = busio.I2C(board.SCL, board.SDA) -count = 0 - -# Wait for I2C lock -while not i2c.try_lock(): - pass - -# Scan for devices on the I2C bus -print("Scanning I2C bus") -for x in i2c.scan(): - print(hex(x)) - count += 1 - -print("%d device(s) found on I2C bus" % count) - -# Release the I2C bus -i2c.unlock() diff --git a/ports/nrf/boards/feather52/examples/pulseio.py b/ports/nrf/boards/feather52/examples/pulseio.py deleted file mode 100644 index cdbe16add..000000000 --- a/ports/nrf/boards/feather52/examples/pulseio.py +++ /dev/null @@ -1,25 +0,0 @@ -import time -from board import * -from pulseio import * - -# Setup BLUE and RED LEDs as PWM output (default frequency is 500 Hz) -ledb = PWMOut(LED2) -ledr = PWMOut(LED1) - -# Set the BLUE LED to have a duty cycle of 5000 (out of 65535, so ~7.5%) -ledb.duty_cycle = 5000 - -# Setup pin A0 as a standard PWM out @ 50% to test on the oscilloscope. -# You should see a 50% duty cycle waveform at ~500Hz on the scope when you -# connect a probe to pin A0 -a0 = PWMOut(A0) -a0.duty_cycle = int(65535/2) - -# Constantly pulse the RED LED -while True: - for i in range(100): - ledr.duty_cycle = int(i / 100 * 65535) - time.sleep(0.01) - for i in range(100, -1, -1): - ledr.duty_cycle = int(i / 100 * 65535) - time.sleep(0.01) diff --git a/ports/nrf/boards/feather52/mpconfigboard.h b/ports/nrf/boards/feather52/mpconfigboard.h deleted file mode 100644 index 176e61499..000000000 --- a/ports/nrf/boards/feather52/mpconfigboard.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * 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 MICROPY_HW_BOARD_NAME "Bluefruit nRF52 Feather" -#define MICROPY_HW_MCU_NAME "NRF52832" -#define MICROPY_PY_SYS_PLATFORM "nrf52" - -#define MICROPY_PY_MACHINE_HW_PWM (1) -#define MICROPY_PY_MACHINE_HW_SPI (1) -#define MICROPY_PY_MACHINE_TIMER (1) -#define MICROPY_PY_MACHINE_RTC (0) -#define MICROPY_PY_MACHINE_I2C (1) -#define MICROPY_PY_MACHINE_ADC (1) -#define MICROPY_PY_MACHINE_TEMP (1) - -#define MICROPY_HW_HAS_LED (1) -#define MICROPY_HW_HAS_SWITCH (0) -#define MICROPY_HW_HAS_FLASH (0) -#define MICROPY_HW_HAS_SDCARD (0) -#define MICROPY_HW_HAS_MMA7660 (0) -#define MICROPY_HW_HAS_LIS3DSH (0) -#define MICROPY_HW_HAS_LCD (0) -#define MICROPY_HW_ENABLE_RNG (0) -#define MICROPY_HW_ENABLE_RTC (0) -#define MICROPY_HW_ENABLE_TIMER (0) -#define MICROPY_HW_ENABLE_SERVO (0) -#define MICROPY_HW_ENABLE_DAC (0) -#define MICROPY_HW_ENABLE_CAN (0) - -#define MICROPY_HW_LED_COUNT (2) -#define MICROPY_HW_LED_PULLUP (0) - -#define MICROPY_HW_LED1 (17) // LED1 -#define MICROPY_HW_LED2 (19) // LED2 - -// UART config -#define MICROPY_HW_UART1_RX (pin_P0_08) -#define MICROPY_HW_UART1_TX (pin_P0_06) -#define MICROPY_HW_UART1_HWFC (0) - -// SPI0 config -#define MICROPY_HW_SPI0_NAME "SPI0" -#define MICROPY_HW_SPI0_SCK (pin_P0_12) // (Arduino D13) -#define MICROPY_HW_SPI0_MOSI (pin_P0_13) // (Arduino D11) -#define MICROPY_HW_SPI0_MISO (pin_P0_14) // (Arduino D12) - -#define MICROPY_HW_PWM0_NAME "PWM0" -#define MICROPY_HW_PWM1_NAME "PWM1" -#define MICROPY_HW_PWM2_NAME "PWM2" - -#define HELP_TEXT_BOARD_LED "1,2" - - - -#define PORT_HEAP_SIZE (32*1024) -#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 diff --git a/ports/nrf/boards/feather52/mpconfigboard.mk b/ports/nrf/boards/feather52/mpconfigboard.mk deleted file mode 100644 index 1e3aa5a24..000000000 --- a/ports/nrf/boards/feather52/mpconfigboard.mk +++ /dev/null @@ -1,42 +0,0 @@ -MCU_SERIES = m4 -MCU_VARIANT = nrf52 -MCU_SUB_VARIANT = nrf52832 -SOFTDEV_VERSION ?= 2.0.1 - -LD_FILE = boards/feather52/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld -BOOTLOADER_PKG = boards/feather52/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip - -NRF_DEFINES += -DNRF52832_XXAA - -ifeq ($(OS),Windows_NT) - NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe -else - NRFUTIL = nrfutil -endif - -ifeq ($(SD), ) -INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include -INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT) -endif - -CFLAGS += -DADAFRUIT_FEATHER52 - -check_defined = \ - $(strip $(foreach 1,$1, \ - $(call __check_defined,$1,$(strip $(value 2))))) -__check_defined = \ - $(if $(value $1),, \ - $(error Undefined make flag: $1$(if $2, ($2)))) - -.PHONY: dfu-gen dfu-flash boot-flash - -dfu-gen: - $(NRFUTIL) dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip - -dfu-flash: - @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) - $(NRFUTIL) dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200 - -boot-flash: - @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) - $(NRFUTIL) dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200 diff --git a/ports/nrf/boards/feather52/mpconfigboard_s132.mk b/ports/nrf/boards/feather52/mpconfigboard_s132.mk deleted file mode 100644 index 315758de3..000000000 --- a/ports/nrf/boards/feather52/mpconfigboard_s132.mk +++ /dev/null @@ -1,4 +0,0 @@ -# This file is a placeholder to enable building with 'SD=s132' flag -# The actual config data is stored in the file referenced below, regardless -# of whether S132 is actively used or not. -include boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/nrf/boards/feather52/nrf52_hal_conf.h b/ports/nrf/boards/feather52/nrf52_hal_conf.h deleted file mode 100644 index fd6073a18..000000000 --- a/ports/nrf/boards/feather52/nrf52_hal_conf.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef NRF52_HAL_CONF_H__ -#define NRF52_HAL_CONF_H__ - -#define HAL_UART_MODULE_ENABLED -#define HAL_SPI_MODULE_ENABLED -#define HAL_TIME_MODULE_ENABLED -#define HAL_PWM_MODULE_ENABLED -#define HAL_RTC_MODULE_ENABLED -#define HAL_TIMER_MODULE_ENABLED -#define HAL_TWI_MODULE_ENABLED -#define HAL_ADCE_MODULE_ENABLED -#define HAL_TEMP_MODULE_ENABLED -#define HAL_RNG_MODULE_ENABLED -// #define HAL_UARTE_MODULE_ENABLED -// #define HAL_SPIE_MODULE_ENABLED -// #define HAL_TWIE_MODULE_ENABLED - -#endif // NRF52_HAL_CONF_H__ diff --git a/ports/nrf/boards/feather52/pins.csv b/ports/nrf/boards/feather52/pins.csv deleted file mode 100644 index 3ffab88d4..000000000 --- a/ports/nrf/boards/feather52/pins.csv +++ /dev/null @@ -1,24 +0,0 @@ -A0,P0_02,ADC0_IN0 -A1,P0_03,ADC0_IN1 -A2,P0_04,ADC0_IN2 -A3,P0_05,ADC0_IN3 -TX,P0_06 -RX,P0_08 -NFC1,P0_09 -NFC2,P0_10 -D11,P0_11 -SCK,P0_12 -MOSI,P0_13 -MISO,P0_14 -D15,P0_15 -D16,P0_16 -LED1,P0_17 -LED2,P0_19 -DFU,P0_20 -SDA,P0_25 -SCL,P0_26 -D27,P0_27 -A4,P0_28,ADC0_IN4 -A5,P0_29,ADC0_IN5 -A6,P0_30,ADC0_IN6 -A7,P0_31,ADC0_IN7 diff --git a/ports/nrf/boards/feather52832/README.md b/ports/nrf/boards/feather52832/README.md new file mode 100644 index 000000000..c98f54614 --- /dev/null +++ b/ports/nrf/boards/feather52832/README.md @@ -0,0 +1,196 @@ +# Setup + +## 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 +``` + +## Installing `nrfutil` + +The Adafruit Bluefruit nRF52 Feather ships with a serial and OTA BLE bootloader +that can be used to flash firmware images over a simple serial connection, +using the on-board USB serial converter. + +If you haven't installed this command-line tool yet, go to the `/libs/nrfutil` +folder (where nrfutil 0.5.2 is installed as a sub-module) and run the following +commands: + +> If you get a 'sudo: pip: command not found' error running 'sudo pip install', +you can install pip via 'sudo easy_install pip' + +``` +$ cd ../../lib/nrfutil +$ sudo pip install -r requirements.txt +$ sudo python setup.py install +``` + +# Building and flashing firmware images + +## Building CircuitPython binaries + +#### REPL over UART (default settings) + +To build a CircuitPython binary with default settings for the +`feather52` target enter: + +> **NOTE:** `BOARD=feather52` is the default option and isn't stricly required. + +``` +$ make BOARD=feather52 V=1 +``` + +#### REPL over BLE UART (AKA 'NUS') + +To build a CircuitPython binary that uses the Nordic UART Service (AKA 'NUS' or +'BLEUART'), modify `/ports/nrf/bluetooth_conf.h` to have the following macro +set to `1` in the `#elif (BLUETOOTH_SD == 132)` section: + +``` +#define MICROPY_PY_BLE_NUS (1) +``` + +... then build as normal, via: + +``` +$ make BOARD=feather52 V=1 +``` + +You can then connect over BLE UART using an application like Bluefruit LE +Connect, available for Android, iOS and OS X, or any other application that +supports the NUS service and allows you to send the corrent EOL sequence. + +## Flashing binaries with `nrfutil` + +### 1. **Update bootloader** to single-bank version + +The Adafruit nRF52 Feather ships, by default, with a **dual-bank** bootloader +that cuts the available flash memory in half in exchange for safer +OTA updates. + +Due to the size of CircuitPython, we must migrate this bootloader to a +**single-bank** version, doubling the amount of flash memory available to us. + +> These commands only need to be run once and will update the SoftDevice and +bootloader from the dual-bank version that ships on Arduino-based Adafruit +Feather52 boards to a single-bank CircuitPython compatible version: + +#### S132 v2.0.1 single-bank (recommended): + +By default s132 v2.0.1 is used when no `SOFTDEV_VERSION` field is passed in: + +``` +$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART boot-flash +``` + +#### S132 v5.0.0 (BLE5, experimental): + +To enable BLE5 support and the latest S132 release, flash the v5.0.0 bootloader via: + +``` +$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SOFTDEV_VERSION=5.0.0 boot-flash +``` + +### 2. Generate and flash a CircuitPython DFU .zip package over serial + +The following command will package and flash the CircuitPython binary using the +appropriate bootloader mentionned above. + +This command assumes you have already built a valid circuitpython +image, as described earlier in this readme. + +> The name of the serial port target will vary, depending on your OS. + +``` +$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash +``` + +By default, CircuitPython will build with **BLE** support enabled using +`SD=s132` and the `SOFTDEV_VERSION=2.0.1`. If you wish to specify a different +SD family or version you can enter the optional fields as shown below: + +``` +$ make BOARD=feather52 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 SOFTDEV_VERSION=5.0.0 dfu-gen dfu-flash +``` + +## Working with CircuitPython + +### Running local files with `ampy` + +[ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy) +is a command-line tool that can be used with the nRF52 Feather to transfer +local python files to the nRF52 for execution, rather than having to enter +the REPL manually, enter paste mode, and paste the code yourself. + +> **IMPORTANT**: You must have `ampy` version **1.0.3** or higher to use `ampy` + with the nRF52. The bootloader on the nRF52 requires a delay between the + HW reset, and the moment when the command sequance is sent to enter raw + mode. This required `-d/--delay` flag was added in release 1.0.3. + + +Save the following file as `test.py`: + +``` +import board +import digitalio +import time + +led = digitalio.DigitalInOut(board.LED2) +led.direction = digitalio.Direction.OUTPUT + +while True: + led.value = True + time.sleep(0.5) + led.value = False + time.sleep(0.5) +``` + +Then run the saved file via ampy, updating the serial port as required: + +``` +$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 run test.py +``` + +This should give you blinky at 1 Hz on LED2 (the blue LED on the nRF52 Feather). + +### Uploading files and libraries with `ampy` + +To upload Python files or pre-compiled CircuitPython libraries to the `lib` folder, +run the following commands: + +> In this example **i2c_device.py** is used, which is part of + [Adafruit_CircuitPython_BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) + +``` +$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 put i2c_device.py lib/i2c_device.py +``` + +To verify that the file was uploaded correctly, you can check the contents of +the `lib` folder with: + +``` +$ ampy -p /dev/tty.SLAB_USBtoUART -d 1.5 ls /lib +i2c_device.py +``` + +### Suggested libraries + +The following libraries should be installed as a minimum on most new boards: + +- [Adafruit_CircuitPython_BusDevice](https://github.com/adafruit/Adafruit_CircuitPython_BusDevice) +- [Adafruit_CircuitPython_Register](https://github.com/adafruit/Adafruit_CircuitPython_Register/tree/master) diff --git a/ports/nrf/boards/feather52832/board.c b/ports/nrf/boards/feather52832/board.c new file mode 100644 index 000000000..e0b77437b --- /dev/null +++ b/ports/nrf/boards/feather52832/board.c @@ -0,0 +1,71 @@ +/* + * 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 +#include + +#include "nrf.h" + +#include "boards/board.h" + +// Must match temp register in bootloader +#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0] +uint32_t bootloaderVersion = 0; + +void board_init(void) { + // Retrieve bootloader version + bootloaderVersion = BOOTLOADER_VERSION_REGISTER; +} + +// Check the status of the two buttons on CircuitPlayground Express. If both are +// pressed, then boot into user safe mode. +bool board_requests_safe_mode(void) { +// gpio_set_pin_function(PIN_PA14, GPIO_PIN_FUNCTION_OFF); +// gpio_set_pin_direction(PIN_PA14, GPIO_DIRECTION_IN); +// gpio_set_pin_pull_mode(PIN_PA14, GPIO_PULL_DOWN); +// +// gpio_set_pin_function(PIN_PA28, GPIO_PIN_FUNCTION_OFF); +// gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_IN); +// gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN); +// bool safe_mode = gpio_get_pin_level(PIN_PA14) && +// gpio_get_pin_level(PIN_PA28); +// reset_pin(PIN_PA14); +// reset_pin(PIN_PA28); +// return safe_mode; + + return false; +} + +void reset_board(void) { +// uint8_t empty[30]; +// memset(empty, 0, 30); +// digitalio_digitalinout_obj_t neopixel_pin; +// common_hal_digitalio_digitalinout_construct(&neopixel_pin, &pin_PB23); +// common_hal_digitalio_digitalinout_switch_to_output(&neopixel_pin, false, +// DRIVE_MODE_PUSH_PULL); +// common_hal_neopixel_write(&neopixel_pin, empty, 30); +// common_hal_digitalio_digitalinout_deinit(&neopixel_pin); +} diff --git a/ports/nrf/boards/feather52832/bootloader/.gitattributes b/ports/nrf/boards/feather52832/bootloader/.gitattributes new file mode 100644 index 000000000..608f8c345 --- /dev/null +++ b/ports/nrf/boards/feather52832/bootloader/.gitattributes @@ -0,0 +1,2 @@ +# Inform git that .zip files should be treated as binary +*.zip binary diff --git a/ports/nrf/boards/feather52832/bootloader/README.md b/ports/nrf/boards/feather52832/bootloader/README.md new file mode 100644 index 000000000..434859085 --- /dev/null +++ b/ports/nrf/boards/feather52832/bootloader/README.md @@ -0,0 +1,9 @@ +# Adafruit nRF52 Feather Single-Bank Bootloader + +These files contain an implementation of a single-bank bootloader, +which doubles the amount of flash memory available to applications +at the expense of safe over the air updates. + +Two versions are present, based on release **2.0.1** and **5.0.0** +of the Nordic S132 SoftDevice. The SoftDevice is included as poart +of the bootloader binary. diff --git a/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_2.0.1_s132_single.zip b/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_2.0.1_s132_single.zip new file mode 100644 index 000000000..42a83bb90 Binary files /dev/null and b/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_2.0.1_s132_single.zip differ diff --git a/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_5.0.0_s132_single.zip b/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_5.0.0_s132_single.zip new file mode 100644 index 000000000..2f30a9fd4 Binary files /dev/null and b/ports/nrf/boards/feather52832/bootloader/feather52_bootloader_5.0.0_s132_single.zip differ diff --git a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld b/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld new file mode 100644 index 000000000..a1c128e37 --- /dev/null +++ b/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld @@ -0,0 +1,44 @@ +/* + GNU linker script for NRF52 w/ s132 2.0.1 SoftDevice + + MEMORY MAP + ------------------------------------------------------------------------ + START ADDR END ADDR SIZE DESCRIPTION + ---------- ---------- ------- ----------------------------------------- + 0x0007F000..0x0007FFFF ( 4KB) Bootloader Settings + 0x0007E000..0x0007EFFF ( 4KB) Master Boot Record Params + 0x00074000..0x0007DFFF ( 40KB) Serial + OTA Bootloader + + 0x00073000..0x00073FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.) + 0x00072000..0x00072FFF ( 4KB ) User NVM data + 0x00059000..0x00071FFF (100KB) User Filesystem + + 0x0001C000..0x00058FFF (244KB) Application Code + 0x00001000..0x0001BFFF (108KB) SoftDevice + 0x00000000..0x00000FFF (4KB) Master Boot Record +*/ + +/* Specify the memory areas (S132 2.0.1) */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */ + FLASH_ISR (rx) : ORIGIN = 0x0001c000, LENGTH = 0x001000 /* sector 0, 4 KiB */ + FLASH_TEXT (rx) : ORIGIN = 0x0001d000, LENGTH = 0x03C000 /* APP - ISR, 240 KiB */ + FLASH_FATFS (r) : ORIGIN = 0x00059000, LENGTH = 0x019000 /* File system 100KB KB */ + RAM (xrw) : ORIGIN = 0x20003000, LENGTH = 0x0D000 /* 52 KiB, give 8KiB headroom for softdevice */ +} + +/* produce a link error if there is not this amount of RAM for these sections */ +_minimum_stack_size = 2K; +_minimum_heap_size = 0 /*16K Circuit Python use static variable for HEAP */; + +/* top end of the stack */ + +/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +/* RAM extents for the garbage collector */ +_ram_end = ORIGIN(RAM) + LENGTH(RAM); +_heap_end = 0x20007000; /* tunable */ + +INCLUDE "boards/common.ld" diff --git a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld b/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld new file mode 100644 index 000000000..f9209bf3d --- /dev/null +++ b/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld @@ -0,0 +1,44 @@ +/* + GNU linker script for NRF52 w/ s132 5.0.0 SoftDevice + + MEMORY MAP + ------------------------------------------------------------------------ + START ADDR END ADDR SIZE DESCRIPTION + ---------- ---------- ------- ----------------------------------------- + 0x0007F000..0x0007FFFF ( 4KB) Bootloader Settings + 0x0007E000..0x0007EFFF ( 4KB) Master Boot Record Params + 0x00074000..0x0007DFFF ( 40KB) Serial + OTA Bootloader + + 0x00073000..0x00073FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.) + 0x00072000..0x00072FFF ( 4KB ) User NVM data + 0x00059000..0x00071FFF ( 100KB) User Filesystem + + 0x00023000..0x00058FFF (216KB) Application Code + 0x00001000..0x00022FFF (136KB) SoftDevice + 0x00000000..0x00000FFF (4KB) Master Boot Record +*/ + +/* Specify the memory areas (S132 5.0.0) */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x080000 /* entire flash, 512 KiB */ + FLASH_ISR (rx) : ORIGIN = 0x00023000, LENGTH = 0x001000 /* sector 0, 4 KiB */ + FLASH_TEXT (rx) : ORIGIN = 0x00024000, LENGTH = 0x036000 /* APP - ISR, 216 KiB */ + FLASH_FATFS (r) : ORIGIN = 0x00059000, LENGTH = 0x019000 /* File system 100KB KB */ + RAM (xrw) : ORIGIN = 0x200039c0, LENGTH = 0x0c640 /* 49.5 KiB, give 8KiB headroom for softdevice */ +} + +/* produce a link error if there is not this amount of RAM for these sections */ +_minimum_stack_size = 2K; +_minimum_heap_size = 0 /*16K Circuit Python use static variable for HEAP */; + +/* top end of the stack */ + +/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +/* RAM extents for the garbage collector */ +_ram_end = ORIGIN(RAM) + LENGTH(RAM); +_heap_end = 0x20007000; /* tunable */ + +INCLUDE "boards/common.ld" diff --git a/ports/nrf/boards/feather52832/examples/ble_scan.py b/ports/nrf/boards/feather52832/examples/ble_scan.py new file mode 100644 index 000000000..9cacbe6f4 --- /dev/null +++ b/ports/nrf/boards/feather52832/examples/ble_scan.py @@ -0,0 +1,26 @@ +from ubluepy import Scanner, constants + +def display_scan_results(scan_entries): + for e in scan_entries: + print("ADDR: ", e.addr()) + print("TYPE: ", e.addr_type()) + print("RSSI: ", e.rssi()) + + # Parse the contents of the advertising packet + scan = e.getScanData() + if scan: + for s in scan: + # Convert byte array to hex format string + hex = ' '.join('0x%02X' % b for b in s[2]) + # Display enum value and hex string together + print('\t{}: {}'.format(s[1], hex)) + + # Line break between record sets + print("") + +# Scan 1s for advertising devices in range +s = Scanner() +scan_res = s.scan(1000) + +# Display the scan results +display_scan_results(scan_res) diff --git a/ports/nrf/boards/feather52832/examples/blinky.py b/ports/nrf/boards/feather52832/examples/blinky.py new file mode 100644 index 000000000..29cca26d0 --- /dev/null +++ b/ports/nrf/boards/feather52832/examples/blinky.py @@ -0,0 +1,12 @@ +import board +import digitalio +import time + +led = digitalio.DigitalInOut(board.LED2) +led.direction = digitalio.Direction.OUTPUT + +while True: + led.value = True + time.sleep(0.5) + led.value = False + time.sleep(0.5) diff --git a/ports/nrf/boards/feather52832/examples/i2c_scan.py b/ports/nrf/boards/feather52832/examples/i2c_scan.py new file mode 100644 index 000000000..8e3ef557d --- /dev/null +++ b/ports/nrf/boards/feather52832/examples/i2c_scan.py @@ -0,0 +1,20 @@ +import board +import busio + +i2c = busio.I2C(board.SCL, board.SDA) +count = 0 + +# Wait for I2C lock +while not i2c.try_lock(): + pass + +# Scan for devices on the I2C bus +print("Scanning I2C bus") +for x in i2c.scan(): + print(hex(x)) + count += 1 + +print("%d device(s) found on I2C bus" % count) + +# Release the I2C bus +i2c.unlock() diff --git a/ports/nrf/boards/feather52832/examples/pulseio.py b/ports/nrf/boards/feather52832/examples/pulseio.py new file mode 100644 index 000000000..cdbe16add --- /dev/null +++ b/ports/nrf/boards/feather52832/examples/pulseio.py @@ -0,0 +1,25 @@ +import time +from board import * +from pulseio import * + +# Setup BLUE and RED LEDs as PWM output (default frequency is 500 Hz) +ledb = PWMOut(LED2) +ledr = PWMOut(LED1) + +# Set the BLUE LED to have a duty cycle of 5000 (out of 65535, so ~7.5%) +ledb.duty_cycle = 5000 + +# Setup pin A0 as a standard PWM out @ 50% to test on the oscilloscope. +# You should see a 50% duty cycle waveform at ~500Hz on the scope when you +# connect a probe to pin A0 +a0 = PWMOut(A0) +a0.duty_cycle = int(65535/2) + +# Constantly pulse the RED LED +while True: + for i in range(100): + ledr.duty_cycle = int(i / 100 * 65535) + time.sleep(0.01) + for i in range(100, -1, -1): + ledr.duty_cycle = int(i / 100 * 65535) + time.sleep(0.01) diff --git a/ports/nrf/boards/feather52832/mpconfigboard.h b/ports/nrf/boards/feather52832/mpconfigboard.h new file mode 100644 index 000000000..176e61499 --- /dev/null +++ b/ports/nrf/boards/feather52832/mpconfigboard.h @@ -0,0 +1,79 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Glenn Ruben Bakke + * + * 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 MICROPY_HW_BOARD_NAME "Bluefruit nRF52 Feather" +#define MICROPY_HW_MCU_NAME "NRF52832" +#define MICROPY_PY_SYS_PLATFORM "nrf52" + +#define MICROPY_PY_MACHINE_HW_PWM (1) +#define MICROPY_PY_MACHINE_HW_SPI (1) +#define MICROPY_PY_MACHINE_TIMER (1) +#define MICROPY_PY_MACHINE_RTC (0) +#define MICROPY_PY_MACHINE_I2C (1) +#define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) + +#define MICROPY_HW_HAS_LED (1) +#define MICROPY_HW_HAS_SWITCH (0) +#define MICROPY_HW_HAS_FLASH (0) +#define MICROPY_HW_HAS_SDCARD (0) +#define MICROPY_HW_HAS_MMA7660 (0) +#define MICROPY_HW_HAS_LIS3DSH (0) +#define MICROPY_HW_HAS_LCD (0) +#define MICROPY_HW_ENABLE_RNG (0) +#define MICROPY_HW_ENABLE_RTC (0) +#define MICROPY_HW_ENABLE_TIMER (0) +#define MICROPY_HW_ENABLE_SERVO (0) +#define MICROPY_HW_ENABLE_DAC (0) +#define MICROPY_HW_ENABLE_CAN (0) + +#define MICROPY_HW_LED_COUNT (2) +#define MICROPY_HW_LED_PULLUP (0) + +#define MICROPY_HW_LED1 (17) // LED1 +#define MICROPY_HW_LED2 (19) // LED2 + +// UART config +#define MICROPY_HW_UART1_RX (pin_P0_08) +#define MICROPY_HW_UART1_TX (pin_P0_06) +#define MICROPY_HW_UART1_HWFC (0) + +// SPI0 config +#define MICROPY_HW_SPI0_NAME "SPI0" +#define MICROPY_HW_SPI0_SCK (pin_P0_12) // (Arduino D13) +#define MICROPY_HW_SPI0_MOSI (pin_P0_13) // (Arduino D11) +#define MICROPY_HW_SPI0_MISO (pin_P0_14) // (Arduino D12) + +#define MICROPY_HW_PWM0_NAME "PWM0" +#define MICROPY_HW_PWM1_NAME "PWM1" +#define MICROPY_HW_PWM2_NAME "PWM2" + +#define HELP_TEXT_BOARD_LED "1,2" + + + +#define PORT_HEAP_SIZE (32*1024) +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 diff --git a/ports/nrf/boards/feather52832/mpconfigboard.mk b/ports/nrf/boards/feather52832/mpconfigboard.mk new file mode 100644 index 000000000..2a1c081fb --- /dev/null +++ b/ports/nrf/boards/feather52832/mpconfigboard.mk @@ -0,0 +1,42 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52832 +SOFTDEV_VERSION ?= 2.0.1 + +LD_FILE = boards/feather52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld +BOOTLOADER_PKG = boards/feather52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip + +NRF_DEFINES += -DNRF52832_XXAA + +ifeq ($(OS),Windows_NT) + NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe +else + NRFUTIL = nrfutil +endif + +ifeq ($(SD), ) +INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include +INC += -Idrivers/bluetooth/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/s132_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT) +endif + +CFLAGS += -DADAFRUIT_FEATHER52 + +check_defined = \ + $(strip $(foreach 1,$1, \ + $(call __check_defined,$1,$(strip $(value 2))))) +__check_defined = \ + $(if $(value $1),, \ + $(error Undefined make flag: $1$(if $2, ($2)))) + +.PHONY: dfu-gen dfu-flash boot-flash + +dfu-gen: + $(NRFUTIL) dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip + +dfu-flash: + @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) + $(NRFUTIL) dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200 + +boot-flash: + @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) + $(NRFUTIL) dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200 diff --git a/ports/nrf/boards/feather52832/mpconfigboard_s132.mk b/ports/nrf/boards/feather52832/mpconfigboard_s132.mk new file mode 100644 index 000000000..315758de3 --- /dev/null +++ b/ports/nrf/boards/feather52832/mpconfigboard_s132.mk @@ -0,0 +1,4 @@ +# This file is a placeholder to enable building with 'SD=s132' flag +# The actual config data is stored in the file referenced below, regardless +# of whether S132 is actively used or not. +include boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/nrf/boards/feather52832/nrf52_hal_conf.h b/ports/nrf/boards/feather52832/nrf52_hal_conf.h new file mode 100644 index 000000000..fd6073a18 --- /dev/null +++ b/ports/nrf/boards/feather52832/nrf52_hal_conf.h @@ -0,0 +1,18 @@ +#ifndef NRF52_HAL_CONF_H__ +#define NRF52_HAL_CONF_H__ + +#define HAL_UART_MODULE_ENABLED +#define HAL_SPI_MODULE_ENABLED +#define HAL_TIME_MODULE_ENABLED +#define HAL_PWM_MODULE_ENABLED +#define HAL_RTC_MODULE_ENABLED +#define HAL_TIMER_MODULE_ENABLED +#define HAL_TWI_MODULE_ENABLED +#define HAL_ADCE_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED +#define HAL_RNG_MODULE_ENABLED +// #define HAL_UARTE_MODULE_ENABLED +// #define HAL_SPIE_MODULE_ENABLED +// #define HAL_TWIE_MODULE_ENABLED + +#endif // NRF52_HAL_CONF_H__ diff --git a/ports/nrf/boards/feather52832/pins.csv b/ports/nrf/boards/feather52832/pins.csv new file mode 100644 index 000000000..3ffab88d4 --- /dev/null +++ b/ports/nrf/boards/feather52832/pins.csv @@ -0,0 +1,24 @@ +A0,P0_02,ADC0_IN0 +A1,P0_03,ADC0_IN1 +A2,P0_04,ADC0_IN2 +A3,P0_05,ADC0_IN3 +TX,P0_06 +RX,P0_08 +NFC1,P0_09 +NFC2,P0_10 +D11,P0_11 +SCK,P0_12 +MOSI,P0_13 +MISO,P0_14 +D15,P0_15 +D16,P0_16 +LED1,P0_17 +LED2,P0_19 +DFU,P0_20 +SDA,P0_25 +SCL,P0_26 +D27,P0_27 +A4,P0_28,ADC0_IN4 +A5,P0_29,ADC0_IN5 +A6,P0_30,ADC0_IN6 +A7,P0_31,ADC0_IN7 diff --git a/tools/build_adafruit_bins.sh b/tools/build_adafruit_bins.sh index 1b25c1e2f..3320a21ef 100755 --- a/tools/build_adafruit_bins.sh +++ b/tools/build_adafruit_bins.sh @@ -2,7 +2,7 @@ rm -rf ports/atmel-samd/build* rm -rf ports/esp8266/build* rm -rf ports/nrf/build* -ATMEL_BOARDS="arduino_zero circuitplayground_express circuitplayground_express_crickit feather_m0_basic feather_m0_adalogger itsybitsy_m0_express itsybitsy_m4_express feather_m0_rfm69 feather_m0_rfm9x feather_m0_express feather_m0_express_crickit feather_m4_express metro_m0_express metro_m4_express pirkey_m0 trinket_m0 gemma_m0 feather52 feather_huzzah pca10056" +ATMEL_BOARDS="arduino_zero circuitplayground_express circuitplayground_express_crickit feather_m0_basic feather_m0_adalogger itsybitsy_m0_express itsybitsy_m4_express feather_m0_rfm69 feather_m0_rfm9x feather_m0_express feather_m0_express_crickit feather_m4_express metro_m0_express metro_m4_express pirkey_m0 trinket_m0 gemma_m0 feather52832 feather_huzzah pca10056" ROSIE_SETUPS="rosie-ci" PARALLEL="-j 5" @@ -53,7 +53,7 @@ for board in $boards; do cp ports/esp8266/build/firmware-combined.bin bin/$board/adafruit-circuitpython-$board-$version.bin (( exit_status = exit_status || $? )) extension=bin - elif [ $board == "feather52" ]; then + elif [ $board == "feather52832" ]; then cp ports/nrf/build-$board-s132/firmware.bin bin/$board/adafruit-circuitpython-$board-$version.bin (( exit_status = exit_status || $? )) extension=bin -- cgit v1.2.3 From 724bd7c17f316ca4fd400b5f75efaef8248ebc62 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 18 Jun 2018 14:07:21 -0700 Subject: Correct the tool build --- tools/build_adafruit_bins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build_adafruit_bins.sh b/tools/build_adafruit_bins.sh index 3320a21ef..4111a7b1b 100755 --- a/tools/build_adafruit_bins.sh +++ b/tools/build_adafruit_bins.sh @@ -20,8 +20,8 @@ for board in $boards; do if [ $board == "feather_huzzah" ]; then make $PARALLEL -C ports/esp8266 BOARD=feather_huzzah (( exit_status = exit_status || $? )) - elif [ $board == "feather52" ]; then - make $PARALLEL -C ports/nrf BOARD=feather52 + elif [ $board == "feather52832" ]; then + make $PARALLEL -C ports/nrf BOARD=feather52832 (( exit_status = exit_status || $? )) elif [ $board == "pca10056" ]; then make $PARALLEL -C ports/nrf BOARD=pca10056 SD=s140 -- cgit v1.2.3 From c90abb1370b5b845ac09ba9e55aa7ba4f00c4ede Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 18 Jun 2018 14:28:45 -0700 Subject: Fix BLE file download for travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index badd78b4c..a5829896f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ before_script: # For teensy build - sudo apt-get install realpath # For nrf builds - - ([[ $TRAVIS_BOARD != "feather52" && $TRAVIS_BOARD != "pca10056" ]] || sudo ports/nrf/drivers/bluetooth/download_ble_stack.sh) + - ([[ $TRAVIS_BOARD != "feather52832" && $TRAVIS_BOARD != "pca10056" ]] || sudo ports/nrf/drivers/bluetooth/download_ble_stack.sh) # For huzzah builds - if [[ $TRAVIS_BOARD = "feather_huzzah" ]]; then wget https://github.com/jepler/esp-open-sdk/releases/download/2018-06-10/xtensa-lx106-elf-standalone.tar.gz && tar xavf xtensa-lx106-elf-standalone.tar.gz; PATH=$(readlink -f xtensa-lx106-elf/bin):$PATH; fi # For coverage testing (upgrade is used to get latest urllib3 version) -- cgit v1.2.3