-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add manner for grabbing unique Board ID/Serial Number #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looking to jump into contributing on this one. But, as this would be my first on this MASSIVE project, I have a couple questions.
In some preliminary research, I found the reference that @tannewt mentioned for Serial Number in USB. Page 44 of the SAMD21 datasheet says that its read from NVM:
Looks like it would be easiest to have the base call in |
Thanks for looking at this! |
Personally, I'd prefer it returning the four words as a list. I would also say that |
I agree that the outside call would be best in As I've gotten further into this, the first hurdle is getting NVM functions ( |
Regular CPython returns something like: Our general philosophy is to match the regular Python's libraries as much as we can, without enhancing or changing their API's, so that code can be ported more easily. If you can suggest an existing API call that returns a unique ID for the current machine, that would be great, but I'm not sure there is one. There are some ways to get a MAC address but they're not straightforward. The |
It's implemented only on the Express boards right now due to space considerations. |
@sommersoft I was thinking more of an |
Yeah,
Well, now I have a reason to buy a CPX. Now that they're out of stock, of course. Until then I'll see what kind of juice I can squeeze out of the Trinket M0. If any. Still a ways off before running anything anyway (at least at my pace). Also, the ESP8266 only has a CHIP_ID, which is the ending 24 bits of the MAC. Not "unique" per se, but closest you can get on that chip. I can work that, but if we make the nRF...out of my reach for now. |
A Feather M0 Express would also work. For the ESP8266, I think writing it as an |
What do you think your use cases would be for the UID? The basic integer type is 31 bits (including sign bit). Only some CircuitPython impls are going to provide long ints due to code space issues. So just a list of integers won't always work. Would an |
I'd prefer the ID be |
@dhalbert To be extremely specific, what I intend on doing is making an example for how Python can be modified without the need to recompile. To accomplish this, I wanted to have a way to have the device create a program unique to it, using the device ID. I would prefer a device ID call that returned the same data type and size regardless of MC |
As far as I can tell through digging in each boards' structures so far, the ESP8266 is the only one that currently even handles a
As you can see, they set it up as a QSTR, so is stored as EDIT # 3: Found it...scrolled right past it in
With regards to the size of the SAMD21 & 51 Now for more background information... LAST EDIT: For the SAMD51, For the nRF52832, Here is a link to Nordic's documentation: http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/ficr.html?cp=2_1_0_12#concept_xb5_mpx_vr Here is a link to the forum post I found on the subject: (EDIT: just noticed that this is referencing nRF 51x; I'll confirm if nRF52 is the same later) Between domestics and football, this is as far as I've gotten today. Apologize for the huge post... |
@sommersoft thank you for the hugely informative post! Could you explain how the The uid is scattered around memory on the SAMDs. The USB code uses it here. |
Ok..so that was part of my fear with that giant post. Info got a little fragmented. I'll see if I can give a clean explanation of where I THINK I am. (Found one mistake from yesterday. I was looking at the SAM_G_51 datasheet. So that info is garbage; I will correct it. SAMD51
Now, the reason I'm saying that the Now that I have all the "what's where" info, I'm going to layout a project on my fork and start working it. After looking at the USB code you referenced, it looks like that particular function is only setting the address locations of where the |
@sommersoft Thanks for doing all that research! The USB code does read the values, 4 bits at a time, on this line:
You don't need the |
So, this would be some of my inexperience showing with "foundational" C & MCU programming. After looking back without my biases, I see what you're saying.
Now, scrapping my |
After 4 different approaches, and this week's holiday break, I went back to zero and applied KISS. Previous iterations of trying to just return
result:
I'm assuming SAMD51 will work as well, just can't verify. The UID is short, obviously because |
I'm suspicious of it being that short. IIRC is only unique if its 64 or 128 bits. Could you adapt it to return a bytes string instead of an int? |
shared-bindings/microcontroller/Processor.c & .h: added UID lookup functionality for use with all ports. See Issue adafruit#462.
ports/atmel-samd/common-hal/microcontroller/Processor.c & .h: added UID lookup function for SAMD ports. See Issue adafruit#462.
SAMD To keep things standard, I'm now working on adding this to ESP8266 by calling the existing After that will come the nRF. I've got a board on the way, so hopefully we can get this issue closed out in a couple weeks. |
ESP8266
|
nRF done! PR imminent... |
shared-bindings/microcontroller/Processor.c & .h: added UID lookup functionality for use with all ports. See Issue adafruit#462.
ports/atmel-samd/common-hal/microcontroller/Processor.c & .h: added UID lookup function for SAMD ports. See Issue adafruit#462.
/ports/nrf/common-hal/microcontroller/Processor.c: add UID function. See Issue adafruit#462.
/shared-bindings/microcontroller/Processor.c: added a note to `microcontroller.cpu.uid` (Issue adafruit#462) that ``struct`` is not currently available on the nRF port.
Pulling a unique ID would be useful for an example I have in mind for #345 and @tannewt mentioned in Discord that a Serial Number was pulled for the USB code and that it may be able to be added somewhere.
Personal preference is
board.id()
but putting it inos
along withos.uname()
would make sense as well. Perhaps even more sense from a programming standpoint since that's where you get other board information from.The text was updated successfully, but these errors were encountered: