使用 OpenOCD 读取 STM32 唯一设备 ID
使用 STM32 系列微控制器时,使用 JTAG 评估工厂编程的 96 位 UUID 可能很有用。在所有主要操作系统上,OpenOCD 提供了一个简单但高度兼容且免费的解决方案来执行此操作。
在此示例中,我们将使用 JLink 适配器和 Olimex E407 评估板。适配器和板都是可互换的,前提是你有可用的 OpenOCD 配置。
根据 STM32F4 参考手册,UUID 存储在内存地址 0x1FFF 7A10(参见 39.1 节)。从此地址开始,我们必须读取三次 32 位(即 3 个字)的内存以获取完整 UUID。
为此,我们可以使用 OpenOCD 通用命令中记录的 mdw 命令
read-unique-id-openocd.sh
openocd -f interface/jlink.cfg -f olimex-e407.cfg -c "init" -c "$target_name mdw 0x1FFF7A10 3" -c "exit"此脚本告诉 OpenOCD 首先初始化目标设备,然后从 0x1FFF7A10 开始读取 3 个字并立即退出。
示例输出:
openocd-output-example.txt
Open On-Chip Debugger 0.7.0 (2013-06-15-20:16)
Licensed under GNU GPL v2
For bug reports, read
https://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
cortex_m3 reset_config sysresetreq
Info : J-Link initialization started / target CPU reset initiated
Info : J-Link ARM V8 compiled Jun 19 2012 11:29:30
Info : J-Link caps 0xb9ff7bbf
Info : J-Link hw version 80000
Info : J-Link hw type J-Link
Info : J-Link max mem block 9320
Info : J-Link configuration
Info : USB-Address: 0x0
Info : Kickstart power on JTAG-pin 19: 0xffffffff
Info : Vref = 3.345 TCK = 1 TDI = 0 TDO = 0 TMS = 0 SRST = 0 TRST = 0
Info : J-Link JTAG Interface ready
Info : clock speed 1000 kHz
Info : JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020, part: 0x6413, ver: 0x0)
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
0x1fff7a10: 00370021 32314718 39313739最后一行首先显示读取的地址,后跟表示三个 32 位 UUID 部分的三个十六进制数字。
使用其他板或接口时,只需将 -f 引用的脚本替换为适当的 OpenOCD 脚本。
虽然我没有详细检查,但我假设其他 STM32 系列将 UUID 存储在同一地址。
Check out similar posts by category:
Embedded
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow