目录
CH347介绍
CH347是一款高速USB总线转接芯片,通过USB总线提供异步串口、I2C同步串行接口、SPI同步串行接口和JTAG接口等。芯片资源如下:
- 2个高速串口,最高波特率达9Mbps
- 1个2线I2C接口
- 1个4线SPI接口,最高速率60MHz
- 1个JTAG接口,最高速率60MHz
- 1个SWD接口
芯片封装分为T/F两种,CH347F可多功能同时使用,CH347T则需要进行相应模式切换。
openFPGALoader简介
类似于成熟的openOCD项目,openFPGALoader主要专注于对FPGA的固件下载,支持Xilinx, Altera/Intel, Lattice, Gowin等常见FPGA。
项目链接:https://github.com/ZhiyuanYuanNJ/openFPGALoader/tree/master
openFPGALoader安装
Windows、Linux、mac均可参照官方链接,按步骤执行:
安装
openFPGALoader使用
CH347F对XILINX SPARTAN-6系列XC6SLX9做下载
Linux系统:
- 使用lsusb查看硬件是否连接:
home:~/develop_pro/openFPGALoader_github/openFPGALoader/build$ lsusb
Bus 003 Device 007: ID 1a86:55de QinHeng Electronics UART+SPI+I2C+JTAG
- 使用detect指令查看是否识别此FPGA:
sudo ./openFPGALoader -c ch347_jtag --pid 0x55de --detect
empty
Cable PID overridden
JTAG TCK frequency set to 7.500 MHz
index 0:
idcode 0x4001093
manufacturer xilinx
family spartan6
model xc6slx9
irlength 6
注:默认PID为CH347T模式3:0x55DD,此处需指定PID。
- 下载固件:
sudo ./openFPGALoader -c ch347_jtag --pid 0x55de --freq 30000000 -B spiOverJtag_xc6slx9csg324.bit.gz -f led_test.bit
empty
write to flash
Cable PID overridden
JTAG TCK frequency set to 30.000 MHz
Open file DONE
Parse file DONE
use: spiOverJtag_xc6slx9csg324.bit.gz
load program
Load SRAM: [==================================================] 100.00%
Done
Detected: ST M25P16 32 sectors size: 16Mb
00000000 00000000 00000000 00
Erasing: [==================================================] 100.00%
Done
Writing: [==================================================] 100.00%
Done
重写上电,检查固件下载情况。
注:此处spiOverJtag_xc6slx9csg324.bit.gz文件为该FPGA的JTAG/SPI的桥接文件,位于源码中spiOverJtag目录下。
Windows系统:
Windows系统指令与Linux类似,需安装MSYS2编译,需提前安装CH347的Windows JTAG驱动
编译方法:
mkdir build;cd build;cmake ..;cmake --build .
...
...
[49/49] Linking CXX executable openFPGALoader.exe
detect FPGA:
lzy@DESKTOP-NM6R9PE MINGW64 /c/Users/lzy/Desktop/openFPGALoader/build
$ openFPGALoader.exe -c ch347_jtag --detect
CH347 Open Success.
JTAG TCK frequency set to 7.500 MHz
index 0:
idcode 0x4001093
manufacturer xilinx
family spartan6
model xc6slx9
irlength 6
Close the CH347.
下载:
lzy@DESKTOP-NM6R9PE MINGW64 /c/Users/lzy/Desktop/openFPGALoader/build
$ ./openFPGALoader -c ch347_jtag --freq 30000000 -B ../spiOverJtag/spiOverJtag_xc6slx9csg324.bit.gz -f led_test.bit
empty
write to flash
CH347 Open Success.
JTAG TCK frequency set to 30.000 MHz
Open file DONE
Parse file DONE
use: C:/Users/lzy/Desktop/openFPGALoader/spiOverJtag/spiOverJtag_xc6slx9csg324.bit.gz
load program
Load SRAM: [==================================================] 100.00%
Done
Shift IR b5
ir: 1 isc_done 1 isc_ena 0 init 1 done 1
Detected: ST M25P16 32 sectors size: 16Mb
00000000 00000000 00000000 00
Erasing: [==================================================] 100.00%
Done
Writing: [==================================================] 100.00%
Done
Close the CH347.
关于openFPGALoader的更多功能信息可查阅官方文档。
特别说明(重要)
- 下载速度指定
下载命令中的--freq
为指定速率命令,CH347支持速率如下
速度0:468.75KHZ;
速度1:937.5KHZ;
速度2:1.875MHZ;
速度3:3.75MHZ;
速度4:7.5MHZ;
速度5:15MHZ;
速度6:30MHZ;
速度7:60MHZ
因此--freq 30000000
,指定JTAG速率为30MHZ
。
--freq 100
,指定JTAG速率为468.75KHZ
(速率默认向上适配)。
2. 指定流文件
-B
对于一些FPGA芯片(intel/xilinx),固化程序时需要指定bitstream文件,具体可参考源码中spiOverJtag文件夹中的文件,
如-B ../spiOverJtag/spiOverJtag_xc6slx9csg324.bit.gz
3. -f
固化指令
使用-f led_test.bit
将改文件固化至flash中。
4. -m
写入sram
如:./openFPGALoader -c ch347_jtag --freq 1875000 -f led_test.bit
以1.875MHZ的JTAG速率下载led_test.bit,因不涉及固化操作,无需使用-B
命令去指定流文件
5. 程序的输出说明
load program
Load SRAM: [==================================================] 100.00%
Done
# 说明此时下载至sram完成
# 固化程序第一步会将指定的流文件下载至sram中
Shift IR b5
ir: 1 isc_done 1 isc_ena 0 init 1 done 1
Detected: ST M25P16 32 sectors size: 16Mb
00000000 00000000 00000000 00
Erasing: [==================================================] 100.00%
Done
Writing: [==================================================] 100.00%
Done
# openFPGALoader正确识别到当前的flash型号容量和大小,并固化成功
固化时的错误
Load SRAM: [==================================================] 100.00%
Done
Detail:
Jedec ID : ff
memory type : ff
memory capacity : ff
flash chip unknown: use basic protection detection
unlock blocks
timeout: ff ff ff
ff
wait: Error
写入sram是成功了,但未能识别到flash。
首先检查-B
命令是否指定了FPGA相对应的流文件。
其次--freq
命令降低JTAG速率,重新尝试,直至最低速率。
程序文件
这里提供了编译好的Windows 10版本:
https://github.com/ZhiyuanYuanNJ/openFPGALoader/releases/tag/openFPGALoader_CH347_WIN10_V1.0