0、前言
目前stm32h750多数使用keil(仿真器不限)、cubeprog(仅限stlink)和SEGGER(仅限jlink)擦写片内和qspi flash,而开源的pyocd无法很好的支持qspi flash的擦写。随着对openocd环境知识的积累了解到它已经支持stmqspi,今天尝试配置openocd来支持ART_Pi外部flash的擦写。
1、实操
首先来看看我编写的脚本art_pi.cfg:
Port F: PF10:AF09:H, PF09:AF10:H, PF08:AF10:H, PF07:AF09:H, PF06:AF09:H
mmw 0x58021400 0x002AA000 0x00155000 ;# MODER
mmw 0x58021408 0x002AA000 0x00155000 ;# OSPEEDR
mmw 0x5802140C 0x00000000 0x003FF000 ;# PUPDR
mmw 0x58021420 0x99000000 0x66000000 ;# AFRL
mmw 0x58021424 0x000009AA 0x00000655 ;# AFRH
Port G: PG06:AF10:H
mmw 0x58021800 0x00002000 0x00001000 ;# MODER
mmw 0x58021808 0x00002000 0x00001000 ;# OSPEEDR
mmw 0x5802180C 0x00000000 0x00003000 ;# PUPDR
mmw 0x58021820 0x0A000000 0x05000000 ;# AFRL
以上是使用gpio_conf_stm32.pl脚本生成的引脚配置,脚本中有以下内容用于自动生成寄存器配置:
ART_Pi dual quad
$GPIO_BASE = 0x58020000;
$Conf = "PG06:AF10:H, PF06:AF09:H, PF07:AF09:H, PF08:AF10:H, PF09:AF10:H, PF10:AF09:H";
字段的意思分别是引脚编号、复用功能、引脚速率。运行gpio_conf_stm32.pl会有如下输出:
u@WINDOWS10:/mnt/c/Users/u/Desktop/openocd$ ./gpio_conf_stm32.pl
0x3FC 0x58021814 6 0x58021414 6
0x58021414 7 0x58021414 8
0x58021414 9 0x58021414 10
PF10:AF09:H, PF09:AF10:H, PF08:AF10:H, PF07:AF09:H, PF06:AF09:H, PG06:AF10:H
Port F: PF10:AF09:H, PF09:AF10:H, PF08:AF10:H, PF07:AF09:H, PF06:AF09:H
mmw 0x58021400 0x002AA000 0x00155000 ;# MODER
mmw 0x58021408 0x002AA000 0x00155000 ;# OSPEEDR
mmw 0x5802140C 0x00000000 0x003FF000 ;# PUPDR
mmw 0x58021420 0x99000000 0x66000000 ;# AFRL
mmw 0x58021424 0x000009AA 0x00000655 ;# AFRH
Port G: PG06:AF10:H
mmw 0x58021800 0x00002000 0x00001000 ;# MODER
mmw 0x58021808 0x00002000 0x00001000 ;# OSPEEDR
mmw 0x5802180C 0x00000000 0x00003000 ;# PUPDR
mmw 0x58021820 0x0A000000 0x05000000 ;# AFRL
u@WINDOWS10:/mnt/c/Users/u/Desktop/openocd$
art_pi.cfg脚本中的qspi_init函数的其它寄存器可以根据注释自己参考stm32h7参考手册做修改配置。
2、连接openocd
运行命令
PS C:\Users\u\Desktop\openocd> openocd -f .\art_pi.cfg
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2022-03-25-17:32)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1800 kHz
Info : STLINK V2J38M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.245093
Info : [stm32h750xbh6.cpu0] Cortex-M7 r1p1 processor detected
Info : [stm32h750xbh6.cpu0] target has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32h750xbh6.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
使用telnet localhost 4444链接到openocd端口:
reset init
flash read_bank 1 xx.bin 0x0 0x20000
flash1 'win w25q64fv/jv' id = 0x1740ef size = 8192kbytes
wrote 131072 bytes to file xx.bin from flash bank 1 at offset 0x00000000 in 0.978964s (130.750 KiB/s)
flash write_image erase u-boot.bin 0x90000000
Device: STM32H74x/75x
flash size probed value 128k
STM32H7 flash has a single bank
Bank (0) size is 128 kb, base address is 0x08000000
Adding extra erase range, 0x90043a69 .. 0x9004ffff
auto erase enabled
wrote 277097 bytes from file u-boot.bin in 3.508002s (77.139 KiB/s)
以上三条命令分别是初始化、读取128kb flash、擦写qspi flash。
原作者:lizimu