aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authordeadprogram <[email protected]>2023-10-27 16:06:03 +0200
committerRon Evans <[email protected]>2023-10-27 17:44:53 +0200
commit938ce22307194504431d91d162608c47e4b4ffd3 (patch)
tree14620e1520df3008640d540a99c525ad208a7c87 /src
parent9fb5a5b9a480c1fa407748b7defd8249ae94d537 (diff)
downloadtinygo-938ce22307194504431d91d162608c47e4b4ffd3.tar.gz
tinygo-938ce22307194504431d91d162608c47e4b4ffd3.zip
machine/stm32: implement DeviceID() with unique ID per processor
Signed-off-by: deadprogram <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/machine/machine_stm32.go24
-rw-r--r--src/machine/machine_stm32f103.go2
-rw-r--r--src/machine/machine_stm32f4.go2
-rw-r--r--src/machine/machine_stm32f7.go2
-rw-r--r--src/machine/machine_stm32l0.go2
-rw-r--r--src/machine/machine_stm32l4.go2
-rw-r--r--src/machine/machine_stm32l5.go2
-rw-r--r--src/machine/machine_stm32wlx.go2
8 files changed, 37 insertions, 1 deletions
diff --git a/src/machine/machine_stm32.go b/src/machine/machine_stm32.go
index 4f04cae4c..1edaa2cd0 100644
--- a/src/machine/machine_stm32.go
+++ b/src/machine/machine_stm32.go
@@ -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[:]
+}
diff --git a/src/machine/machine_stm32f103.go b/src/machine/machine_stm32f103.go
index e7593829b..66a74d04b 100644
--- a/src/machine/machine_stm32f103.go
+++ b/src/machine/machine_stm32f103.go
@@ -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
diff --git a/src/machine/machine_stm32f4.go b/src/machine/machine_stm32f4.go
index 3b8923cb7..42193a739 100644
--- a/src/machine/machine_stm32f4.go
+++ b/src/machine/machine_stm32f4.go
@@ -14,6 +14,8 @@ import (
"unsafe"
)
+var deviceIDAddr = []uintptr{0x1FFF7A10, 0x1FFF7A14, 0x1FFF7A18}
+
const (
PA0 = portA + 0
PA1 = portA + 1
diff --git a/src/machine/machine_stm32f7.go b/src/machine/machine_stm32f7.go
index a08d083a2..11eff1108 100644
--- a/src/machine/machine_stm32f7.go
+++ b/src/machine/machine_stm32f7.go
@@ -11,6 +11,8 @@ import (
"unsafe"
)
+var deviceIDAddr = []uintptr{0x1FF0F420, 0x1FF0F424, 0x1FF0F428}
+
// Alternative peripheral pin functions
const (
AF0_SYSTEM = 0
diff --git a/src/machine/machine_stm32l0.go b/src/machine/machine_stm32l0.go
index f3d213c48..844cfccb4 100644
--- a/src/machine/machine_stm32l0.go
+++ b/src/machine/machine_stm32l0.go
@@ -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
diff --git a/src/machine/machine_stm32l4.go b/src/machine/machine_stm32l4.go
index f60a77e70..856320911 100644
--- a/src/machine/machine_stm32l4.go
+++ b/src/machine/machine_stm32l4.go
@@ -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
diff --git a/src/machine/machine_stm32l5.go b/src/machine/machine_stm32l5.go
index d85157dbe..faa583c9c 100644
--- a/src/machine/machine_stm32l5.go
+++ b/src/machine/machine_stm32l5.go
@@ -11,6 +11,8 @@ import (
"unsafe"
)
+var deviceIDAddr = []uintptr{0x0BFA0590, 0x0BFA0594, 0x0BFA0598}
+
const (
AF0_SYSTEM = 0
AF1_TIM1_2_5_8_LPTIM1 = 1
diff --git a/src/machine/machine_stm32wlx.go b/src/machine/machine_stm32wlx.go
index 010d038e0..d42ef2e38 100644
--- a/src/machine/machine_stm32wlx.go
+++ b/src/machine/machine_stm32wlx.go
@@ -14,6 +14,8 @@ import (
"unsafe"
)
+var deviceIDAddr = []uintptr{0x1FFF7590, 0x1FFF7594, 0x1FFF7598}
+
const (
AF0_SYSTEM = 0
AF1_TIM1_2_LPTIM1 = 1