How to flash uf2 bootloader / circuitpython on pitaya go

Hello I’m trying to flash the uf2 bootloader on my pitaya go in order to install circuitpython but I’m having trouble.

If I try to flash this package Releases · adafruit/Adafruit_nRF52_Bootloader · GitHub using this command adafruit-nrfutil dfu serial -pkg pitaya_go_bootloader-0.6.1_s140_6.1.1.zip -p /dev/ttyACM0 -b 115200 I get a serial.serialutil.PortNotOpenError: Attempting to use a port that is not open error

If I use the nrf programmer desktop application and try to write pitaya_go_bootloader-0.6.1_s140_6.1.1.hex from Releases · adafruit/Adafruit_nRF52_Bootloader · GitHub I get a DFU failed: Error message for known extended error code from DFU target: The init packet does not contain a signature. This bootloader requires DFU updates to be signed. error

Do you know how can I sign the hex / successfully flash the uf2 bootloader ?

You shouldn’t need to sign anything if you’re replacing the bootloader. You can use pyocd to program the UF2 bootloader by itself, rather than nrfutil, though both should work.

nrfutil is trying to actually use the DFU functionality of the bootloader that’s already present when you see that second error you speak of. The first error is more of the clue though, because I see you’re trying to actually use the dfu command in that. You’ll want to use SWD to flash at least the bootloader, because that will write to the raw flash of the NRF52840. The bootloader’s DFU mode is designed to just write the “user application” area, not the bootloader itself, (if I recall correctly, it’s been a good bit since I’ve looked at that code.) Do you have a Pitaya Link or other similar SWD programmer?

Here’s how you can flash the NRF52 with nrfutil over SWD:

$ adafruit-nrfutil -f nrf52 --eraseall # wipe the NRF52840
$ adafruit-nrfutil --program "pitaya_go_bootloader_0.6.1_s140_6.1.1.hex" -f nrf52 --sectorerase --reset

After that, you should be able to boot up in the bootloader mode (it should boot there automatically, blinking the LED red while it is), and drop your CircuitPython UF2 file on the ‘Drive’.

One last thing that can be a real gotcha:

Adafruit’s bootloader will look for specific bits for checksum verification before it’ll launch your application image too, so you’ll want to write a value that says “my app is valid” to the UICRs. I’m not sure of what exactly the arguments are to do it with nrfutil, but here’s how I do it with pyocd

$ pyocd cmd -t nrf52840 --command w32 0xFF000 0x00000001 --command reset

I’m sure nrfutil has a similar functionality, but the gist is you want to write the 32 bit value of 1 to 0xFF000. After that value is there, the UF2 bootloader will skip the checksum verification of the application image, and boot right to it regardless.

Hope this helps.