1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 18:13:49 +01:00

cpu/esp32: port periph/cpu_id to ESP-IDF read_mac

This commit is contained in:
Gunar Schorcht 2022-03-12 15:40:51 +01:00
parent d9fc082686
commit 9065dcff14
2 changed files with 19 additions and 16 deletions

View File

@ -54,7 +54,7 @@ extern "C" {
/** /**
* @brief Length of the CPU_ID in octets * @brief Length of the CPU_ID in octets
*/ */
#define CPUID_LEN (7U) #define CPUID_LEN (6U)
/** /**
* @name GPIO configuration * @name GPIO configuration

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Gunar Schorcht * Copyright (C) 2022 Gunar Schorcht
* *
* This file is subject to the terms and conditions of the GNU Lesser * This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level * General Public License v2.1. See the file LICENSE in the top level
@ -22,22 +22,25 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include "periph/cpuid.h" #include "periph_cpu.h"
#include "soc/efuse_reg.h" #include "esp_mac.h"
/*
* ESP32x SoCs don't have a real chip id. The factory-programmed default MAC
* address from EFUSE is used instead.
*/
void cpuid_get(void *id) void cpuid_get(void *id)
{ {
/* since ESP32 has two cores, the default MAC address is used as CPU id */ #if defined(CPU_FAM_ESP32H2) && defined(CONFIG_IEEE802154_ENABLED)
uint32_t rdata1 = REG_READ(EFUSE_BLK0_RDATA1_REG); /* ESP32H2 has IEEE802.15.4 radio which has an EUI64 address. Function
uint32_t rdata2 = REG_READ(EFUSE_BLK0_RDATA2_REG); * esp_efuse_mac_get_default will return this 8 byte address if
* CONFIG_IEEE802154_ENABLED */
_Static_assert(CPUID_LEN == 8,
"CPUID_LEN hast to be 8 if IEEE 802.15.4 interface enabled");
#else
_Static_assert(CPUID_LEN == 6, "CPU_ID_LEN hast to be 6");
#endif
uint8_t *tmp = id; esp_efuse_mac_get_default(id);
tmp[0] = rdata2 >> 16;
tmp[1] = rdata2 >> 8;
tmp[2] = rdata2;
tmp[3] = rdata1 >> 24;
tmp[4] = rdata1 >> 16;
tmp[5] = rdata1 >> 8;
tmp[6] = rdata1;
} }