gpt4 book ai didi

stm32f4 - Openocd如何将选项字节写入STM32F4

转载 作者:行者123 更新时间:2023-12-05 02:16:53 24 4
gpt4 key购买 nike

我有两 block 带有 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"

这导致错误消息:“错误:stm32x 设备 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 session 中尝试了以下操作:

  1. mww 0x08 0x08192A3B
  2. mww 0x08 0x04C5D6E7F
  3. mdw 0x0C
  4. mww 0x18 0x0EC
  5. mww 0x14 0x0EC

第1行0x08为FLASH_OPTKEYR,第3行0x0C为FLASH_SR,检查BSY位是否未设置,第4行0x14为FLASH_OPTCR1,第5行0x14为FLASH_OPTCR。

然后重新启动并尝试对应用程序进行编程openocd -f openocd.cfg -c "p​​rogram HCF-220_07_010_PA2.hex reset exit"

这会导致错误:

Error: stm32x device protected.

我还尝试在编程前执行以下命令解锁:openocd -f openocd.cfg -c "openocd -f openocd.cfg -c "重置暂停; stm32f2x解锁0;程序 HCF-220_07_010_PA2.hex 重置退出”

同样的结果:

Error: stm32x device protected.

更新

我在 telnet 中尝试了以下但没有成功,用户选项仍然是 0xCFC:

  1. mww 0x40023C08 0x08192A3B
  2. mww 0x40023C08 0x04C5D6E7F
  3. mdw 0x40023c0c
  4. mww 0x40023C18 0x0EC
  5. mww 0x40023C14 0x0EC
  6. mww 0x40023C08 0x02
  7. 电源循环

在 RM0090 第 3.7.2 章中,它还说:4。在 FLASH_OPTCR 寄存器中设置选项起始位 (OPTSTRT)因此,上面的 nr 6.

最佳答案

我的工作解决方案如下:

  1. stm32f2x lock 0 是锁不解锁。
  2. 执行电源循环
  3. 重置初始化
  4. mww 0x40023C08 0x08192A3B
  5. mww 0x40023C08 0x04C5D6E7F
  6. mdw 0x40023c0c 等待闪存写入完成,确保我们收到 00000000
  7. mww 0x40023C18 0x0FFF0000
  8. mww 0x40023C14 0x0FFFAAEC 将 user_options 写入与工作相同
  9. mww 0x40023C14 0x0FFFAAEE 设置选项起始位,步骤“4”。在 rm0090。
  10. mdw 0x40023c0c 等待闪存删除完成,确保我们收到 00000。这大约需要 10 秒。
  11. 执行电源循环

它不能与 OpenOCD 命令“options_write”一起工作的原因,可以在 OpenOCD 手册中找到。 “user_options”参数采用来自 FLASH_OPTCR 的位 31-28 和 7-0。

关于stm32f4 - Openocd如何将选项字节写入STM32F4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48927028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com