OpenOCD:Open On-Chip Debugger,自由开源的片上调试和编程工具。
OpenOCD所有的命令索引链接:请点击这里
OpenOCD官方使用手册:https://openocd.org/doc-release/pdf/openocd.pdf
[flash write_image]命令
Command: flash write_image [erase] [unlock] filename [offset] [type]
Write the image filename to the current target’s flash bank(s). Only loadable sections from the image are written. A relocation offset may be specified, in which case it is added to the base address for each section in the image. The file [type] can be specified explicitly as bin (binary), ihex (Intel hex), elf (ELF file), s19 (Motorola s19). mem, or builder. The relevant flash sectors will be erased prior to programming if the erase parameter is given. If unlock is provided, then the flash banks are unlocked before erase and program. The flash bank to use is inferred from the address of each image section.
Warning: Be careful using the erase flag when the flash is holding data you want to preserve. Portions of the flash outside those described in the image’s sections might be erased with no notice.
- When a section of the image being written does not fill out all the sectors it uses, the unwritten parts of those sectors are necessarily also erased, because sectors can’t be partially erased.
- Data stored in sector “holes” between image sections are also affected. For example, “flash write_image erase …” of an image with one byte at the beginning of a flash bank and one byte at the end erases the entire bank – not just the two sectors being written.
Also, when flash protection is important, you must re-apply it after it has been removed by the unlock flag.
译文:将 filename 镜像文件写入当前目标的闪存组。仅写入镜像的第二部分。可以指定重定位偏移量,在这种情况下,它将添加到镜像中每个部分的基地址。文件[type]可以显式指定为 bin (二进制)、 ihex (Intel十六进制)、 elf (ELF文件)、 s19 (Motorola s19)。 mem 或 builder 。如果给定 erase 参数,相关 flash 扇区将在编程之前被擦除。如果提供了 unlock ,则 flash 组在擦除和编程之前被解锁。要使用的 flash 库是从每个镜像部分的地址推断出来的。
警告:当 flash 保存您想要保留的数据时,请小心使用 erase 参数。 flash 的部分以外的那些描述在镜像的部分可能会在没有通知的情况下被删除。
- 当被写入的镜像的一部分没有填满它使用的所有扇区时,这些扇区的未写入部分也必须被擦除,因为扇区不能被部分擦除。
- 存储在镜像部分之间的扇区“孔”中的数据也会受到影响。例如,在 flash 的开头和结尾各有一个字节的镜像的“ flash write_image erase … “会擦除整个 flash ,而不仅仅是写入的两个扇区。
此外,当 flash 保护很重要时,您必须在它被 unlock 标志删除后重新应用它。
注意:flash write_image指令必须指定烧录文件名和地址,如"STM32F103C8T6.bin 0x08000000"。
[program命令]
Command: program filename [preverify] [verify] [reset] [exit] [offset]
This is a helper script that simplifies using OpenOCD as a standalone programmer. The only required parameter is filename, the others are optional. See Flash Programming.
译文:这是一个帮助脚本,可以简化作为独立程序员使用OpenOCD的过程。唯一必需的参数是 filename ,其他都是可选的。详情参见Flash编程。
下面给出一个使用示例。参见程序:
// program and verify using elf/hex/s19. verify and reset are optional parameters
openocd -f board/stm32f3discovery.cfg -c "program filename.elf verify reset exit"
// binary files need the flash address passing
openocd -f board/stm32f3discovery.cfg -c "program filename.bin exit 0x08000000"
flash write_image和program有2种下载方式:
- 使用telnet/tcl端口连接模式,与cmd/powershell终端配合;
- 使用直链下载模式,一条命令行下载,无需新建cmd/powershell终端。
OpenOCD监听端口的各功能:
OpenOCD配置完成并正确连接上开发板后,就会监听6666,4444,3333端口,分别用于tcl, telnet,gdb-server。
tcl, telnet用于下载,gdb-server用于Debug调试。
参考博文:OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)