在 Raspberry Pi 上使用 OpenOCD 对 STM32F4 进行编程 4

Programing an STM32F4 with OpenOCD on Raspberry Pi 4

我正在尝试通过 SWD 接口在 STM32F407 上刷新引导加载程序,有问题的板是 Makerbase Robin Nano v3,这是一个 3d 打印机控制器板。

我的 Raspberry Pi 4 上有 OpenOCD 运行,我可以读取内部存储器的扇区

问题是我不会写,我也不知道为什么。

我尝试了一个简单的测试

READ  -> stm32f4.cpu mdb 0x8000000 -> output: 0xFF
WRITE -> stm32f4.cpu mwb 0x8000000 0xAA -> no output
READ  -> stm32f4.cpu mdb 0x8000000 -> output: 0xFF // didn't change

写入特定字节似乎不起作用。

如果我尝试用 load_image 编程,这就是输出

> load_image nano_v3_bootloader.bin 0x8000000     
SWD DPIDR 0x2ba01477
Failed to write memory and, additionally, failed to find out where

SWD DPIDR 0x2ba01477

如果我尝试用 program 编程,这就是输出

> program nano_v3_bootloader.bin 0x8000000
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
SWD DPIDR 0xdeadbeef
Failed to write memory and, additionally, failed to find out where
error writing to flash at address 0x08000000 at offset 0x00000000
embedded:startup.tcl:308: Error: auto erase enabled

at file "embedded:startup.tcl", line 308

我是 ARM 的新手,我猜可能是引导加载程序被锁定了(我尝试用 stm32f4x unlock 0 解锁它,似乎没有什么区别),或者我正在做一些事情顺序错误或某处遗漏了一个步骤。

如果有人能帮我弄清楚我做错了什么,我将不胜感激

这是我的openocd.cfg

source [find interface/raspberrypi2-native.cfg]
transport select swd

set CHIPNAME stm32f4
source [find target/stm32f4x.cfg]

# did not yet manage to make a working setup using srst
#reset_config srst_only
reset_config  srst_nogate

adapter_nsrst_delay 100
adapter_nsrst_assert_width 100

init
targets
reset halt

这是我的 raspberrypi2_native.cfg

#
# Config for using Raspberry Pi's expansion header
#
# This is best used with a fast enough buffer but also
# is suitable for direct connection if the target voltage
# matches RPi's 3.3V and the cable is short enough.
#
# Do not forget the GND connection, pin 6 of the expansion header.
#

adapter driver bcm2835gpio

bcm2835gpio_peripheral_base 0xFE000000

# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
# These depend on system clock, calibrated for stock 700MHz
# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET
bcm2835gpio_speed_coeffs 236181 60

# Each of the JTAG lines need a gpio number set: tck tms tdi tdo
# Header pin numbers: 23 22 19 21
bcm2835gpio_jtag_nums 11 25 10 9

# Each of the SWD lines need a gpio number set: swclk swdio
# Header pin numbers: 23 22
bcm2835gpio_swd_nums 25 24

# If you define trst or srst, use appropriate reset_config
# Header pin numbers: TRST - 26, SRST - 18

# bcm2835gpio_trst_num 7
# reset_config trst_only

bcm2835gpio_srst_num 18
reset_config srst_only srst_push_pull

# or if you have both connected,
# reset_config trst_and_srst srst_push_pull

运行这些命令解决了问题

> flash erase_sector 0 0 11 // this will erase bank 0
> flash write_bank 0 nano_v3_bootloader.bin 0 // this will write the bin file to the bank 0