Programming Pi Pico from Host (getting into Bootmode without user interaction)

Hi

I am working on a new project and exploring the Pi Pico board. I am doing the programming in Arduino IDE.

Essentially, the Pi Pico will be connected to a RPI 4 running a Yocto build of Linux. I don't have the expertise to further develop the Yocto build and include additional packages/builds. So, I can't install new tools (eg. Picotool) . In addition, the Pi Pico will be embedded (ie. I can't ask the user to open the system and press the BootSel button when I need to update code on the Pi Pico).

What I am trying to achieve: I want to be able to update the program running on the Pi Pico from the RPI 4 without user intervention or having to install new tools for the host Linux build.

I have done extensive reading and this is my understanding in terms of options:

  • [not an option] Adruino or other IDE can be used to program but requires the software to be installed on the (Windows only???) host.

  • [not an option] Programming can be done using SWD. This requires additional software to be installed on the Linux host and additional pins for the interface.

  • [not an option] I could write or use one of the already written bootloaders that upload new code via UART. This is a bit too complex and time is better spent elsewhere (eg. here is an example if anyone is interested Pico serial bootloader • Brian Starkey)

  • [selected method] Programming can be done by getting the Pi Pico into bootloader mode which results in it appearing as a USB drive. A UF2 file can be copied to the drive. The Pi Pico will then flash itself and reboot. I have learnt how to create the UF2 from the bin/elf file generated by the Arduino IDE thanks to the help on this forum (see post Pi Pico - Generating Uf2 from Bin)

So the issue now becomes how to get the board into bootmode without user intervention (ie. no disconnecting the USB cable or pressing the bootsel button):

Options:

  • [tested and works] Setting the baud address of the Pi Pico serial port on the host to 1200 baud. This functionality exists without having to include anything in my code so I assume it is added automatically?

    This can be done in Linux as follows [not tested by myself]: sudo stty -F /dev/ttyACM0 1200

    This can be done in Windows using the cmd as follows [tested by myself]: Mode Com14: Baud=1200 Parity=N Data=8 Stop=1

    (change COM port as appropriate for your system)

  • [tested and works] Programatically by adding the following code to my Arduino code:

    extern "C" {
    #include "pico.h"
    #include "pico/time.h"
    #include "pico/bootrom.h"
    }

    reset_usb_boot(1<<PICO_DEFAULT_LED_PIN,0); //invokes reset into bootloader mode

  • [not tested] Resetting twice within 200ms. I believe this is referred to as "double-tap". Does this mean that if bring the RUN pin low on the PI Pico twice within 200ms it will invoke the bootloader mode? Does this exist already in the code (already linked in) or do I have to add code to make this available to my program?

  • [not tested] USB Vendor Reset. If I understand correctly, there is a USB Vendor ID that can be used to reset the Pi Pico. How can I do this? In Windows, I can inspect the USB registers by looking at the properties in Device Manager. Which register do I adjust to invoke the bootloader? And how can I achieve same in Linux from the command line?

Thank to all in advance.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.