? ? ? ? CH347是一款USB转多接口芯片,可在OpenOCD中增添对应接口,实现OpenOCD操作CH347,进行调试下载等应用。
一、CH347简介
????????CH347是一款国产USB2.0(480Mbps)转接芯片,可以通过USB转出UART、SPI、JTAG、I2C以及8路GPIO等接口。其JTAG时钟频率最高可为72Mbps且频率可调。
二、OpenOCD简介
????????OpenOCD是一款开源的片上调试器软件,提供了片上编程和调试功能,若需要添加新的调试器接口,可在源码中通过修改相关配置文件,并添加对应操作硬件的实现代码后编译即可实现新接口的使用。
三、为OpenOCD添加接口
????????OpenOCD需要识别并操作CH347,则需要添加如下文件:
????????1、tcl/target中添加CH347.cfg设备文件CH347.cfg
adapter driver ch347
ch347 vid_pid 0x1a86 0x55dd
adapter speed 10000
????????2、src/jtag/driver/ch347.c文件,设备驱动文件,提供给JTAG core操作的接口
????????可从仓库获取,仓库地址:https://github.com/WCHSoftGroup/ch347
四、修改配置文件
configure.ac
a.m4_define([USB1_ADAPTERS]中添加CH347接口
m4_define([USB1_ADAPTERS],
[[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]],
[[ch347], [Mode 3 of the CH347 devices], [CH347]],
[[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]],
[[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]],
[[ulink], [Keil ULINK JTAG Programmer], [ULINK]],
[[usb_blaster_2], [Altera USB-Blaster II Compatible], [USB_BLASTER_2]],
[[ft232r], [Bitbang mode of FT232R based devices], [FT232R]],
[[vsllink], [Versaloon-Link JTAG Programmer], [VSLLINK]],
[[xds110], [TI XDS110 Debug Probe], [XDS110]],
[[cmsis_dap_v2], [CMSIS-DAP v2 Compliant Debugger], [CMSIS_DAP_USB]],
[[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]],
[[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]],
[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]],
[[rlink], [Raisonance RLink JTAG Programmer], [RLINK]],
[[usbprog], [USBProg JTAG Programmer], [USBPROG]],
[[aice], [Andes JTAG Programmer], [AICE]]])
b.AC_ARG_ENABLE 部分,添加内容如下:
AC_ARG_ENABLE([ch347],
AS_HELP_STRING([--enable-ch347], [Enable building support for CH347]),
[build_ch347=$enableval], [build_ch347=no])
c.AS_IF 部分,添加内容如下:
AS_IF([test "x$build_ch347" = "xyes"], [
AC_DEFINE([BUILD_CH347], [1], [1 if you want CH347.])
], [
AC_DEFINE([BUILD_CH347], [0], [0 if you don't want CH347.])
])
d.AM_CONDITIONAL 部分,添加内容如下:
AM_CONDITIONAL([CH347], [test "x$build_ch347" = "xyes"])
src/jtag/interfaces.c
a.添加编译选项
#if BUILD_CH347 == 1
extern struct adapter_driver ch347_adapter_driver;
#endif
b.在jtag接口列表结构体adapter_drivers中添加,此处由配置脚本来启用对应接口驱动
#if BUILD_CH347 == 1
&ch347_adapter_driver,
#endif
/src/jtag/drivers/Makefile.am
a.添加编译支持
if CH347
DRIVERFILES += %D%/ch347.c
endif
五、编译
????????1、使用cygwin进行编译,cygwin编译依赖大概如下:
? ? ? ? ?2、Cygwin进入修改好的源码目录下,进行如下步骤
1、执行./bootstrap
2、执行./configure --prefix=/home/OpenOCD/CH347 --enable-ch347 --host=i686-w64-mingw32 CFLAGS='-g -o0'
3、执行make install
4、到/home/OpenOCD/CH347文件夹下可看见编译后文件,其中bin文件下为OpenOCD可执行文件。
????????3、执行./configure后显示已经支持该接口,此处只编译部分接口。
?????????至此,接口添加操作完毕,使用Windows终端,通过OpenOCD可看见已扫描到FPGA ID信息,接着即可愉快开始下一步操作了。
|