The nRF52840 by Nordic is an Arm M4 chip with 1MB of flash and 256KB of ram, and has native USB capabilities. This makes it very convenient to run Circuit Python.
Circuit Python however, uses a bootloader called UF2 which Adafruit had adapted for the nRF chips: https://github.com/adafruit/Adafruit_nRF52_Bootloader
I decided to make a small shield with some necessary components on it, so I can just snap it on top of the prototype dev board I had and I don't have to make anything permanent.
- On the left side is a female header that connects the USB VBUS, D-, D+ and GND to the nRF52840 directly.
- There's also the red wire to connect VBUS to VDDH.
- A 10k resistor pulls up the reset pin through VDD
- A momentary switch is connected to the reset pin, which then is shorted to ground via a 1k resistor when pushed
I then downloaded the pre-built hex binary from https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases/tag/0.3.2 (I used the pca10056_bootloader-0.3.2_s140_6.1.1.hex) and flashed it via SWD
PS C:\Users\tristan\Downloads> openocd -d2 -f interface/jlink.cfg -c "transport select swd" -f target/nrf52.cfg -c "init; halt; flash erase_check 0; program pca10056_bootloader-0.3.2_s140_6.1.1.hex; reset; exit" xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 2 swd Info : J-Link ARM-OB STM32 compiled Jun 30 2009 11:14:15 Info : Hardware version: 7.00 Info : VTarget = 3.300 V Info : clock speed 1000 kHz Info : SWD DPIDR 0x2ba01477 Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints Info : starting gdb server for nrf52.cpu on 3333 Info : Listening on port 3333 for gdb connections Info : nRF52840-xxAA(build code: D0) 1024kB Flash, 256kB RAM Warn : Flash protection of this nRF device is not supported Error: nrf52.cpu -- clearing lockup after double fault Running slow fallback erase check - add working memory target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc ** Programming Started ** Info : Padding image section 0 at 0x00000b00 with 1280 bytes Info : Flash write discontinued at 0x00025de8, next section at 0x000f4000 Warn : Adding extra erase range, 0x00025de8 .. 0x00025fff Warn : Adding extra erase range, 0x000fb620 .. 0x000fbfff Warn : Adding extra erase range, 0x10001000 .. 0x10001013 Warn : Adding extra erase range, 0x1000101c .. 0x10001fff ** Programming Finished ** P
Attaching a USB cable will then present the UF2 bootloader as a disk drive with the label NRF52BOOT
I then downloaded a pre-built Circuit Python firmware from https://circuitpython.org/downloads but the question is: which one? Since this is a bare chip and I don't have any peripherals, I browsed through the available boards and looked for one that had the minimal configuration. I ended up with the SparkFun Pro nRF52840 Mini https://circuitpython.org/board/sparkfun_nrf52840_mini/ and the pin definitions at https://github.com/adafruit/circuitpython/blob/main/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c
Dragging the uf2 file onto the bootloader reboots the chip and then presents it as a disk drive with the label CIRCUITPY
Editing code.py and then saving it with a small blink sketch works as expected. I had to refer to https://github.com/adafruit/circuitpython/blob/main/ports/nrf/boards/sparkfun_nrf52840_mini/pins.c for the pin definitions as SparkFun didn't use the matching pin numbers for the silkscreen.
Next up: I try out Mbed OS and make a custom target definitionARM Mbed OS on a Bare nRF52840 Chengdu Ebyte Custom Target