diff --git a/cores/beken-72xx/base/lt_api.c b/cores/beken-72xx/base/lt_api.c index 1191cb2..04c0416 100644 --- a/cores/beken-72xx/base/lt_api.c +++ b/cores/beken-72xx/base/lt_api.c @@ -29,12 +29,6 @@ lt_cpu_model_t lt_cpu_get_model() { return CPU_MODEL_ENUM(FAMILY, chipId); } -uint32_t lt_cpu_get_mac_id() { - uint8_t mac[6]; - cfg_load_mac(mac); // force loading MAC from TLV (ignore user-set WiFi MAC) - return (mac[3]) | (mac[4] << 8) | (mac[5] << 16); -} - const char *lt_cpu_get_core_type() { return "ARM968E-S"; } @@ -45,6 +39,10 @@ const char *lt_cpu_get_core_type() { | | | |/ _ \ \ / / |/ __/ _ \ | |__| | __/\ V /| | (_| __/ |_____/ \___| \_/ |_|\___\__*/ +void lt_get_device_mac(uint8_t *mac) { + cfg_load_mac(mac); +} + void lt_reboot() { bk_reboot(); } diff --git a/cores/common/base/api/lt_cpu.h b/cores/common/base/api/lt_cpu.h index 7feb523..f2c6b80 100644 --- a/cores/common/base/api/lt_cpu.h +++ b/cores/common/base/api/lt_cpu.h @@ -38,6 +38,7 @@ uint32_t lt_cpu_get_unique_id(); /** * @brief Get CPU ID based on the last three octets of MAC address. * Note: the number is 24-bit (with the MSB being zero). + * The 3rd-to-last octet is least-significant, the last octet is most-significant. */ uint32_t lt_cpu_get_mac_id(); diff --git a/cores/common/base/api/lt_device.h b/cores/common/base/api/lt_device.h index 36e9a14..43d8477 100644 --- a/cores/common/base/api/lt_device.h +++ b/cores/common/base/api/lt_device.h @@ -20,6 +20,13 @@ const char *lt_get_board_code(); */ const char *lt_get_device_name(); +/** + * @brief Read device's *default* MAC address into 'mac' array. + * This can be used even without Wi-Fi enabled, and will ignore + * user-changed Wi-Fi MAC (if changing is possible). + */ +void lt_get_device_mac(uint8_t *mac); + /** * @brief Reboot the CPU. */ diff --git a/cores/common/base/lt_api.c b/cores/common/base/lt_api.c index df0e15d..b65a7ad 100644 --- a/cores/common/base/lt_api.c +++ b/cores/common/base/lt_api.c @@ -39,6 +39,12 @@ __attribute__((weak)) uint32_t lt_cpu_get_unique_id() { return lt_cpu_get_mac_id(); } +__attribute__((weak)) uint32_t lt_cpu_get_mac_id() { + uint8_t mac[6]; + lt_get_device_mac(mac); + return (mac[3] << 0) | (mac[4] << 8) | (mac[5] << 16); +} + __attribute__((weak)) uint8_t lt_cpu_get_core_count() { return 1; } diff --git a/cores/realtek-amb/arduino/libraries/WiFi/WiFiSTA.cpp b/cores/realtek-amb/arduino/libraries/WiFi/WiFiSTA.cpp index 7067a8f..926ecc7 100644 --- a/cores/realtek-amb/arduino/libraries/WiFi/WiFiSTA.cpp +++ b/cores/realtek-amb/arduino/libraries/WiFi/WiFiSTA.cpp @@ -158,10 +158,7 @@ IPAddress WiFiClass::localIP() { uint8_t *WiFiClass::macAddress(uint8_t *mac) { if ((getMode() & WIFI_MODE_STA) == 0) { - uint8_t *efuse = (uint8_t *)malloc(512); - EFUSE_LogicalMap_Read(efuse); - memcpy(mac, efuse + 0x11A, ETH_ALEN); - free(efuse); + lt_get_device_mac(mac); return mac; } memcpy(mac, NETIF_RTW_STA.hwaddr, ETH_ALEN); diff --git a/cores/realtek-ambz/base/lt_api.c b/cores/realtek-ambz/base/lt_api.c index 94624e6..2d7181a 100644 --- a/cores/realtek-ambz/base/lt_api.c +++ b/cores/realtek-ambz/base/lt_api.c @@ -57,6 +57,13 @@ uint32_t lt_cpu_get_freq() { | | | |/ _ \ \ / / |/ __/ _ \ | |__| | __/\ V /| | (_| __/ |_____/ \___| \_/ |_|\___\__*/ +void lt_get_device_mac(uint8_t *mac) { + uint8_t *efuse = (uint8_t *)malloc(512); + EFUSE_LogicalMap_Read(efuse); + memcpy(mac, efuse + 0x11A, 6); + free(efuse); +} + bool lt_reboot_download_mode() { // mww 0x40000138 0x8 HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_NORESET_FF, 0x08); diff --git a/cores/realtek-ambz2/base/lt_api.c b/cores/realtek-ambz2/base/lt_api.c index 3de1f67..ae1df72 100644 --- a/cores/realtek-ambz2/base/lt_api.c +++ b/cores/realtek-ambz2/base/lt_api.c @@ -28,12 +28,6 @@ lt_cpu_model_t lt_cpu_get_model() { return CPU_MODEL_ENUM(FAMILY, (chip_id & 0xFF) | flash_mode); } -uint32_t lt_cpu_get_mac_id() { - uint8_t mac[3]; - efuse_logical_read(0x11A + 3, 3, mac); - return (mac[0] << 0) | (mac[1] << 8) | (mac[2] << 16); -} - const char *lt_cpu_get_core_type() { return "ARM Cortex-M4"; } @@ -48,6 +42,10 @@ uint32_t lt_cpu_get_freq() { | | | |/ _ \ \ / / |/ __/ _ \ | |__| | __/\ V /| | (_| __/ |_____/ \___| \_/ |_|\___\__*/ +void lt_get_device_mac(uint8_t *mac) { + efuse_logical_read(0x11A, 6, mac); +} + void lt_reboot() { sys_cpu_reset(); while (1) {}