Merge pull request #3156 from jepler/esp32s2-serial-number
esp32s2: Use the device's EUI-48 address as unique ID
This commit is contained in:
commit
3610520ca4
@ -26,10 +26,14 @@
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common-hal/microcontroller/Processor.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
#include "soc/efuse_reg.h"
|
||||
|
||||
float common_hal_mcu_processor_get_temperature(void) {
|
||||
return NAN;
|
||||
}
|
||||
@ -42,5 +46,23 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
STATIC uint8_t swap_nibbles(uint8_t v) {
|
||||
return ((v << 4) | (v >> 4)) & 0xff;
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
memset(raw_id, 0, COMMON_HAL_MCU_PROCESSOR_UID_LENGTH);
|
||||
|
||||
uint8_t *ptr = &raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH-1];
|
||||
// MAC address contains 48 bits (6 bytes), 32 in the low order word
|
||||
uint32_t mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_0_REG);
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff);
|
||||
|
||||
// and 16 in the high order word
|
||||
mac_address_part = REG_READ(EFUSE_RD_MAC_SPI_SYS_1_REG);
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
|
||||
*ptr-- = swap_nibbles(mac_address_part & 0xff);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#ifndef MICROPY_INCLUDED_LITEX_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
#define MICROPY_INCLUDED_LITEX_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
|
||||
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 15
|
||||
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 6
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
|
@ -7,7 +7,7 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz
|
||||
INTERNAL_LIBM = 1
|
||||
|
||||
# Chip supplied serial number, in bytes
|
||||
USB_SERIAL_NUMBER_LENGTH = 30
|
||||
USB_SERIAL_NUMBER_LENGTH = 12
|
||||
|
||||
# Longints can be implemented as mpz, as longlong, or not
|
||||
LONGINT_IMPL = MPZ
|
||||
|
Loading…
Reference in New Issue
Block a user