Unique hardware serial number

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

Unique hardware serial number

Postby dg9ngf » Wed Dec 28, 2022 6:46 pm

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?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Unique hardware serial number

Postby ESP_igrr » Thu Dec 29, 2022 1:01 am

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

dg9ngf
Posts: 40
Joined: Mon Sep 16, 2019 6:49 pm

Re: Unique hardware serial number

Postby dg9ngf » Thu Dec 29, 2022 10:44 am

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.

schafon
Posts: 5
Joined: Mon Dec 12, 2022 7:48 pm

Re: Unique hardware serial number

Postby schafon » Thu Dec 29, 2022 6:53 pm

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.

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: Unique hardware serial number

Postby mbratch » Sun Jan 01, 2023 12:08 am

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).

Who is online

Users browsing this forum: No registered users and 445 guests