STM32: Black Magic Probe @ BRO-DBG-LINK-V2-1

通过gdb(arm-none-eabi-gdb) 调试STM32系列MCU, 我们可以通过gdb + OpenOCD + ST-LINK/V2的方式进行在线调试。而Black Magic Proble的出现,使得我们我们可以直接通过gdb + Black Maigc Probe进行在线调试。由于不需要OpenOCD作媒介,进行在线调试会方便很多。

从https://github.com/blacksphere/blackmagic/wiki/Debugger-Hardware可以了解到Black Magic Probe除了Native Hardware: Black Magic Probe Mini V2.0 (BMPM2)/Black Magic Probe Mini V1.0(BMPM1)/Black Magic Probe外,还支持FTDI target, ST Link,F4 Discovery,SW Link及Launchpad ICDI。由于BRO-DBG-LINK-V2-1是与ST-LINK兼容的硬件,这使得我们可以在BRO-DBG-LINK-V2-1上运行Black Magic Probe固件。

关于ST Link的支持情况,请看http://esden.net/2014/12/29/black-magic-discovery/。

  • 关于Black Magic Probe

1. 介绍(https://github.com/blacksphere/blackmagic/wiki):

The Black Magic Probe is a modern, in-application debugging tool for embedded microprocessors. It allows you see what is going on ‘inside’ an application running on an embedded microprocessor while it executes. It is able to control and examine the state of the target microprocessor using a JTAG or Serial Wire Debugging (SWD) port and on-chip debug logic provided by the microprocessor. The probe connects to a host computer using a standard USB interface. The user is able to control exactly what happens using the GNU source level debugging software, GDB.

2016_10_29_black_magic_mini_v2

(图为 Black Magic Probe Mini V2.0)

2. 特点(https://github.com/blacksphere/blackmagic/wiki):

  • Targets ARM Cortex-M and Cortex-A based microcontrollers.
  • Connects to the target processor using the JTAG or Serial Wire Debug (SWD) interface.
  • Provides full debugging functionality, including: watchpoints, flash memory breakpoints, memory and register examination, flash memory programming, etc.
  • Semihosting / Host IO support
  • Interface to the host computer is a standard USB CDC ACM device (virtual serial port), which does not require special drivers on Linux or OS X.
  • Implements the GDB extended remote debugging protocol for seamless integration with the GNU debugger and other GNU development tools.
  • Implements USB DFU class for easy firmware upgrade as updates become available.
  • Works with Windows, Linux and Mac environments.
  • 代码下载及编译

1. 代码下载

$ git clone https://github.com/blacksphere/blackmagic.git

由于代码中包含子模块libopencm3, 还需要如下操作:

$ cd backmagci
$ git submodule init
$ git submodule update

NOTE:

如果执行”git submodule update”更新速度太慢,可以通过如下方法:

$ git clone https://github.com/libopencm3/libopencm3.git
$ git submodule update

2. 编译代码

$ make PROBE_HOST=stlink

最终会在src目录下生成我们所需的bin/hex文件:

$ make PROBE_HOST=stlink
  GENHDR  include/libopencm3/efm32/efm32g/irq.json
  GENHDR  include/libopencm3/efm32/efm32gg/irq.json
  GENHDR  include/libopencm3/efm32/efm32lg/irq.json
  GENHDR  include/libopencm3/efm32/efm32tg/irq.json
...
  CC      platforms/stm32/serialno.c
  CC      platforms/common/timing.c
  CC      platforms/stm32/timing_stm32.c
  LD      blackmagic
  OBJCOPY blackmagic.bin
  CC      platforms/stlink/usbdfu.c
  CC      platforms/stm32/dfucore.c
  CC      platforms/stm32/dfu_f1.c
  LD      blackmagic_dfu
  OBJCOPY blackmagic_dfu.bin
  OBJCOPY blackmagic_dfu.hex
  CC      platforms/stlink/dfu_upgrade.c
  LD      dfu_upgrade
  OBJCOPY dfu_upgrade.bin
  OBJCOPY dfu_upgrade.hex

这里我们注意到会长成3个bin/hex文件:

- backmagic

- backmagic_dfu

- dfu_upgrade

整个Flash被化分成两个部分:

- bootloader:占用0x2000个字节,存放的是backmagic_dfu文件,用于加载与更新固件。

- app:起始位置为(0x08002000)存放的是backmaigc或者是dfu_upgrade文件,dfu_upgrade固件用于更新bootloader。

  • 固件下载及更新

1. 下载bootloader文件,可通过OpenOCD + ST-LINK/V2-1下载

$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfg -c init -c 'reset halt' -c 'flash write_image erase src/blackmagic_dfu.bin 0x08000000 bin' -c 'verify_image src/blackmagic_dfu.bin 0x08000000 bin' -c 'reset run' -c shutdown

2. 下载app文件

$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfg -c init -c 'reset halt' -c 'flash write_image erase src/blackmagic.bin 0x08002000 bin' -c 'verify_image src/blackmagic.bin 0x08002000 bin' -c 'reset run' -c shutdown

由于bootloader支持标准的dfu协议,也可通过dfu-util工具下载:

通过dfu-util工具更新firmware(https://github.com/blacksphere/blackmagic/wiki/Upgrading-Firmware):

$ dfu-util -d 1d50:6018,:6017 -s 0x08002000:leave -D src/blackmagic.bin 
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 1d50:6017
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 1024
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x08002000, size = 54568
Download	[=========================] 100%        54568 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state
  • 相关的参考文档
  1. http://www.blacksphere.co.nz/
  2. https://github.com/blacksphere/blackmagic
  3. https://github.com/blacksphere/blackmagic/wiki
  4. https://github.com/blacksphere/blackmagic/wiki/Getting-Started
  5. http://esden.net/2014/12/29/black-magic-discovery/

评论

Be the First to Comment!

提醒我
avatar

wpDiscuz