Python script: watch for RP2040 bootloader and copy firmware (button)

Here’s a Python script for Windows that watches for the RP2040 bootloader to connect, then copies a firmware file from the build folder.

Combine this with a button.scr script that jumps to bootloader, and firmware can be updated by pressing the button. This has been a really nice improvement when I’m not developing with a debugger.

A Linux version using pyudev is easier.

Python script

Script shamelessly pulled from here, with only small modifications. (2.1 KB)

def backup(drive: Drive):
    if drive.label != 'RPI-RP2':
        return'RP2040 bootloader has been plugged in')'Copying firmware to {drive.letter}')
    shutil.copyfile(r'C:\buspirate5-firmware\build\bus_pirate5_rev10.uf2', drive.letter + '\\firmware.uf2')

Set the location of your build folder on line 135.

The script cannot be ctrl-c exited, so there’s that.


# Jump to bootloader

Add the jump to bootloader command to a file called button.scr in the root folder of the Bus Pirate disk. Now pressing the button will activate the bootloader.