1. 安装MinGW64
MinGW-w64 官方网站的地址是:http://mingw-w64.org ,点击红框中的“Downloads”超链接,进入 MinGW-w64 下载详情页面。
2. 安装Msys2
3. 配置工具链及基本编译需要的工具及库文件:
# pacman -Syu
# pacman -S --needed base-devel
# pacman -S mingw-w64-i686-pkg-config
# pacman -S --needed autoconf
# pacman -S --needed automake
# pacman -S --needed libtool
# pacman -S mingw-w64-x86_64-libftdi
# pacman -S mingw-w64-x86_64-libusb
# pacman -S mingw-w64-x86_64-libftdi
4. 如果编译OpenOCD支持cmsis-dap,还需要安装HIDAPI库,下载 hidapi:
$ cd ~
$ git clone https://github.com/signal11/hidapiGitHub - signal11/hidapi: A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows.A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows. - GitHub - signal11/hidapi: A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows.https://github.com/signal11/hidapi.git
$ cd hidapi
$ ./bootstrap
$ ./configure --disable-shared
$ make
$ make install
$ cd ~
会把 hidapi 库安装到 /usr/local/lib 目录下,
$ ll /usr/local/lib 应是这样:
5. OpenOCD 编译时默认连接 hidapi 和 libusb-1.0 以及libftdi1的动态库,因此把静态库覆盖动态库
$ cp /usr/local/lib/libhidapi.a /usr/local/lib/libhidapi.dll.a
$ cp /usr/local/lib/libusb-1.0.a /usr/local/lib/libusb-1.0.dll.a
$ cp /usr/local/lib/libftdi1.a /usr/local/lib/libftdi1.dll.a
7. 下载RISC-V对应的Openocd:
$ git clone https://github.com/riscv/riscv-openocd.git
8. 依次执行以下命令:
$./bootstrap
$ ./configure --prefix=/home/bin --enable-fdti --enable-jlink --enable-ftdi-oscan1 --enable-cmsis-dap --enable-static=yes --disable-shared PKG_CONFIG_PATH=/mingw64/lib/pkgconfig
$ make && make install
9. 最后在/home/bin下生成不需要依赖动态库的OpenOCD,用生成的OpenOCD连接GD32VF103V如下所示: