makeuf2

Overview

makeuf2 is a Python program that

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

The transmogrification chops up the binary into 256 bytes blocks, inserting the required headers. For the RP2040, it also prepends the required check-summed 256 byte code block that initialises the QSPI interface to the flash memory for Execute in Place, while for the RP2350 it adds the necessary meta data.

See section Start-up for more details.

The Python version used to develop the program is 3.12.

The boot code block for the RP2040 is provided in file boot2.uf2 in the tools directory.

Installation for Command Line Usage

This is how I install and run makeuf2:

  • put makeuf2.py and boot2.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).

Command Line Usage

Running

> python -m makeuf2 -h

prints

usage: makeuf2 [-h] [-v] {rp2040,rp2350} ...

options:
  -h, --help       show this help message and exit
  -v               verbose, print feedback

commands:
  {rp2040,rp2350}
    rp2040         create UF2 binary for RP2040/Pico, optionally upload
    rp2350         create UF2 binary for RP2350/Pico2, optionally upload

That is, there’s a sub-command for each supported MCU, rp2040 and rp2350, respectively.

Running

> python -m makeuf2 rp2040 -h

prints

usage: makeuf2 rp2040 [-h] [-d DRIVE] [-b BOOT2_FILE] [-f FLASH_SIZE] [-u] bin_file

positional arguments:
  bin_file       binary file (.bin)

options:
  -h, --help     show this help message and exit
  -d DRIVE       upload drive, eg. E:
  -b BOOT2_FILE  bootstage 2 file, default: boot2.uf2 in installation directory
  -f FLASH_SIZE  flash memory size in hexadecimal, default: 0x200000
  -u             upload to drive 'RP2040' ('-d' takes precedence), experimental

If option -d is specified, makeuf2 will attempt to upload the UF2 file to the Pico, which must be in BOOTSEL mode.

Option -b allows to specify an alternative boot file, and -f can be used for boards that offer more than the Pico’s 2MB of flash memory.

Option -u is an experimental feature that allows to omit a specific drive letter using option -d, but instead makeuf2 looks for the drive by name, which is handy if the drive letter changes.

Running

> python -m makeuf2 rp2350 -h

prints

usage: makeuf2 rp2350 [-h] [-d DRIVE] [-f FLASH_SIZE] [-u] bin_file

positional arguments:
  bin_file       binary file (.bin)

options:
  -h, --help     show this help message and exit
  -d DRIVE       upload drive, eg. E:
  -f FLASH_SIZE  flash memory size in hexadecimal, default: 0x400000
  -u             upload to drive 'RP2350' ('-d' takes precedence), experiment

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

> python -m makeuf2 rp2040 BlinkPlus.bin -d F:

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

Installation in Astrobe’s Tool Menu

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

For RP2040:

[Command3]
MenuItem=Create and Upload UF2 (RP2040)
Path=C:\Users\gray\AppData\Local\Programs\Python\Python312\python.exe
Parameters=-m makeuf2 rp2040 %FileDir%\%FileRoot%.bin -d F:
WorkingFolder=%FileDir%
ConsoleApp=TRUE
Prompt=FALSE

For RP2350:

[Command4]
MenuItem=Create and Upload UF2 (RP2350)
Path=C:\Users\gray\AppData\Local\Programs\Python\Python312\python.exe
Parameters=-m makeuf2 rp2350 %FileDir%\%FileRoot%.bin -d E:
WorkingFolder=%FileDir%
ConsoleApp=TRUE
Prompt=FALSE

Tools Menu Usage

With the program module in the foremost Astrobe editor window, after successfully building, select the corresponding menu item from the Tools menu. If you use the -d or -u option, don’t forget to put the Pico into BOOTSEL mode before running makeuf2 with uploading.1

Astrobe IDE

  • Use makeuf2 rp2040 and makeuf2 rp2350 with Astrobe for RP2040 and for Cortex-M0.
  • Use only makeuf2 rp2350 with Astrobe for RP2350, for Cortex-M3, and for Cortex-M4.

Astrobe Configuration

Astrobe for RP2040 and for RP2350 create UF2 files directly – a few notes.

  • The UF2 file created by Astrobe for RP2040 is binary equal to the UF2 files created using makeuf2 rp2040 from .bin files generated by Astrobe for Astrobe for RP2040 and for Cortex-M0.
  • The UF2 file created by Astrobe for RP2350 is not binary equal to the UF2 files created using makeuf2 rp2350, due to a different approach regarding the placement of the meta data, see Start-up. It’s important to set the code start address to 010000000H when using the UF2 file created by Astrobe for RP2350, but a value of 010000100H when using makeuf2 rp2350. The config files in the repo indicate this selection by c000H or c100H, respectively, in the file name, and a corresponding entry in the description.

Outlook

The RP2350 can be configured in different ways as regards the placement, segmentation, etc. of the uploaded UF2 binaries. This requires closer exploration. makeuf2 will be extended accordingly.

The meta data block for the RP2350 is hardcoded in the tool for the time being. With the extensions, the meta data will be read from a configuration file, which can be project-specific.

Repository


  1. Do yourself a big favour and wire up a reset button to the RP’s RUN pin if you use a board without one, such as the Pico or Pico 2. ↩︎