stm32f7x7_hal/
signature.rs

1//! Device electronic signature
2//!
3//! (stored in flash memory)
4
5use core::str::from_utf8_unchecked;
6
7/// This is the test voltage, in millivolts of the calibration done at the factory
8pub const VDDA_CALIB: u32 = 3300;
9
10macro_rules! define_ptr_type {
11    ($name: ident, $ptr: expr) => (
12        impl $name {
13            fn ptr() -> *const Self {
14                $ptr as *const _
15            }
16
17            /// Returns a wrapped reference to the value in flash memory
18            pub fn get() -> &'static Self {
19                unsafe { &*Self::ptr() }
20            }
21        }
22    )
23}
24
25/// Uniqure Device ID register
26#[derive(Hash, Debug)]
27#[repr(C)]
28pub struct Uid {
29    x: u16,
30    y: u16,
31    waf_lot: [u8; 8],
32}
33define_ptr_type!(Uid, 0x1FF0_F420);
34
35impl Uid {
36    /// X coordinate on wafer
37    pub fn x(&self) -> u16 {
38        self.x
39    }
40
41    /// Y coordinate on wafer
42    pub fn y(&self) -> u16 {
43        self.y
44    }
45
46    /// Wafer number
47    pub fn waf_num(&self) -> u8 {
48        self.waf_lot[0]
49    }
50
51    /// Lot number
52    pub fn lot_num(&self) -> &str {
53        unsafe {
54            from_utf8_unchecked(&self.waf_lot[1..])
55        }
56    }
57}
58
59/// Size of integrated flash
60#[derive(Debug)]
61#[repr(C)]
62pub struct FlashSize(u16);
63define_ptr_type!(FlashSize, 0x1FF0_F442);
64
65impl FlashSize {
66    /// Read flash size in kilobytes
67    pub fn kilo_bytes(&self) -> u16 {
68        self.0
69    }
70
71    /// Read flash size in bytes
72    pub fn bytes(&self) -> usize {
73        usize::from(self.kilo_bytes()) * 1024
74    }
75}
76
77/// ADC VREF calibration value is stored in at the factory
78#[derive(Debug)]
79#[repr(C)]
80pub struct VrefCal(u16);
81define_ptr_type!(VrefCal, 0x1FF0_F44A);
82
83impl VrefCal {
84    /// Read calibration value
85    pub fn read(&self) -> u16 {
86        self.0
87    }
88}
89
90/// A temperature reading taken at 30°C stored at the factory
91#[derive(Debug)]
92#[repr(C)]
93pub struct VtempCal30(u16);
94define_ptr_type!(VtempCal30, 0x1FF0_F44C);
95
96impl VtempCal30 {
97    /// Read calibration value
98    pub fn read(&self) -> u16 {
99        self.0
100    }
101}
102
103/// A temperature reading taken at 110°C stored at the factory
104#[derive(Debug)]
105#[repr(C)]
106pub struct VtempCal110(u16);
107define_ptr_type!(VtempCal110, 0x1FF0_F44E);
108
109impl VtempCal110 {
110    /// Read calibration value
111    pub fn read(&self) -> u16 {
112        self.0
113    }
114}
115