abin2uf2

Overview

abin2uf2 is a Python program (script?) that

  • transmogrifies Astrobe’s .bin file into UF2 format,
  • can directly upload the UF2 file to the Pico.

The transmogrification has two aspects:

  • chop up the binary into 256 bytes blocks, inserting the required headers, and
  • prepend the required code for the second boot phase of the RP2040.

The program consists of two files, namely the Python program itself, plus the UF2 binary with the boot code (bootstage2.uf2).

Installation for Command Line Usage

I am not a Pythonista, so this may well not be the “right” way to do it.

  • Put abin2uf2.py and bootstage2.uf2 into any directory, which must be on $PYTHONPATH.
  • One possibility is to leave the two files in their directory in the repo structure, so you get and “install” any updates automatically. Just put the directory on $PYTHONPATH.
  • Run the program with the -m option for Python (without the .py extension).

Hence, to transmogrify one of the examples, I run in the Windows PowerShell, assuming the Pico’s drive is ‘F:’:

PS python -m abin2uf2 BlinkPlus.bin -d F:

Of course you can copy the UF2 file manually to the Pico’s drive, without using the -d option.

Running

PS python -m abin2uf2 -h

prints

usage: abin2uf2.py [-h] [-v] [-o OFN] [-l LFN] [-d DRV] ifn

positional arguments:
  ifn                  input file (binary)

options:
  -h, --help           show this help message and exit
  -v, --verbose        print too much feedback
  -o OFN, --ofn OFN    output file (uf2), default: ifn.uf2
  -l LFN, --lfn LFN    bootstage 2 file (uf2), default: 'bootstage2.uf2'
  -d DRV, --drive DRV  install drive, eg. 'F:'

Installation for Astrobe’s Tool Menu

Install as outlined above, then add this – mutatis mutandis – to your Tools.ini file in the Astrobe configs folder:

[Command3]
MenuItem=Create and Upload &UF2
Path=C:\Users\gray\AppData\Local\Microsoft\WindowsApps\python.exe
Parameters=-m abin2uf2 %FileDir%\%FileRoot%.bin -d F:
WorkingFolder=%FileDir%
ConsoleApp=TRUE
Prompt=FALSE

The drive letter is “hard-coded”, since I don’t want to enter it with the parameter dialog of Astrobe again and again, and the Pico always appears at the same letter on my machine. I am sure it would be possible to extend the Python program to search for the Pico’s drive name (it’s RPI-RP2), ie. not the drive letter, but I haven’t found the time for this yet.

BOOTSEL

Don’t forget to put the Pico into BOOTSEL mode before running abin2uf2 with uploading, ie. by using option -d.

Do yourself a big favour and wire up a reset button to the RP2040’s RUN pin if you use a board without one, such as the Pico.

Repository