USB转串口,FTDI的产品是最好的,其它的都有缺陷。

1 FT2232主要特性
1)2232表示支持2个RS232。
2)FT2232D最高支持full-speed,所以时钟是12MHz;而FT2232H最高支持high-speed,所以时钟是60MHz。
3)FT2232的Port A和Port B会在Windows设备管理器的“通用串行总线控制器”下产生2个设备。绝大部分的MCU JTAG工具都是基于FT2232制作的,FT2232的其中一个Port作为JTAG,另一个Port作为UART用来打印调试log。
4)Port A和Port B的初始配置放置在一个SOP8 EEPROM中。
5)FT2232缺少对一些特殊接口控制信号的支持,可以使用FPGA扩展,FPGA的固件通过FT2232下载,保存在SPI NOR Flash中。
6)PC驱动架构:ftdibus.inf, ftdiport.inf
Figure 1-1 Windows CDM Driver Architecture

2 Bit-Bang
2.1 基本概念
1)Use software to control serial communication at general-purpose I/O pins。
2)对接传统的很多基于PC LPT并口模拟的外设。
3)用GPIO模拟I2C和SPI都称为Bit-Bang。
4)FT_SetBitMode()的参数ucMask对应bit为0表示input,反之则为output。

2.2 Bit-Bang分类
1)异步Bit-Bang - 0x01
2)同步Bit-Bang - 0x04
3)CBUS Bit-Bang - 0x20
Figure 2-1 ucMode Table

Figure 2-2 CBUS Bit-Bang ucMask

2.3 GPIO读写控制传输
DBUS FTDI_SIO_SET_BITMODE
ucMask对应bit为0表示input,反之则为output
bmRequestType:0x40
bRequest:0x0B
wValue:ucMode << 8 | ucMask
wIndex:bInterfaceNumber + 1
wLength:0

CBUS FTDI_SIO_SET_BITMODE
ucMask的高4位表示方向,低4位表示数值
bmRequestType:0x40
bRequest:0x0B
wValue:0x20 << 8 | ucMask
wIndex:bInterfaceNumber + 1
wLength:0

FTDI_SIO_READ_PINS
bmRequestType:0xC0
bRequest:0x0C
wValue:0
wIndex:bInterfaceNumber + 1
wLength:1
返回一字节buffer

2.4 EEPROM读写控制传输
FTDI_SIO_READ_EEPROM
bmRequestType:0xC0
bRequest:0x90
wValue:0
wIndex:eeprom_addr,u16地址
wLength:2
每次只能返回2字节buffer

FTDI_SIO_WRITE_EEPROM
bmRequestType:0x40
bRequest:0x91
wValue:2字节的EEPROM值,每次只能写2字节
wIndex:eeprom_addr,u16地址
wLength:0

3 MPSSE
3.1 基本概念
FT2232不需要固件程序,因为所有功能都由芯片硬件实现,the FT2232D, FT232H, FT2232H and FT4232H incorporate a command processor called the Multi-Protocol Synchronous Serial Engine (MPSSE)。

The MPSSE Command Processor unit is controlled using a SETUP command。Various commands are used to clock data out of and into the chip,as well as controlling the other I/O lines。

USB SETUP command参考文档"API Definitions for FTDI FT232 and FT245 USB Interface Chips"。

USB SETUP command的状态阶段的状态包是个ZLP。

3.2 Port A包括2组pin
ADBUS - Port A Data Bus
ACBUS - Port A Control Bus

3.3 Port B包括2组pin
BDBUS - Port B Data Bus
BCBUS - Port B Control Bus

3.4 使能MPSSE控制传输
FTDI_SIO_SET_BITMODE
bmRequestType:0x40
bRequest:0x0B
wValue:0x02 << 8 | 0x0
wIndex:bInterfaceNumber + 1
wLength:0

3.5 Data Shifting Command
Figure 3-1 Data Shifting Command

1)+VE、-VE:Valid Edge,分别表示上升沿和下降沿有效。
2)图中说明:MPSSE串行命令的bit7为0,MPSSE其它命令的bit7为1。

4 FTDI编程
4.1 FTDI FT_Prog
该工具主要用来读写EEPROM,修改完毕,选择[DEVICES][Program]写入EEPROM即可。

4.2 Python ftd2xx for Windows
1)安装
Programming FTDI devices in Python: Part 1
https://iosoft.blog/2018/12/02/ftdi-python-part-1

ftd2xx is a simple python wrapper around the FTDI D2XX DLL.
pip install ftd2xx

2)示例
import sys, ftd2xx as ftd
d = ftd.open(0)
print(d.getDeviceInfo())

4.3 libFTDI for Windows
1)
USB Resources for Microchip Microcontrollers, libusb and libftdi
https://sourceforge.net/projects/picusb/files/
2)拷贝lib64\site_packages下所有文件到python的Lib\site_packages下
3)拷贝bin64\Python3.6\Lib\site_packages下所有文件到python的Lib\site_packages下

5 Eltima VSPD
5.1 Creating Pairs of Virtual Ports
Virtual Serial Port Driver is used to emulate virtual serial pair in Windows, for example, COM1 and COM2, then one application uses COM1, the second application uses COM2, they can communicate with each other.

5.2 Splitting Real Serial Ports
将一个真实串口(物理串口)映射成多个虚拟串口。真实串口接收到的数据转发给每个虚拟串口,虚拟串口接收到的数据都转发给真实串口。常用于多个应用需要同时和一台设备通信的场景。

6 FT4232
4232表示支持4个RS232。
Windows openocd uses legacy ft2232 driver instead of libusb.
The below command is used to check if JTAG mode is enabled.
openocd -f attach_fhe4232.cfg

7 Abbreviations
.cat文件:category表示Windows的驱动签名安全目录
CH341:winchiphead
CP2102: Cygnal Integrated Products. Cygnal Integrated Products was acquired by Silicon Laboratories Inc. in 2003.
D2XX:D表示FTD,2表示USB2.0
FTDI:Future Technology Devices International
MISO:mi s əu
MOSI:m əu si
QUP:高通平台的SPI总线和I2C共用core和引脚,称为QUP(QCOM Universal Peripheral);而UART和QUP又共用引脚,并且称为BLSP

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐