Openocd如何将选项字节写入STM32F4
Openocd how to write option bytes to STM32F4
我有两块带有 STM32F437 (IGH6 7BA4S VQ PHL 7B 542) 处理器的开发板。我们用 openocd 和 jtag 对它们进行编程,但是最近有一张卡停止工作了。不再可能对卡进行编程,我们发现的差异之一是卡之间的用户选项字节不同。
- 0x0EC 在工作卡上
- 0xCFC 就坏了
我尝试做的是使用 options_write 命令。请注意,STM32F4 显然在 "stm32f2x" 命令下。
openocd -f openocd.cfg -c "reset halt; stm32f2x unlock 0; reset halt; stm32f2x options_write 0 0x0EC"
这导致错误消息:"Error: stm32x device protected"
在 STM32F437 参考手册 RM0090 的“3.7.2 编程用户选项字节”下,它说:
To run any operation on this sector, the option lock bit (OPTLOCK) in the Flash option
control register (FLASH_OPTCR) must be cleared. To be allowed to clear this bit, you have
to perform the following sequence: \n
- Write OPTKEY1 = 0x0819 2A3B in the Flash option key register (FLASH_OPTKEYR)
- Write OPTKEY2 = 0x4C5D 6E7F in the Flash option key register (FLASH_OPTKEYR)
The user option bytes can be protected against unwanted erase/program operations by
setting the OPTLOCK bit by software.
为此,我在 telnet 会话中尝试了以下操作:
mww 0x08 0x08192A3B
mww 0x08 0x04C5D6E7F
mdw 0x0C
mww 0x18 0x0EC
mww 0x14 0x0EC
第1行0x08为FLASH_OPTKEYR,第3行0x0C为FLASH_SR检查BSY位是否未设置,第4行0x14为FLASH_OPTCR1,0x14为第 5 行是 FLASH_OPTCR.
然后重新启动并尝试对应用程序进行编程
openocd -f openocd.cfg -c "program HCF-220_07_010_PA2.hex reset exit"
这会导致错误:
Error: stm32x device protected.
我也试过在编程前执行以下命令解锁:
openocd -f openocd.cfg -c "openocd -f openocd.cfg -c "reset halt; stm32f2x unlock 0; program HCF-220_07_010_PA2.hex reset exit"
同样的结果:
Error: stm32x device protected.
更新
我在 telnet 中尝试了以下但没有成功,用户选项仍然是 0xCFC:
mww 0x40023C08 0x08192A3B
mww 0x40023C08 0x04C5D6E7F
mdw 0x40023c0c
mww 0x40023C18 0x0EC
mww 0x40023C14 0x0EC
mww 0x40023C08 0x02
Power Cycle
在 RM0090 第 3.7.2 章中还说:4. Set the option start bit (OPTSTRT) in the FLASH_OPTCR register
因此上面的 nr 6.
Flash 寄存器基地址为 0x40023C00(根据 RM0090)。 0x08 是相对于 base 的偏移量,所以你应该写入 0x40023C08
我的工作解决方案如下:
stm32f2x lock 0
是锁定未解锁。
- 执行电源循环
reset init
mww 0x40023C08 0x08192A3B
mww 0x40023C08 0x04C5D6E7F
mdw 0x40023c0c
等待闪存写入完成,确保我们收到 00000000
mww 0x40023C18 0x0FFF0000
mww 0x40023C14 0x0FFFAAEC
写入 user_options 与工作相同
mww 0x40023C14 0x0FFFAAEE
设置选项起始位,步骤“4”。在 rm0090.
mdw 0x40023c0c
等待闪存擦除完成,确保我们收到 00000。这大约需要 10 秒。
- 执行电源循环
它不能与 OpenOCD 命令一起工作的原因 "options_write",可以在 OpenOCD 手册中找到。 "user_options" 参数从 FLASH_OPTCR 中获取位 31-28 和 7-0。
我有两块带有 STM32F437 (IGH6 7BA4S VQ PHL 7B 542) 处理器的开发板。我们用 openocd 和 jtag 对它们进行编程,但是最近有一张卡停止工作了。不再可能对卡进行编程,我们发现的差异之一是卡之间的用户选项字节不同。
- 0x0EC 在工作卡上
- 0xCFC 就坏了
我尝试做的是使用 options_write 命令。请注意,STM32F4 显然在 "stm32f2x" 命令下。
openocd -f openocd.cfg -c "reset halt; stm32f2x unlock 0; reset halt; stm32f2x options_write 0 0x0EC"
这导致错误消息:"Error: stm32x device protected"
在 STM32F437 参考手册 RM0090 的“3.7.2 编程用户选项字节”下,它说:
To run any operation on this sector, the option lock bit (OPTLOCK) in the Flash option control register (FLASH_OPTCR) must be cleared. To be allowed to clear this bit, you have to perform the following sequence: \n
- Write OPTKEY1 = 0x0819 2A3B in the Flash option key register (FLASH_OPTKEYR)
- Write OPTKEY2 = 0x4C5D 6E7F in the Flash option key register (FLASH_OPTKEYR)
The user option bytes can be protected against unwanted erase/program operations by setting the OPTLOCK bit by software.
为此,我在 telnet 会话中尝试了以下操作:
mww 0x08 0x08192A3B
mww 0x08 0x04C5D6E7F
mdw 0x0C
mww 0x18 0x0EC
mww 0x14 0x0EC
第1行0x08为FLASH_OPTKEYR,第3行0x0C为FLASH_SR检查BSY位是否未设置,第4行0x14为FLASH_OPTCR1,0x14为第 5 行是 FLASH_OPTCR.
然后重新启动并尝试对应用程序进行编程
openocd -f openocd.cfg -c "program HCF-220_07_010_PA2.hex reset exit"
这会导致错误:
Error: stm32x device protected.
我也试过在编程前执行以下命令解锁:
openocd -f openocd.cfg -c "openocd -f openocd.cfg -c "reset halt; stm32f2x unlock 0; program HCF-220_07_010_PA2.hex reset exit"
同样的结果:
Error: stm32x device protected.
更新
我在 telnet 中尝试了以下但没有成功,用户选项仍然是 0xCFC:
mww 0x40023C08 0x08192A3B
mww 0x40023C08 0x04C5D6E7F
mdw 0x40023c0c
mww 0x40023C18 0x0EC
mww 0x40023C14 0x0EC
mww 0x40023C08 0x02
Power Cycle
在 RM0090 第 3.7.2 章中还说:4. Set the option start bit (OPTSTRT) in the FLASH_OPTCR register
因此上面的 nr 6.
Flash 寄存器基地址为 0x40023C00(根据 RM0090)。 0x08 是相对于 base 的偏移量,所以你应该写入 0x40023C08
我的工作解决方案如下:
stm32f2x lock 0
是锁定未解锁。- 执行电源循环
reset init
mww 0x40023C08 0x08192A3B
mww 0x40023C08 0x04C5D6E7F
mdw 0x40023c0c
等待闪存写入完成,确保我们收到 00000000mww 0x40023C18 0x0FFF0000
mww 0x40023C14 0x0FFFAAEC
写入 user_options 与工作相同mww 0x40023C14 0x0FFFAAEE
设置选项起始位,步骤“4”。在 rm0090.mdw 0x40023c0c
等待闪存擦除完成,确保我们收到 00000。这大约需要 10 秒。- 执行电源循环
它不能与 OpenOCD 命令一起工作的原因 "options_write",可以在 OpenOCD 手册中找到。 "user_options" 参数从 FLASH_OPTCR 中获取位 31-28 和 7-0。