1pub fn uid() -> &'static [u8; 12] {
5 unsafe { &*crate::pac::UID.uid(0).as_ptr().cast::<[u8; 12]>() }
6}
7
8pub fn uid_hex() -> &'static str {
10 unsafe { core::str::from_utf8_unchecked(uid_hex_bytes()) }
11}
12
13pub fn uid_hex_bytes() -> &'static [u8; 24] {
15 const HEX: &[u8; 16] = b"0123456789ABCDEF";
16 static mut UID_HEX: [u8; 24] = [0; 24];
17 static mut LOADED: bool = false;
18 critical_section::with(|_| unsafe {
19 if !LOADED {
20 let uid = uid();
21 for (idx, v) in uid.iter().enumerate() {
22 let lo = v & 0x0f;
23 let hi = (v & 0xf0) >> 4;
24 UID_HEX[idx * 2] = HEX[hi as usize];
25 UID_HEX[idx * 2 + 1] = HEX[lo as usize];
26 }
27 LOADED = true;
28 }
29 });
30 unsafe { &*core::ptr::addr_of!(UID_HEX) }
31}