I am trying to access the unique identifier from the Due's processor. The data sheet (p39):
mentions a 128 bit unique identifier that can't be changed. Is this possible to read this number through code? Preferably using Arduino's IDE..
I am trying to access the unique identifier from the Due's processor. The data sheet (p39):
mentions a 128 bit unique identifier that can't be changed. Is this possible to read this number through code? Preferably using Arduino's IDE..
Preferably using Arduino's IDE..
The IDE is a text editor that invokes a compiler, a linker, and avrdude to upload the hex file that the linker produced. avrdude is the only application that can talk to the Arduino, and only to the bootloader.
You might be able to read the unique ID using code that executes at run time. The IDE won't be able to.
The technique for reading the UID is not straightforward and AFAIK you can't do it from code running in flash which means you have to load a small routine into RAM.
See section 20.4.3.8 of the data sheet.
Rob
#define EFC_ACCESS_MODE_128 0
#define FLASH_ACCESS_MODE_128 EFC_ACCESS_MODE_128
#define EFC0 (0x400E0A00U)
#define EFC EFC0
uint32_t ul_rc;
uint32_t unique_id[4];
typedef enum flash_rc {
FLASH_RC_OK = 0, //!< Operation OK
FLASH_RC_YES = 1, //!< Yes
FLASH_RC_NO = 0, //!< No
FLASH_RC_ERROR = 0x10, //!< General error
FLASH_RC_INVALID, //!< Invalid argument input
FLASH_RC_NOT_SUPPORT = 0xFFFFFFFF //!< Operation is not supported
} flash_rc_t;
typedef unsigned long UL;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
ul_rc = efc_init(EFC, FLASH_ACCESS_MODE_128, 4);
if (ul_rc != 0) {
Serial.println(" FOUT" );
}
Serial.println("-I- Reading 128 bits Unique Identifier\r");
ul_rc = flash_read_unique_id(unique_id, 4);
Serial.print(" ID = " );
Serial.print((UL)unique_id[0]);Serial.print(",");
Serial.print((UL)unique_id[1]);Serial.print(",");
Serial.print((UL)unique_id[2]);Serial.print(",");
Serial.println((UL)unique_id[3]);
}
void loop() {
// put your main code here, to run repeatedly:
}
uint32_t flash_read_unique_id(uint32_t *pul_data, uint32_t ul_size)
{
uint32_t uid_buf[4];
uint32_t ul_idx;
if (FLASH_RC_OK != efc_perform_read_sequence(EFC, EFC_FCMD_STUI,
EFC_FCMD_SPUI, uid_buf, 4)) {
return FLASH_RC_ERROR;
}
if (ul_size > 4) {
/* Only 4 dword to store unique ID */
ul_size = 4;
}
for (ul_idx = 0; ul_idx < ul_size; ul_idx++) {
pul_data[ul_idx] = uid_buf[ul_idx];
}
return FLASH_RC_OK;
}
for anyone else stumbling upon this, the code examples on the forums no longer compile with IDE 1.6.9.
i'm trying to solve it here invalid conversion from 'unsigned int' to 'Efc*' - Programming Questions - Arduino Forum