STM32G070的CPUID地址:- /*!< Device Electronic Signature */5 W. y! ^& y3 c; @
- #define PACKAGE_BASE (0x1FFF7500UL) /*!< Package data register base address */1 _" i5 u9 @4 V$ p3 J* }: G% n/ y
- #define UID_BASE (0x1FFF7590UL) /*!< Unique device ID register base address */
, E) {+ e' T# G- ]. H8 P) {9 Q - #define FLASHSIZE_BASE (0x1FFF75E0UL) /*!< Flash size data register base address */1 L9 d t8 c" C7 |
- /**
0 D# m3 Q8 m ~: }
复制代码
$ P3 v8 w L8 n" k9 V
; R9 A7 `- y) x; o/ N1 p/ `. _HAL库已经预留了API可以直接读取:- /**
4 B) L9 ]) M0 X5 a! d" i+ `3 N9 s+ { - * @brief Returns first word of the unique device identifier (UID based on 96 bits)
( O$ F; r: D6 R' P8 |- i - * @retval Device identifier& Q0 s' z# q' J+ D h
- */1 H' E! `3 a, `" U. m4 L! _, ^
- uint32_t HAL_GetUIDw0(void)
- f* J! c' V) N - {7 X1 v \$ W9 E& A, D% ]3 M
- return (READ_REG(*((uint32_t *)UID_BASE)));5 G! {0 ]- G$ b% _
- }, h( P; Y4 M7 W6 M! S& q% P0 ]+ P
- , G2 y/ \% z( Y3 Z
- /**. O. H% N$ x6 A% a, u- ^& r
- * @brief Returns second word of the unique device identifier (UID based on 96 bits)
* b* c. Z1 A" D; c8 Q: ?9 { - * @retval Device identifier
# l3 y% [- Y9 H8 ~/ `3 e/ G$ g - */6 l2 |- s& S3 v. F! A5 I
- uint32_t HAL_GetUIDw1(void) }+ ]% ]0 d$ T1 @+ |
- {& f1 f; w/ `* Q/ F+ D" [
- return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
$ _( N1 G, y9 P3 m9 A$ U - }5 |( p& z4 _2 L* }. I
- ' `1 G1 m2 N. G1 e
- /**
3 |" k4 i/ [3 b: H+ D% P% j' ]) v - * @brief Returns third word of the unique device identifier (UID based on 96 bits)
& A+ o' c" T% {; _2 p, P6 X5 X - * @retval Device identifier# i! K% l$ Z# T6 U; V7 T
- */
, g4 D8 y9 K% O/ [, f9 ` - uint32_t HAL_GetUIDw2(void)
% `( Z! B4 c1 H7 s- L - {* L3 \( T+ [& M# j; \
- return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));0 ^ R% g' C% `2 k! h* n
- }
* w$ P; Z( d7 f) _$ Z7 ?
6 x" P3 I8 A- F' ^) u% p% I
复制代码
& ^8 P8 a# H$ C1 t ]! n+ }0 a& s! ~5 I* r5 w6 c8 Q1 w
1 B. a, [% i- | |