]> granicus.if.org Git - esp-idf/commitdiff
Add customer MAC address that read from efuse
authorXiaXiaotian <xiaxiaotian@espressif.com>
Mon, 17 Apr 2017 13:16:16 +0000 (21:16 +0800)
committerXiaXiaotian <xiaxiaotian@espressif.com>
Mon, 17 Apr 2017 13:24:15 +0000 (21:24 +0800)
components/esp32/Kconfig
components/esp32/system_api.c

index 0db76f3d596c7ef181ceb90451719da29c2ed4d6..a8470c2c92bcab05798028098f535c47bf85510d 100644 (file)
@@ -105,6 +105,13 @@ config MEMMAP_SPISRAM
         main memory map. Enable this if you have this hardware and want to use it in the same
         way as on-chip RAM.
 
+config CUSTOMER_MAC_ADDRESS
+    bool "Customer MAC address"
+    default n
+    help
+        Customers can define their own mac address in efuse.
+        Set to 'y' if you decide to use the mac address that you defined in efuse.
+        
 choice NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE
     bool "Number of MAC address generated from the hardware MAC address in efuse"
     default FOUR_MAC_ADDRESS_FROM_EFUSE
index 028513718ef62ff6bcf9375e42f4908e1664bff6..f43e2251a0e69420735b0314554ee318e89c65a4 100644 (file)
@@ -42,10 +42,14 @@ void system_init()
 
 esp_err_t esp_efuse_read_mac(uint8_t* mac)
 {
+    uint32_t mac_low;
+    uint32_t mac_high;
     uint8_t efuse_crc;
     uint8_t calc_crc;
-    uint32_t mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG);
-    uint32_t mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG);
+
+#ifndef CONFIG_CUSTOMER_MAC_ADDRESS
+    mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG);
+    mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG);
 
     mac[0] = mac_high >> 8;
     mac[1] = mac_high;
@@ -55,6 +59,27 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac)
     mac[5] = mac_low;
 
     efuse_crc = mac_high >> 16;
+#else
+    uint8_t version = REG_READ(EFUSE_BLK3_RDATA5_REG) >> 24;
+
+    if (version != 1) {
+        ESP_LOGE(TAG, "Customer efuse MAC address version error, version = %d", version);
+        abort();
+    }
+
+    mac_low = REG_READ(EFUSE_BLK3_RDATA1_REG);
+    mac_high = REG_READ(EFUSE_BLK3_RDATA0_REG);
+
+    mac[0] = mac_high >> 8;
+    mac[1] = mac_high >> 16;
+    mac[2] = mac_high >> 24;
+    mac[3] = mac_low;
+    mac[4] = mac_low >> 8;
+    mac[5] = mac_low >> 16;
+
+    efuse_crc = mac_high;
+#endif //CONFIG_CUSTOMER_DEFINED_MAC_ADDR
+
     calc_crc = esp_crc8(mac, 6);
 
     if (efuse_crc != calc_crc) {