STM32G070的CPUID地址:- /*!< Device Electronic Signature */
& v! J$ ?& g9 q4 D2 c. b - #define PACKAGE_BASE (0x1FFF7500UL) /*!< Package data register base address */
( O v q4 h( D0 t- m; f - #define UID_BASE (0x1FFF7590UL) /*!< Unique device ID register base address */* b2 s+ W, Z$ k5 p. a& k4 D
- #define FLASHSIZE_BASE (0x1FFF75E0UL) /*!< Flash size data register base address */
9 L( u* s( t7 J) x- l- n" i& o - /**
# Y4 s% x+ x& M. D/ U# v
复制代码
{9 _0 N& V/ d6 Q) y- J$ c$ R7 r: H4 I1 D
HAL库已经预留了API可以直接读取:- /**
& k! K8 D8 T& P3 |; J - * @brief Returns first word of the unique device identifier (UID based on 96 bits)6 `7 N7 u3 W6 J
- * @retval Device identifier
; ~( F* y; j# } - */
& Z! s* R% [$ E t0 \" }7 h0 P - uint32_t HAL_GetUIDw0(void): h9 W- ?: U: `
- {, g4 N3 n9 {. b" C
- return (READ_REG(*((uint32_t *)UID_BASE)));
! f _# n5 d- K6 g. j; v- f0 I - }2 C+ A9 `# f/ U) e- o) ?5 I4 ^
6 w5 ], \ P3 a7 W5 \3 c- /**
! l1 U$ |6 j/ @. Y - * @brief Returns second word of the unique device identifier (UID based on 96 bits)
8 n8 V1 b$ N2 N+ i' D - * @retval Device identifier
6 B0 \- K" \8 q - */* v# F% O. f0 O: V# X
- uint32_t HAL_GetUIDw1(void)( a' i& F1 V7 `! A! ]* ^
- {
8 J2 R N- f8 V+ A/ Y8 L - return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));: t0 D- G: o+ ~; Y
- }
- q" [7 c2 l% V" m
' z2 `% L8 e, }' k1 ^: h- /**
1 _: F1 ?& F# c7 C - * @brief Returns third word of the unique device identifier (UID based on 96 bits)3 [7 v) G: t6 v- M- B6 I3 \4 ]
- * @retval Device identifier
, s6 s3 g! p0 h4 @& _9 P0 L - */- ~+ e |3 R0 H& B( {4 N# }( O
- uint32_t HAL_GetUIDw2(void)
" q+ N; Z+ Y/ [) G3 m - {
1 E- Z+ P K7 ^% K- l - return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));7 o+ x6 U) E' X+ ]- O2 O
- }
7 l4 }7 s$ }1 }. k2 b- D% ~: J - 8 d; I! T! Q3 Q K
复制代码
% S9 J% `8 \8 z3 m( A4 L; H! N! G! X4 W- t
: `9 Q4 m& }' N* A8 s* Z7 }
|