emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 5:27 pm

Newly released Pico utilities and docs are IMO superbly well done. The PDFs are specially top notch for ARM and believe me, I've muddled through a few from the likes of ST, NXP, Cypress, etc. Amazing for a first go.

However not everyone is as enthusiastic about the 'double fisted' button pushing game to download via MSD as hinted at here: viewtopic.php?f=144&t=299746

GDB/OOCD debug environment works great for serious development but somewhat overkill for the things I want to do at this stage. Also the bloaty-bloat nature of these utilities can more than double disk resources. A friend actually binned his new Pico as a result because he would need to buy a new SD (among other more minor issues).

My personal long term goal was to integrate into Geany like I've done with other MCU families and GCC for Pi itself. Works fine just clicking on EXECUTE or BUILD w/o further actions. Specially helpful eliminating the button pushing part.




METHOD #1
--------------------

Half as many cables as SWD approach and no software other than UF2 file to flash but needs cap on TP6.

First step was to eliminate the two button requirement by putting a bypass cap on TP6 as seen in the photo below. Now a short negative pulse on 3V3_EN will immediately put Pico in MSD mode instead of having to hold down BOOTSEL while unplug-plug as docs indicate. Unplug-plug also boots into MSD mode now but, in addition to wear and tear reliability issues, strikes me as just plain lame.

Connecting the other end to a Pi pin (GPIO7 in my example) allows this w/o having to push any buttons at all. Easy to do from command line, a script, or program using WiringPi or the excellent pigpio utility. I chose the latter because that insane Arduino pin numbering just drives me up the wall.

For a simple demo you can just follow the Getting Started Guide for BLINK.C up to 'make -j4' then enter the following:

Code: Select all

sudo pigpiod #once/pi boot
sleep 1 #wait else socket fail
pigs w 7 0 #loop back here
sleep 0.1
pigs w 7 1
sleep 6 #msd can take 3-5s, less w/o auto-mount
sudo cp ~/pico/pico-examples/build/blink/blink.uf2 /media/pi/RPI-RP2
sleep is there only if doing it from a script. I currently have this working with Geany but it does take a few seconds (better than minutes, hours, or even DAYS most Linux hackers are used to) so room to streamline.

Anyway here's mine. Shorting block is only for convenience to undo the mod and note that the RUN button still works as before to restart the program w/o reload. NBB definitely qualifies as Poor Man's project with total cost under 5 cents.

viewtopic.php?t=300851&p=1807255#p1807255
pico_bot2.JPG
pico_bot2.JPG (74.74 KiB) Viewed 6115 times


METHOD #2
--------------------

No cap but uses twice the cables compared to METHOD #1 and needs full OOCD software installed. Much faster, specially with auto-mount enabled. Thanks to fivdi showing how to use OOCD from command line.

Connect SWD and 5v power as shown in photo below. You could also use USB for power instead. Like before follow Getting Started Guide up to the 'make -j4' step then from CLI:

Code: Select all

openocd -f interface/raspberrypi-swd.cfg -f target/rp2040.cfg -c "targets rp2040.core0; program blink.elf reset exit"
pico_swd.JPG
pico_swd.JPG (125.68 KiB) Viewed 5297 times



Edited 2/22/2021 added SWD no button boot method.
Edited 2/3/2021 to eliminate nasty mount steps and improve safety by using /media/pi/RPI-RP2. Also forgot to include pigpiod and new photo to better indicate pin usage.
Last edited by emma1997 on Tue Feb 23, 2021 5:25 am, edited 16 times in total.

ejolson
Posts: 10249
Joined: Tue Mar 18, 2014 11:47 am

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 5:53 pm

Sorry to be clueless, but I don't see a wire in the picture from the Pico that connects to GPIO 7 on the Pi 4. Where does it attach?

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:03 pm

Yes, that pic was from last week when I first got this running so the wire not shown yet. As indicated you would connect Pico 3V3_EN (pin 37) to Pi GPIO7 (pin 26). Power/ground obviously already taken care of by the USB cable.

But thanks for mentioning this and I will take some more pics when schedule allows. Every little bit helps when forging into new territory.

BTW doesn't have to be Pi4. For yucks I tried on a few older models. Molasses is like a bolt of lightening by comparison.

I would love to skip the whole /dev mount step and go direct as hinted above. Would probably speed thing up big time.
Last edited by emma1997 on Wed Feb 03, 2021 6:45 pm, edited 2 times in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 31859
Joined: Sat Jul 30, 2011 7:41 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:07 pm

He binned a Pico because he didn't want to install stuff on his SD card or buy a new one? You have strange friends!

And I would heartily recommend using SWD/OpenOCD from first principles, it just saves so much faffing about. I did about three MSD uploads before I moved to SWD, it was so much faster. I'm really not seeing why people are so reluctant to use it. Maybe its just because I am used to having a debugger when modifying the Videocore firmware that I deem them vital.
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

cleverca22
Posts: 6828
Joined: Sat Aug 18, 2012 2:33 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:13 pm

emma1997 wrote:
Tue Feb 02, 2021 5:27 pm
For one thing the "cat blink.uf2 > /dev/sdX" suggestion from cleverca22 seems quite useful. He mentions 'root only' but I still get permission errors with sudo so IDK. Anybody got a clue?
thats because the > is handled before sudo is ran, "sudo cat blink.uf2 > /dev/sdX" only runs cat as root, and nothing else

you instead want something like:

Code: Select all

sudo sh -c "cat blink.uf2 > /dev/sdX"
one idea i was considering, was to make a udev rule, that would detect the pico device being inserted, and immediately cat /home/pi/default.uf2 into it
then you just update the default.uf2 symlink depending on what your working on today, and it will auto-program any pico it detects


but ive now got SWD working, and its far simpler to just run "load blink.elf" in gdb instead

GregAC
Posts: 53
Joined: Sun Aug 17, 2014 9:48 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:14 pm

I'm really not seeing why people are so reluctant to use it.
I'm also a bit puzzled by the reluctance over using it.

@emma1997's little mod is nice but seems like more faff than connecting up SWD (or equivalent, they both need soldering but getting the capacitor soldered onto the testpad sounds more fiddly then soldering a header into pre-drilled hole). You can buy jumper wires or make them up yourself easily and you do after all still need one for this mod.
Last edited by GregAC on Tue Feb 02, 2021 6:25 pm, edited 1 time in total.

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:21 pm

jamesh wrote:
Tue Feb 02, 2021 6:07 pm
He binned a Pico because he didn't want to install stuff on his SD card or buy a new one? You have strange friends!
True, but then again I am considered strange myself by just about everybody who knows me. IME one of my greatest advantages in life. lol
jamesh wrote:
Tue Feb 02, 2021 6:07 pm
And I would heartily recommend using SWD/OpenOCD from first principles, it just saves so much faffing about. I did about three MSD uploads before I moved to SWD, it was so much faster. I'm really not seeing why people are so reluctant to use it. Maybe its just because I am used to having a debugger when modifying the Videocore firmware that I deem them vital.
I did have great luck first time with GDB/OCD thanks to excellent Pico guide but for what I want now (Geany integration) this probably won't do.

My theory is that those who have zero experience with streamlined methods like Arduino (won't mention any names, lol) simply don't know how wonderful life can be outside Eclipse/Netbeans/VS etc. Life is too short to dick around with menus and project settings for hobby use when we can just one click or key. Agreed this is not appropriate for serious commercial development. If getting paid I would certainly take advantage of the high end toolsets but I'm not so I won't.

BTW I will add that the I personally have a STRONG dislike for the Arduino IDE itself and prefer to extract only those features working to my advantage (AVRdude!). It's sometimes the quickest route to getting some sensor or module going so I have to use it but don't have to like it.

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:36 pm

cleverca22 wrote:
Tue Feb 02, 2021 6:13 pm
you instead want something like:

Code: Select all

sudo sh -c "cat blink.uf2 > /dev/sdX"
Thanks for that. I wish I had a fraction the experience of guys like you and the other regulars here. It will be first on my list when I get physical access to that setup. Will take more pics too so ej will be happy. lol

It would be greatly appreciated if this did not degrade into another ide-war like those other threads. No mention of 'real' toolsets please unless there is some way to integrate into Geany.

I have literally dozens of those up and running on my PC. Snappy, productive, and everything you say is true but not for this use case. They allow me to do what must be done (ie debugging for pay) but none are suited for hobby use on my Pi ATM. I am dong this Pico stuff for fun and unlike most here do not live, breath, sleep, and shower, clutching gigabyte dev sys.

I would prefer not to have this thread locked as several friends stuck out here in the real world with me are now playing with Pico and depend on the kindergarden type methods espoused.

ejolson
Posts: 10249
Joined: Tue Mar 18, 2014 11:47 am

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 6:56 pm

emma1997 wrote:
Tue Feb 02, 2021 6:36 pm
cleverca22 wrote:
Tue Feb 02, 2021 6:13 pm
you instead want something like:

Code: Select all

sudo sh -c "cat blink.uf2 > /dev/sdX"
Thanks for that. I wish I had a fraction the experience of guys like you and the other regulars here. It will be first on my list when I get physical access to that setup. Will take more pics too so ej will be happy. lol
I think the simplicity of

Code: Select all

sudo dd if=blink.uf2 of=/dev/sdX
is one reason dd opens the output device using its own process privileges. Note that mounting the fake filesystem and copying the file is less likely to overwrite the root filesystem on a Linux PC.

User avatar
HermannSW
Posts: 5426
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: Poor Man's Pico No-Button-Boot (NBB)

Tue Feb 02, 2021 10:19 pm

After doing "make" in build directory, I typically do these steps for flashing:
  1. disconnect USB cable, press bootsel and reconnect USB cable
  2. wait until fake filesystem popup opens
  3. press ESC
  4. cp blink.uf2 /media/pi/RPI-RP2/
  5. minicom -b 115200 -o -D /dev/ttyACM0
Not perfect, but fast.
https://hermann-sw.github.io/planar_graph_playground
https://stamm-wilbrandt.de/en#raspcatbt
https://github.com/Hermann-SW/memrun
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/en/Raspberry_camera.html

cleverca22
Posts: 6828
Joined: Sat Aug 18, 2012 2:33 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 1:12 am

HermannSW wrote:
Tue Feb 02, 2021 10:19 pm
After doing "make" in build directory, I typically do these steps for flashing:
  1. disconnect USB cable, press bootsel and reconnect USB cable
  2. wait until fake filesystem popup opens
  3. press ESC
  4. cp blink.uf2 /media/pi/RPI-RP2/
  5. minicom -b 115200 -o -D /dev/ttyACM0
Not perfect, but fast.
once you get openocd+gdb setup, you can run make, then do the following:

Code: Select all

(gdb) load ~/apps/rpi/pico/pico-examples/build2/hello_world/usb/hello_usb.elf
Loading section .boot2, size 0x100 lma 0x10000000
Loading section .text, size 0x6e78 lma 0x10000100
Loading section .rodata, size 0x5b0 lma 0x10006f78
Loading section .binary_info, size 0x20 lma 0x10007528
Loading section .data, size 0xaa4 lma 0x10007548
Start address 0x10000104, load size 32748
Transfer rate: 41 KB/sec, 5458 bytes/write.
condition  continue
(gdb) continue
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: new full-speed USB device number 50 using ohci-pci
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: New USB device found, idVendor=2e8a, idProduct=000a, bcdDevice= 1.00
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: Product: Pico
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: Manufacturer: Raspberry Pi
Jan 30 11:42:26 amd-nixos kernel: usb 13-2: SerialNumber: 000000000000
Jan 30 11:42:26 amd-nixos kernel: cdc_acm 13-2:1.0: ttyACM0: USB ACM device
no need to touch any usb cable or the bootsel button

WestfW
Posts: 238
Joined: Tue Nov 01, 2011 9:56 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 3:12 am

It looks like it should be pretty trivial to add a "single button reboot" to to the SDK, using pretty much any gpio you're not using for something else.
Would that solve most of the objections to the "too difficult to get into boot mode" complaints?

ejolson
Posts: 10249
Joined: Tue Mar 18, 2014 11:47 am

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 3:48 am

WestfW wrote:
Wed Feb 03, 2021 3:12 am
It looks like it should be pretty trivial to add a "single button reboot" to to the SDK, using pretty much any gpio you're not using for something else.
Would that solve most of the objections to the "too difficult to get into boot mode" complaints?
It's a curious problem. On one hand the Pico is designed for connecting wires, on the other hand it may be unwise if the first soldering a student in 5th standard does is to solder a capacitor directly to the back side of a Pico.

incognitum
Posts: 1124
Joined: Tue Oct 30, 2018 3:34 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 3:00 pm

WestfW wrote:
Wed Feb 03, 2021 3:12 am
It looks like it should be pretty trivial to add a "single button reboot" to to the SDK, using pretty much any gpio you're not using for something else.
Would that solve most of the objections to the "too difficult to get into boot mode" complaints?
Would require a button.

Wouldn't it be possible to just listen on USB for a command to reset to flash mode?

As in:
- offer a stdio_init_all_and_listen_for_reflash_command() function in the SDK, that people could call at the start of their programs.
- this would setup the stdio_usb stuff, and in addition use the functionality TinyUSB already seems to have to invoke a callback on receiving a special character (e.g. \0 ) ( https://github.com/hathach/tinyusb/blob ... vice.h#L69 )
- that callback would have to do whatever is necessary to reboot to flash mode (e.g. erase first flash page so there is no valid program, and reboot?)
- could then reset to flash mode by sending the special char to the USB, by running on the host system something among the lines of: printf "\0" > /dev/ttyACM0

Or am I thinking too simple?

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 4:16 pm

To reiterate my goal here was to flash with a script to make possible integration into the Geany editor using EXECUTE or BUILD button. Apparently achieved.

I did get all the suggestions working but seems like Hermann's is best so far. Most useful is /media/pi/RPI-RP2 instead of /dev/sdb1 resulting in major improvement in safety. I've also determined cp is better due to mysterious half minute delay with cat or dd.

So total cycle time is now 6s instead of my 28s first attempt. 90% of time now is waiting for Pico to install as MSD so not sure any improvement possible. Also no need anymore for my silly C program to bump partition letters.

I also need to update 1st post to activate pigpiod sockets which I forgot to include before. Lots of confusion for non-expert Linux appliance user like me. Once I figured out what has to run every new terminal session, or once per Pi boot, or once PERIOD then things went much smoother. All-in-all quite satisfied with the way it's turning out. Easy now to flash from script or CLI w/o any buttons or OOCD.


WestfW wrote:
Wed Feb 03, 2021 3:12 am
It looks like it should be pretty trivial to add a "single button reboot" to to the SDK, using pretty much any gpio you're not using for something else.
That's pretty much what I did. Note however that single button operation is only possible with a bypass cap on BOOTSEL. Otherwise you'd need one for RUN pin too. My use of a random GPIO on PI is icing on the cake to get button pushing down to zero.

I understand why you might show interest here being one of the top bootloader experts on the planet. Last week my plan was to implement something like opti for Pico but then realized it would still involve thousands of button pushes to get that going. Also probably dozens of Arduinoids simultaneously trying to get this done ATM for that IDE so I'd be duplicating effort.

Glad I decided to take a different tact with help from experts here. Thanks people.

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1342
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 8:20 pm

note you can use

Code: Select all

picotool load -x <binary>
to load an execute your binary (if the Pico is in BOOTSEL mode) - you don't need to mount the drive and it is not dangerous like the dd

ejolson
Posts: 10249
Joined: Tue Mar 18, 2014 11:47 am

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 11:43 pm

emma1997 wrote:
Tue Feb 02, 2021 5:27 pm
GDB/OOCD works great for serious development but somewhat overkill for the things I want to do at this stage. Also the bloaty-bloat nature of these utilities can more than double disk resources. A friend actually binned his new Pico as a result because he would need to buy a new SD (among other more minor issues).
If someone wanted to install all the Pico development tools on a Pi 4, would a 32GB SD card be enough?

cleverca22
Posts: 6828
Joined: Sat Aug 18, 2012 2:33 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Wed Feb 03, 2021 11:57 pm

ejolson wrote:
Wed Feb 03, 2021 11:43 pm
If someone wanted to install all the Pico development tools on a Pi 4, would a 32GB SD card be enough?
ive made it all fit on an 8gig SD card

User avatar
led-bloon
Posts: 26
Joined: Mon Dec 03, 2012 4:48 am
Location: Oz

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 12:25 am

I prefer to use the "two button turn-around". On/off switch using 3V3_EN pin & GND, and, the BOOTSEL switch.
I also like the "dd" upload (thanks ejolson).
The "fix" for the large upload time: switch off auto-mount!

Findecanor
Posts: 18
Joined: Tue Jan 26, 2021 2:29 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 9:42 am

Pardon my ignorance, but would it not be possible to use some inline assembly to jump to the bootloader?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 31859
Joined: Sat Jul 30, 2011 7:41 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 12:14 pm

led-bloon wrote:
Thu Feb 04, 2021 12:25 am
I prefer to use the "two button turn-around". On/off switch using 3V3_EN pin & GND, and, the BOOTSEL switch.
I also like the "dd" upload (thanks ejolson).
The "fix" for the large upload time: switch off auto-mount!
I prefer to use SWD, no button presses required at all!
Principal Software Engineer at Raspberry Pi Ltd.
Working in the Applications Team.

cleverca22
Posts: 6828
Joined: Sat Aug 18, 2012 2:33 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 3:20 pm

Findecanor wrote:
Thu Feb 04, 2021 9:42 am
Pardon my ignorance, but would it not be possible to use some inline assembly to jump to the bootloader?
theres a function for just that!

Code: Select all

/*!
 * \brief Reboot the device into BOOTSEL mode
 * \ingroup pico_bootrom
 *
 * This function reboots the device into the BOOTSEL mode ('usb boot").
 *
 * Facilities are provided to enable an "activity light" via GPIO attached LED for the USB Mass Storage Device,
 * and to limit the USB interfaces exposed.
 *
 * \param usb_activity_gpio_pin_mask 0 No pins are used as per a cold boot. Otherwise a single bit set indicating which
 *                               GPIO pin should be set to output and raised whenever there is mass storage activity
 *                               from the host.
 * \param disable_interface_mask value to control exposed interfaces
 *  - 0 To enable both interfaces (as per a cold boot)
 *  - 1 To disable the USB Mass Storage Interface
 *  - 2 To disable the USB PICOBOOT Interface
 */
static inline void __attribute__((noreturn)) reset_usb_boot(uint32_t usb_activity_gpio_pin_mask,
                                                            uint32_t disable_interface_mask) {

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 4:56 pm

kilograham wrote:
Wed Feb 03, 2021 8:20 pm
note you can use

Code: Select all

picotool load -x <binary>
to load an execute your binary (if the Pico is in BOOTSEL mode) - you don't need to mount the drive and it is not dangerous like the dd
That would be a very useful feature but after hitting BOOTSEL and entering:

Code: Select all

$ picotool load -x ~/pico/pico-examples/build/blink/blink.uf2

No accessible RP2040 devices in BOOTSEL mode were found.
but:
Device at bus 1, address 9 appears to be a RP2040 device in BOOTSEL mode, but picotool was unable to connect
The message seems to be in character for typical Linux devs known for being great practical jokers. I looked at help, specially load command but no hint there either. The same setup/path works fine with drag and drop and post #1 trick.

What could I be doing wrong?

cleverca22
Posts: 6828
Joined: Sat Aug 18, 2012 2:33 pm

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 5:30 pm

emma1997 wrote:
Thu Feb 04, 2021 4:56 pm
That would be a very useful feature but after hitting BOOTSEL and entering:

Code: Select all

$ picotool load -x ~/pico/pico-examples/build/blink/blink.uf2

No accessible RP2040 devices in BOOTSEL mode were found.
but:
Device at bus 1, address 9 appears to be a RP2040 device in BOOTSEL mode, but picotool was unable to connect
The message seems to be in character for typical Linux devs known for being great practical jokers. I looked at help, specially load command but no hint there either. The same setup/path works fine with drag and drop and post #1 trick.

What could I be doing wrong?
you need to either use udev rules to give yourself permission to the node, or run picotool as root

emma1997
Posts: 1737
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pico No-Button-Boot (NBB)

Thu Feb 04, 2021 5:34 pm

Of course. Deja Vu all over again. Thanks for bailing out my butt one more time. Kinda funny the message said :

"No RP2040 devices in BOOTSEL mode were found."

followed by:

"appears to be a RP2040 device in BOOTSEL mode"

Like I said, great practical jokers. I suppose a refreshing change from those annoying 'permission' scoldings. lol

Return to “General”