raspberrypi / picotool

BSD 3-Clause "New" or "Revised" License
525 stars 86 forks source link

Feature: Target devices by it's unique ID #54

Open ggsubs opened 1 year ago

ggsubs commented 1 year ago

Feature request: Target devices by their unique ID, so that I can work with multiple devices connected at the same time, while allowing the USB port connections to change.

The unique id is available on the SDK (pico_get_unique_board_id), the same string is exposed on the device descriptor.

ggsubs commented 1 year ago

Example: lsusb -v output shows iSerial value:

Bus 002 Device 004: ID 2e8a:000a  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x2e8a 
  idProduct          0x000a 
  bcdDevice            1.00
  iManufacturer           1 Raspberry Pi
  iProduct                2 Pico
  iSerial                 3 E66038B713249237
  bNumConfigurations      1

The following snippet shows how to get the unique ID: libusb_get_string_descriptor_ascii( deviceHandle, deviceDescriptor.iSerialNumber, stringBuff, stringBuffLen)

neilenns commented 1 year ago

Yes, this would be excellent. I opened similar issues a while back (https://github.com/raspberrypi/picotool/issues/48) and despite how I closed that issue I actually never solved my problem. I couldn't find any way to programmatically reference an RP2040 device and flash it using picotool.

lurch commented 1 year ago

I guess this ties up closely with #12 (since the ID returned by pico_get_unique_board_id is the flash-chip's unique ID.

Ferdi265 commented 1 year ago

I have created a very experimental branch here that provides a --serial option for selecting devices, as well as --multiple for e.g., rebooting multiple devices into BOOTSEL mode at once.

The branch is pretty experimental, but it simplifies the workflow for working with multiple picos by a lot.

For example:

picotool load server.uf2 --serial $SERVER_SERIAL -f
picotool load client.uf2 --serial $CLIENT_SERIAL -f

will correctly reboot two specific picos into BOOTSEL mode, flash them, and reboot them back into application mode. I'm still cleaning up the branch, but I hope I will have something quite usable in a week or two.