Skip to content

Added Unique ID Functions/Updated Support Matrix #527

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

Merged
merged 15 commits into from
Jan 18, 2018

Conversation

sommersoft
Copy link

@sommersoft sommersoft commented Jan 15, 2018

/shared-bindings/index.rst: updated Support Matrix format as discussed in PR #503 & Issue #448.

Issue #462 :
/shared-bindings/microcontroller/Processor.x:

  • Added functionality for retrieving the unique identifiers for all ports that support it.
  • Sphinx-rST documentation is in place, to include a note that the nRF port does not currently include struct for bytearray unpacking.

/ports/XXXX/common-hal/microcontroller/Processor.x:

  • Added functions to retreive unique identifiers for the following ports: SAMDxx, ESP8266, and nRF5x.
  • SAMD21 and SAMD51 use different memory addresses (handled in the function), whereas the nRF51x and nRF52x use the same memory addresses. ESP8266 uses the same functionality as machine.unique_id (which is still available).

P.S. I apologize for the merges/etc...trying to minimize the squashes necessary. Not sure I made that mark...

@sommersoft
Copy link
Author

Hold of on merging. Just compiled on my new Feather M0 Express, and I'm getting some weird results:


Adafruit CircuitPython 3.0.0-alpha.1-62-g111faa1-dirty on 2018-01-15; Adafruit Feather M0 Express with samd21g18
>>> import microcontroller
>>> microcontroller.cpu.uid
bytearray(b'TRJ=\x01\x00\x00\x00(a\x00 @\x13\x00 ')
>>>

@tannewt
Copy link
Member

tannewt commented Jan 15, 2018

Why is that result weird?

@sommersoft
Copy link
Author

yeah, nevermind. I was actually getting errors on the struct.unpack...but now it isn't. must have been a case of "error: sommersoft did something wrong".


>>> import microcontroller
>>> import struct as struct
>>> print(struct.unpack('<i', microcontroller.cpu.uid))
(1028280916,)
>>>

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close. Great work!

#endif

for (int i=0; i<4; i++) {
raw_id[i] = *id_addresses[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need a loop within this one to save the four bytes of each uint32_t into four slots in raw_id.

uint32_t* id_addresses[2] = {(uint32_t *) 0x060, (uint32_t *) 0x064};

for (int i=0; i<2; i++) {
raw_id[i] = *id_addresses[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

@@ -32,7 +32,7 @@

#include "py/objproperty.h"

#include "py/objproperty.h"
#include "py/objproperty.h" // <-- is this doubled for a reason? @sommersoft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an oversight, please remove.

//| Returns a bytearray object. Use the CPython ``struct``
//| library to unpack the bytearray. Unpacked result is
//| a singleton (single item tuple).
//| _Note: ``struct`` is currently not available on the nRF port._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mention struct here. People can do what they want with it afterwards.

@@ -93,9 +93,34 @@ const mp_obj_property_t mcu_processor_temperature_obj = {
},
};

//| .. attribute:: unique id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..attribute:: uid It should match the entry in mcu_processor_locals_dict_table below.

@sommersoft
Copy link
Author

Changes made. SAMD tested on Feather M0 Express; nRF tested on Feather nRF52.

tannewt
tannewt previously approved these changes Jan 16, 2018
@tannewt
Copy link
Member

tannewt commented Jan 16, 2018

Please rebase these onto latest master. Ping me on discord if you need help.

@tannewt tannewt added this to the 3.0 milestone Jan 16, 2018
sommersoft and others added 15 commits January 16, 2018 23:19
shared_bindings/index.rst: updated Support Matrix format as discussed in PR adafruit#503 & Issue adafruit#448.
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.
shared-bindings/index.rst: corrected term agreement/grammar for previous Support Matrix update. See PR adafruit#503 & Issue adafruit#448.
/esp8266/common-hal/microcontroller.h: added UID length definition
/esp8266/common-hal/microcontroller/Processor.c: added UID function
	modified:   ports/atmel-samd/common-hal/microcontroller/Processor.h
	modified:   shared-bindings/microcontroller/Processor.c
	modified:   shared-bindings/microcontroller/Processor.h
	modified:   ports/atmel-samd/common-hal/microcontroller/Processor.h
	modified:   shared-bindings/microcontroller/Processor.c
	modified:   shared-bindings/microcontroller/Processor.h
/ports/nrf/common-hal/microcontroller/Processor.h: add UID length definition.
/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.
/ports/atmel-samd/common-hal/microcontroller.c: corrected `raw_id[]` assignment per requested changes in PR adafruit#527
/ports/nrf/common-hal/microcontroller.c: corrected `raw_id[]` assignment per requested changes in PR adafruit#527
/shared-bindings/microcontroller/Processor.c: corrected Sphinx documentation per requested changes in PR adafruit#527
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code still looks good! Will wait for Travis and then merge.

@tannewt tannewt merged commit 44bc171 into adafruit:master Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants