github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_atsam.go (about) 1 //go:build sam 2 3 package machine 4 5 import ( 6 "runtime/volatile" 7 "unsafe" 8 ) 9 10 var deviceID [16]byte 11 12 // DeviceID returns an identifier that is unique within 13 // a particular chipset. 14 // 15 // The identity is one burnt into the MCU itself, or the 16 // flash chip at time of manufacture. 17 // 18 // It's possible that two different vendors may allocate 19 // the same DeviceID, so callers should take this into 20 // account if needing to generate a globally unique id. 21 // 22 // The length of the hardware ID is vendor-specific, but 23 // 8 bytes (64 bits) and 16 bytes (128 bits) are common. 24 func DeviceID() []byte { 25 for i := 0; i < len(deviceID); i++ { 26 word := (*volatile.Register32)(unsafe.Pointer(deviceIDAddr[i/4])).Get() 27 deviceID[i] = byte(word >> ((i % 4) * 8)) 28 } 29 30 return deviceID[:] 31 }