File tree 3 files changed +24
-2
lines changed
common-hal/microcontroller 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 26
26
*/
27
27
28
28
#include <math.h>
29
+ #include <string.h>
30
+
29
31
#include "common-hal/microcontroller/Processor.h"
30
32
#include "py/runtime.h"
31
33
#include "supervisor/shared/translate.h"
32
34
35
+ #include "soc/efuse_reg.h"
36
+
33
37
float common_hal_mcu_processor_get_temperature (void ) {
34
38
return NAN ;
35
39
}
@@ -42,5 +46,23 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
42
46
return 0 ;
43
47
}
44
48
49
+ STATIC uint8_t swap_nibbles (uint8_t v ) {
50
+ return ((v << 4 ) | (v >> 4 )) & 0xff ;
51
+ }
52
+
45
53
void common_hal_mcu_processor_get_uid (uint8_t raw_id []) {
54
+ memset (raw_id , 0 , COMMON_HAL_MCU_PROCESSOR_UID_LENGTH );
55
+
56
+ uint8_t * ptr = & raw_id [COMMON_HAL_MCU_PROCESSOR_UID_LENGTH - 1 ];
57
+ // MAC address contains 48 bits (6 bytes), 32 in the low order word
58
+ uint32_t mac_address_part = REG_READ (EFUSE_RD_MAC_SPI_SYS_0_REG );
59
+ * ptr -- = swap_nibbles (mac_address_part & 0xff ); mac_address_part >>= 8 ;
60
+ * ptr -- = swap_nibbles (mac_address_part & 0xff ); mac_address_part >>= 8 ;
61
+ * ptr -- = swap_nibbles (mac_address_part & 0xff ); mac_address_part >>= 8 ;
62
+ * ptr -- = swap_nibbles (mac_address_part & 0xff );
63
+
64
+ // and 16 in the high order word
65
+ mac_address_part = REG_READ (EFUSE_RD_MAC_SPI_SYS_1_REG );
66
+ * ptr -- = swap_nibbles (mac_address_part & 0xff ); mac_address_part >>= 8 ;
67
+ * ptr -- = swap_nibbles (mac_address_part & 0xff );
46
68
}
Original file line number Diff line number Diff line change 27
27
#ifndef MICROPY_INCLUDED_LITEX_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
28
28
#define MICROPY_INCLUDED_LITEX_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
29
29
30
- #define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 15
30
+ #define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 6
31
31
32
32
#include "py/obj.h"
33
33
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz
7
7
INTERNAL_LIBM = 1
8
8
9
9
# Chip supplied serial number, in bytes
10
- USB_SERIAL_NUMBER_LENGTH = 30
10
+ USB_SERIAL_NUMBER_LENGTH = 12
11
11
12
12
# Longints can be implemented as mpz, as longlong, or not
13
13
LONGINT_IMPL = MPZ
You can’t perform that action at this time.
0 commit comments