nrf52480 build and flash

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

nrf52480 build and flash

Post by ltmerlin » Tue Feb 18, 2020 3:58 pm

Has anyone succeeded in building and flashing Micropython for the Adafruit Feather nrf52480?
So far there is no board in the ports. I successfully built micropython for the pca10056 (since the Adafruit Feather nrf52480 is based on this one)

Code: Select all

make BOARD=pca10056 SD=s140 sd
Flashing the device using the uf2 does not work. Any ideas what I need to change? pins.csv?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: nrf52480 build and flash

Post by jimmo » Wed Feb 19, 2020 12:56 am

I have use MicroPython on the Particle Xenon (also 52840) although had some issues with flashing.

How did you make the uf2 firmware (I don't think the Makefile does this?) -- it's likely that the firmware needs to be built to be aware of the bootloader layout etc. (I'm fairly sure the NRF builds are designed to be flashed directly with SWD, i.e. not using a bootloader). Although see https://github.com/micropython/micropython/pull/5158 which might give you some hints.

As far as debugging this -- it could be anything from "not booting at all" to "just the uart isn't configured correctly". Depending on what you have available, you could experiment with adding some GPIO toggling in main.c or attach an SWD debugger (I've used both a black magic probe and an st-link on this board).

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: nrf52480 build and flash

Post by ltmerlin » Wed Feb 19, 2020 10:56 am

Thanks for your answer,
I have managed to built and flash the Adafruit nrf52480 with micropython instead of circuitpython. (Used the https://github.com/Microsoft/uf2/blob/m ... uf2conv.py to created the uf2 after using the regular makefile )
Now before starting with bluetooth programming I have the following bluetooth related modules available:
- ble
- ubluepy

I read your bluetooth examples at the micropython GitHub: https://github.com/micropython/micropyt ... /bluetooth and there you use the "bluetooth" module but no "ubluepy" like in the nrf port examples at https://github.com/micropython/micropyt ... f/examples
What is the difference? Can I get the "bluetooth" module working for this board as well or do I need to use "ubluepy"? it actually does not matter for me which one , but I want to use the most complete bluetooth module to do standard stuff like GATT, peripheral, central,...
Any advice?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: nrf52480 build and flash

Post by jimmo » Wed Feb 19, 2020 1:00 pm

ltmerlin wrote:
Wed Feb 19, 2020 10:56 am
I have managed to built and flash the Adafruit nrf52480 with micropython instead of circuitpython. (Used the https://github.com/Microsoft/uf2/blob/m ... uf2conv.py to created the uf2 after using the regular makefile )
Great, how did you fix it?
ltmerlin wrote:
Wed Feb 19, 2020 10:56 am
What is the difference?
Yes, what you said is correct for the time being. The nrf port has ubluepy and the stm32 and nrf ports have ubluetooth. My plan is to update the NRF port to use ubluetooth also, so I guess the current state of ubluepy is "deprecated". The APIs are quite different -- the idea is that ubluetooth is as low-level as possible, you can build higher-level object-based abstractions on top of it in Python.

Unfortunately I don't know much about ubluepy. I know it definitely supports peripheral (i.e. gatt client) and advertiser and scanner roles, but I'm unsure about central (i.e. gatt client). (I looked at the code and it doesn't look like it...) There are examples of peripheral/advertiser/scanner in ports/nrf/examples.

The main question when it comes to adding ubluetooth to NRF is whether to go down the Nordic SoftDevice route or perhaps use NimBLE directly (i.e. NimBLE has a controller for the NRF radio, which we could hook up to the existing NimBLE host bindings). Some research required to confirm that this doesn't require the full MyNewt OS to run the controller. (And of course more spare time...!).

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: nrf52480 build and flash

Post by ltmerlin » Wed Feb 19, 2020 2:22 pm

Great, how did you fix it?
Inside your Micropython git clone directory create a new board directory for the custom port named NRF52840:

Code: Select all

cd /micropython/ports/nrf/boards
mkdir NRF52840
containing:

Code: Select all


/*
 * This file is part of the MicroPython project, http://micropython.org/
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2016 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       "FEATHER-NRF52840"
#define MICROPY_HW_MCU_NAME         "NRF52840"
#define MICROPY_PY_SYS_PLATFORM     "nrf52840-feather"

#define MICROPY_PY_MACHINE_UART     (1)
#define MICROPY_PY_MACHINE_HW_PWM   (1)
#define MICROPY_PY_MACHINE_HW_SPI   (1)
#define MICROPY_PY_MACHINE_TIMER    (1)
#define MICROPY_PY_MACHINE_RTCOUNTER (1)
#define MICROPY_PY_MACHINE_I2C      (1)
#define MICROPY_PY_MACHINE_ADC      (1)
#define MICROPY_PY_MACHINE_TEMP     (1)

#define MICROPY_HW_USB_CDC          (1) //very important to get USB-Serial to work

#define MICROPY_HW_ENABLE_RNG       (1)

#define MICROPY_HW_NEOPIXEL         (16)

#define BOARD_HAS_CRYSTAL 1

#if QSPI_FLASH_FILESYSTEM
#define MICROPY_QSPI_DATA0          (17)
#define MICROPY_QSPI_DATA1          (22)
#define MICROPY_QSPI_DATA2          (23)
#define MICROPY_QSPI_DATA3          (21)
#define MICROPY_QSPI_SCK            (19)
#define MICROPY_QSPI_CS             (20)
#endif

#define MICROPY_HW_HAS_LED          (1)
#define MICROPY_HW_LED_COUNT        (2)
#define MICROPY_HW_LED_PULLUP       (0)

#define MICROPY_HW_LED1             (32+10) // LED1
#define MICROPY_HW_LED2             (32+15) // LED2

// UART config
#define MICROPY_HW_UART1_RX         (24)
#define MICROPY_HW_UART1_TX         (25)
//#define MICROPY_HW_UART1_CTS        (7)
//#define MICROPY_HW_UART1_RTS        (5)
#define MICROPY_HW_UART1_HWFC       (0)

// SPI0 config
#define MICROPY_HW_SPI0_NAME        "SPI0"

#define MICROPY_HW_SPI0_SCK         (14)
#define MICROPY_HW_SPI0_MOSI        (13)
#define MICROPY_HW_SPI0_MISO        (15)

#define MICROPY_HW_PWM0_NAME        "PWM0"
#define MICROPY_HW_PWM1_NAME        "PWM1"
#define MICROPY_HW_PWM2_NAME        "PWM2"
#if 0
#define MICROPY_HW_PWM3_NAME        "PWM3"
#endif

#define HELP_TEXT_BOARD_LED         "1,2"

Create a mpconfigboard.mk file containing:

Code: Select all

MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52840
SOFTDEV_VERSION = 6.1.1
LD_FILES += boards/nrf52840_1M_256k.ld
NRF_DEFINES += -DNRF52840_XXAA
Pins.csv file containing:

Code: Select all


P0,P0
P1,P1
P2,P2
P3,P3
P4,P4
P5,P5
P6,P6
P7,P7
P8,P8
P9,P9
P10,P10
P11,P11
P12,P12
P13,P13
P14,P14
P15,P15
P16,P16
P17,P17
P18,P18
P19,P19
P20,P20
P21,P21
P22,P22
P23,P23
P24,P24
P25,P25
P26,P26
P27,P27
P28,P28
P29,P29
P30,P30
P31,P31
P32,P32
P33,P33
P34,P34
P35,P35
P36,P36
P37,P37
P38,P38
P39,P39
P40,P40
P41,P41
P42,P42
P43,P43
P44,P44
P45,P45
P46,P46
P47,P47
To build with soft device 140 (as is required for this chip):

Code: Select all

cd /micropython/ports/nrf/
make submodules
make BOARD=NRF52840 sd=s140
A build folder will be created, and therein you will find the firmware.hex and firmware.bin files. Either of these should be converted to a uf2 file, so that it can be dragged and dropped to the Adafruit board. To convert the firmware to a uf2 file, we need to use the uf2conv.py script. (see link previous post for uf2conv.py)
Perform the conversion, not forgetting to set the family flag, -f, to 0XADA52840 and the convert only flag -c

Code: Select all

cd /micropython/ports/nrf/build-NRF52840-s140
python3 /Users/ltmerlin/Desktop/uf2tool.py firmware.hex -c -f 0xADA52840
This should create a flash.uf2 file in the build directory. Connect the Adafruit board via USB to the computer and double press the reset button on the board to go into bootloader mode. The Neopixel should go green and the red LED labelled D3 should breathe. A drive should now be visible called FTHR840BOOT. Drag the flash.uf2 file to this drive. The board should reset itself and micropython should be running.

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: nrf52480 build and flash

Post by ttmetro » Tue Jan 05, 2021 4:00 am

Thanks for the instructions!
Bernhard Boser

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: nrf52480 build and flash

Post by ttmetro » Tue Jan 05, 2021 4:04 am

Thanks for the instructions!

If you add the following to the Makefile (e.g. after the section

Code: Select all

## Create binary .hex file from the .out file

Code: Select all

### Create a .uf2 file from the .hex file
uf2: $(BUILD)/$(OUTPUT_FILENAME).uf2

$(BUILD)/$(OUTPUT_FILENAME).uf2: $(BUILD)/$(OUTPUT_FILENAME).hex
	$(ECHO) "Create $@"
	$(PYTHON3) $(TOP)/tools/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/$(OUTPUT_FILENAME).uf2" $^
and change the "all" target to

Code: Select all

all: binary uf2
the uf2 file is created automatically. "uf2conv.py" comes with the micropython distribution; no need to download.
Bernhard Boser

goku
Posts: 1
Joined: Sun Aug 15, 2021 10:22 pm

Re: nrf52480 build and flash

Post by goku » Mon Aug 16, 2021 6:50 am

Any chance someone could post a converted UF2 for Adafruit's nrf52480 boot loader?

Following the steps that ltmerlin outlined above.
I only made a minor edit for my Feather Sense's LED mapping vs ltmerlin's Feather Express.
However on copying flash.uf2 to my Feather Sense (0.6.1 Bootloader/ Soft Device S140 6.1.1), I'm only seeing LED1 blink rapidly, without USB CDC enumeration.

By default does MicroPython use the QSPI?
Does QSPI_FLASH_FILESYSTEM do anything?

Code: Select all

cd micropython
make -C mpy-cross

cd ports/nrf
./drivers/bluetooth/download_ble_stack.sh
make submodules
make BOARD=feather_sense SD=s140
cd build-feather_sense-s140
python3 ../../../tools/uf2conv.py firmware.hex -c -f 0xADA52840


I also tried using the Adafruit DFU with the same results.

Code: Select all

adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application firmware.hex firmware.zip
adafruit-nrfutil dfu serial --package firmware.zip -p /dev/usbmodem1101 -b 115200
Thanks!

Post Reply