Unique serial numbers for picoprobe#8
Conversation
| uint8_t nibble = (uID.id[bi] >> 4) & 0x0F; | ||
| uID.id[bi] <<= 4; | ||
| /* Binary to hex digit */ | ||
| usb_serial[i] = nibble < 10 ? nibble + '0' : nibble + 'A' - 10; |
There was a problem hiding this comment.
Or you could just use sprintf ?
There was a problem hiding this comment.
With a cast to uint64_t?
Yes, type punning would in this case be 100% safe (and even guaranteed by the standard), and printf is already brought in so that won't make much of a difference.
But, it will display the flash ID in reverse with respect to the "wire order". Not that it makes that much of a difference, I just find it weird.
Otherwise, it would be sprintf in a loop on the id[] array (quite an expensive thing) or a monster call (ugly), and not really any simpler in both cases - as you can see it's four simple lines.
There was a problem hiding this comment.
sprintf in a loop on the id[] array (quite an expensive thing)
With the Pico running at 133MHz, I guess I was just being lazy 😉
I believe fetching the flash-chip UID is only done once at startup? So any calls to |
Yes you are right! I was thinking of the underlying call. |
This PR (hinted at in the comments for #5) makes the USB serial number for each Picoprobe unique.
It will come handy for multi probe support in pyocd.
Code is very simple, a direct conversion of the flash unique ID to a C string.
As far as I can see, there's no need to bracket the call to
pico_get_unique_board_id();with disable/enable interrupt, as they seem not to be enabled (yet) whenusb_serial_init()is called.