Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 104:b5183e348f9d, committed 2017-11-21
- Comitter:
- Helmut Tschemernjak
- Date:
- Tue Nov 21 16:59:28 2017 +0100
- Parent:
- 103:59930a715bf8
- Child:
- 105:6e6d141c3da8
- Commit message:
- Added better CPUID code, now the Mac address and the MCU revision
is being used.
Changed in this revision
| Arduino-mbed-APIs/arduino-esp32.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Arduino-mbed-APIs/arduino-esp32.cpp Mon Nov 20 12:42:09 2017 +0100
+++ b/Arduino-mbed-APIs/arduino-esp32.cpp Tue Nov 21 16:59:28 2017 +0100
@@ -12,24 +12,49 @@
#include "arduino-util.h"
#include <time.h>
+#if defined(ARDUINO_ARCH_ESP32)
-#if defined(ARDUINO_ARCH_ESP32)
+#include "soc/efuse_reg.h"
+
+
/*
* ARDUINO_ARCH_ESP32 ESP32 development board
* Heltec ESP32 boards
*/
-int
-CPUID(uint8_t *buf, int maxSize, uint32_t xorval)
+int CPUID(uint8_t *buf, int maxSize, uint32_t xorval)
{
- uint64_t chipid = ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
-
+ uint8_t uuid[16];
+ int f1 = 0x6aa0f551; // EFUSE_BLK0_RDATA1_REG address
+ int f2 = 0x6aa0f55d; // EFUSE_BLK0_RDATA2_REG address
- if (maxSize >= sizeof(chipid)) {
- memset(buf, 0, maxSize);
- chipid = chipid ^ xorval;
- memcpy(&chipid, buf, sizeof(chipid));
- return sizeof(chipid) ;
+ if (maxSize >= sizeof(uuid)) {
+ int fa = f1 ^ xorval;
+ int fb = f2 ^ xorval;
+
+ uint32_t mac_low = REG_READ(fa);
+ uint32_t mac_high = REG_READ(fb);
+
+ uuid[0] = mac_high >> 8;
+ uuid[1] = mac_high;
+ uuid[2] = mac_low >> 24;
+ uuid[3] = mac_low >> 16;
+ uuid[4] = mac_low >> 8;
+ uuid[5] = mac_low;
+
+ uuid[6] = uuid[0] ^ 0x16;
+ uuid[7] = uuid[1] ^ 0x27;
+ uuid[8] = uuid[2] ^ 0x38;
+ uuid[9] = uuid[4] ^ 0x49;
+ uuid[10] = uuid[5] ^ 0x50;
+ uuid[11] = uuid[5] ^ 0x61;
+
+ uuid[12] = ESP.getChipRevision();
+ uuid[13] = 0x12;
+ uuid[14] = 0x34;
+ uuid[15] = 0x56;
+ memcpy(buf, &uuid[0], sizeof(uuid));
+ return sizeof(uuid);
}
return 0;
}