mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 12:10:59 +00:00
add base MAC address storage choice.
Base MAC address can be stored in default manufacture-defined or customer pre-defined place in EFUSE and other place e.g. flash or EEPROM. If choose to use base MAC address which is stored in other place, please call esp_base_mac_addr_set_external() before initializing WiFi/BT/Ehternet.
This commit is contained in:
@@ -36,10 +36,38 @@
|
||||
|
||||
static const char* TAG = "system_api";
|
||||
|
||||
static uint8_t ext_base_mac_addr[6] = {0};
|
||||
|
||||
void system_init()
|
||||
{
|
||||
}
|
||||
|
||||
esp_err_t esp_base_mac_addr_set_external(uint8_t *mac)
|
||||
{
|
||||
if (mac == NULL) {
|
||||
ESP_LOGE(TAG, "External base MAC address is NULL");
|
||||
abort();
|
||||
}
|
||||
|
||||
memcpy(ext_base_mac_addr, mac, 6);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_base_mac_addr_get_external(uint8_t *mac)
|
||||
{
|
||||
uint8_t null_mac[6] = {0};
|
||||
|
||||
if (memcmp(ext_base_mac_addr, null_mac, 6) == 0) {
|
||||
ESP_LOGE(TAG, "External MAC address is not set");
|
||||
abort();
|
||||
}
|
||||
|
||||
memcpy(mac, ext_base_mac_addr, 6);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_efuse_read_mac(uint8_t* mac)
|
||||
{
|
||||
uint32_t mac_low;
|
||||
@@ -47,7 +75,7 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
|
||||
uint8_t efuse_crc;
|
||||
uint8_t calc_crc;
|
||||
|
||||
#ifndef CONFIG_CUSTOMER_MAC_ADDRESS
|
||||
#ifdef CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE
|
||||
mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG);
|
||||
mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG);
|
||||
|
||||
@@ -78,7 +106,7 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
|
||||
mac[5] = mac_low >> 16;
|
||||
|
||||
efuse_crc = mac_high;
|
||||
#endif //CONFIG_CUSTOMER_DEFINED_MAC_ADDR
|
||||
#endif //CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE
|
||||
|
||||
calc_crc = esp_crc8(mac, 6);
|
||||
|
||||
@@ -139,7 +167,13 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
|
||||
|| NUM_MAC_ADDRESS_FROM_EFUSE == TWO_MAC_ADDRESS_FROM_EFUSE, \
|
||||
"incorrect NUM_MAC_ADDRESS_FROM_EFUSE value");
|
||||
|
||||
#if defined(CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE) || defined(CONFIG_BASE_MAC_STORED_CUSTOMER_DEFINED_EFUSE)
|
||||
esp_efuse_read_mac(efuse_mac);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BASE_MAC_STORED_OTHER_CUSTOMER_DEFINED_PLACE)
|
||||
esp_base_mac_addr_get_external(efuse_mac);
|
||||
#endif
|
||||
|
||||
switch (type) {
|
||||
case ESP_MAC_WIFI_STA:
|
||||
|
Reference in New Issue
Block a user