machine/stm32: implement DeviceID() with unique ID per processor
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
9fb5a5b9a4
коммит
938ce22307
8 изменённых файлов: 37 добавлений и 1 удалений
|
@ -2,7 +2,12 @@
|
|||
|
||||
package machine
|
||||
|
||||
import "device/stm32"
|
||||
import (
|
||||
"device/stm32"
|
||||
|
||||
"runtime/volatile"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const deviceName = stm32.Device
|
||||
|
||||
|
@ -80,3 +85,20 @@ func (p Pin) PortMaskClear() (*uint32, uint32) {
|
|||
pin := uint8(p) % 16
|
||||
return &port.BSRR.Reg, 1 << (pin + 16)
|
||||
}
|
||||
|
||||
var deviceID [12]byte
|
||||
|
||||
// DeviceID returns an identifier that is unique within
|
||||
// a particular chipset.
|
||||
//
|
||||
// The identity is one burnt into the MCU itself.
|
||||
//
|
||||
// The length of the device ID for STM32 is 12 bytes (96 bits).
|
||||
func DeviceID() []byte {
|
||||
for i := 0; i < len(deviceID); i++ {
|
||||
word := (*volatile.Register32)(unsafe.Pointer(deviceIDAddr[i/4])).Get()
|
||||
deviceID[i] = byte(word >> ((i % 4) * 8))
|
||||
}
|
||||
|
||||
return deviceID[:]
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ func CPUFrequency() uint32 {
|
|||
return 72000000
|
||||
}
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FFFF7E8, 0x1FFFF7EC, 0x1FFFF7F0}
|
||||
|
||||
// Internal use: configured speed of the APB1 and APB2 timers, this should be kept
|
||||
// in sync with any changes to runtime package which configures the oscillators
|
||||
// and clock frequencies
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FFF7A10, 0x1FFF7A14, 0x1FFF7A18}
|
||||
|
||||
const (
|
||||
PA0 = portA + 0
|
||||
PA1 = portA + 1
|
||||
|
|
|
@ -11,6 +11,8 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FF0F420, 0x1FF0F424, 0x1FF0F428}
|
||||
|
||||
// Alternative peripheral pin functions
|
||||
const (
|
||||
AF0_SYSTEM = 0
|
||||
|
|
|
@ -13,6 +13,8 @@ func CPUFrequency() uint32 {
|
|||
return 32000000
|
||||
}
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FF80050, 0x1FF80054, 0x1FF80058}
|
||||
|
||||
// Internal use: configured speed of the APB1 and APB2 timers, this should be kept
|
||||
// in sync with any changes to runtime package which configures the oscillators
|
||||
// and clock frequencies
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
|
||||
// Peripheral abstraction layer for the stm32l4
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FFF7590, 0x1FFF7594, 0x1FFF7598}
|
||||
|
||||
const (
|
||||
AF0_SYSTEM = 0
|
||||
AF1_TIM1_2_LPTIM1 = 1
|
||||
|
|
|
@ -11,6 +11,8 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
var deviceIDAddr = []uintptr{0x0BFA0590, 0x0BFA0594, 0x0BFA0598}
|
||||
|
||||
const (
|
||||
AF0_SYSTEM = 0
|
||||
AF1_TIM1_2_5_8_LPTIM1 = 1
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
var deviceIDAddr = []uintptr{0x1FFF7590, 0x1FFF7594, 0x1FFF7598}
|
||||
|
||||
const (
|
||||
AF0_SYSTEM = 0
|
||||
AF1_TIM1_2_LPTIM1 = 1
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче