Page 1 of 1
Unique hardware serial number
Posted: Wed Dec 28, 2022 6:46 pm
by dg9ngf
Hello,
Is there a unique serial number somewhere in an ESP32 chip? I want to provide a way to distinguish multiple ESP32-based devices on a field bus and would have used a serial number for that. Other microcontrollers provide such a number that is different in each device without any customisation work. It's set in the factory. I couldn't find any information about this for ESP32. Does it exist? And how can I retrieve it? Any format is fine (binary or text).
Or will I have to implement my own serial numbers in code and with EEPROM or similar?
Re: Unique hardware serial number
Posted: Thu Dec 29, 2022 1:01 am
by ESP_igrr
Each chip is pre-programmed with a unique MAC address, which you can read by calling esp_efuse_mac_get_default function:
https://docs.espressif.com/projects/esp ... tP7uint8_t
Re: Unique hardware serial number
Posted: Thu Dec 29, 2022 10:44 am
by dg9ngf
Thank you, that should work.
But will the function write 6 or 8 bytes to the provided memory? That's entirely unspecified and a likely source of crashes. AFAIK, MAC addresses are always 6 bytes. Not sure why the function would write 8 bytes.
Re: Unique hardware serial number
Posted: Thu Dec 29, 2022 6:53 pm
by schafon
Hi,
I'm having the same challenge as you.
I decided to not count on the mac address and write my own serial for each device.
But during my research I did found that my esp32 (s2) has a field in efuse by the name optional unique id.
OPTIONAL_UNIQUE_ID (BLOCK2) Optional unique 128-bit ID
This might be helpful but I can't find any documentation about it so I can't know for sure that it's unique.
If you'd like to go the same route as me wait few minutes till my post gets approved and you'l be able to write your own serial number to efuse.
Re: Unique hardware serial number
Posted: Sun Jan 01, 2023 12:08 am
by mbratch
According to the
ESP-IDF documentation:
If CONFIG_IEEE802154_ENABLED is set then for these types: ESP_MAC_IEEE802154, ESP_MAC_BASE, ESP_MAC_EFUSE_FACTORY and ESP_MAC_EFUSE_CUSTOM the MAC size is 8 bytes. If CONFIG_IEEE802154_ENABLED is not set then for all types it returns 6 bytes.
So, you could test the macro CONFIG_IEEE802154_ENABLED (for IEEE 802.15.4) to determine if you are fetching a 6-byte versus an 8-byte MAC when calling `esp_efuse_mac_get_default`.
Alternatively, at run time, if you're using the latest ESP-IDF master ersion, you could call
esp_mac_addr_len_get providing the MAC type as a parameter (e.g., ESP_MAC_WIFI_STA).