ftdi
1. 相关的开源库
1.1 libmpsse
它的调用底层也是libftdi
Open source library for SPI/I2C control via FTDI chips, https://github.com/devttys0/libmpsse
可以直接生成python接口,方便python调用,目前在windows环境试用过,目前只支持SPI/I2C接口的操作,可以自己根据MPSSE命令扩展以支持JTAG操作和MCU emulator接口操作。
依目前来看,自己在这个的基础上修改C代码看起来是一种比较靠谱的方式。
这个项目是采用的swig与python之间进行交互接口,数据的传递是通过char *, 但是char *处理char值>0x80的有很不方便的地方会插入0xffffffc2,造成数据处理困扰。最好应该能有支持unsigned char *的。--- 目前还没有找到方法,不确定是不是swig版本的问题。 --- 这个需要使用c与python bytes相互转换的功能。 具体请参考 使用swig连接python与c
1.2 pyftdi
pip install pyftdi
, https://pypi.org/project/pyftdi/, https://eblot.github.io/pyftdi/
纯python实现,没有调用libftdi, 估计是直接调用的libusb。目前包装好对外的函数没有支持pause_ir/dr,需要自己稍稍修改一下。
-- 重要:目前这个开源代码还有问题:
- 其中write_dr会在TCK是出一个10ns左右的毛刺应该是个BUG,无法确认是FTDI芯片问题还是开源代码的问题。 -- 需要再确认下是否是接地不良造成的。
- write_dr, read_dr, shift_register,都没有实现在Exit1-DR时把最后一个bit的数据发送或接收功能,JTAG功能无法真正使用。
安装方式:管理员方式运行python3 setup.py install
,期间需要联网自动更新一些依赖包。
Overview
PyFtdi aims at providing a user-space driver for popular FTDI devices, implemented in pure Python language.
Suported FTDI devices include:
- UART and GPIO bridges
- FT232R (single port, 3Mbps)
- FT230X/FT231X/FT234X (single port, 3Mbps)
- UART and multi-serial protocols (SPI, I2C, JTAG) bridges
- FT2232C/D (dual port, clock up to 6 MHz)
- FT232H (single port, clock up to 30 MHz)
- FT2232H (dual port, clock up to 30 MHz)
- FT4232H (quad port, clock up to 30 MHz)
Features
PyFtdi currently supports the following features:
- UART/Serial USB converter, up to 12Mbps (depending on the FTDI device capability)
- GPIO/Bitbang support, with 8-bit asynchronous, 8-bit synchronous and 8-/16-bit MPSSE variants
- SPI master, with simultanous GPIO support, up to 12 pins per port, with support for non-byte sized transfer
- I2C master, with simultanous GPIO support, up to 14 pins per port
- Basic JTAG master capabilities
- EEPROM support (some parameters cannot yet be modified, only retrieved)
- Experimental CBUS support on selected devices, 4 pins per port
Supported host OSes
- macOS
- Linux
- FreeBSD
Windows, although not officially supported
1.3 pylibftdi
pylibftdi is a minimal Pythonic interface to FTDI devices using libftdi.
pip install pylibftdi
, https://pypi.org/project/pylibftdi, https://github.com/codedstructure/pylibftdi
支持串口, BitBang模式。
1.4 libFTDI
这个是开源的c库(https://www.intra2net.com/en/developer/libftdi/index.php),官方的D2XX是闭源的C库
FTD2XX is a proprietary USB driver library developed by Future Technologies Devices International (FTDI), available from http://www.ftdichip.com. LibFTDI is an alternative open source USB driver library available from http://www.intra2net.com/en/developer/libftdi/.
FTD2XX is a closed-source library. A program licensed under the GNU General Public License (such as OpenOCD) cannot be distributed in binary form if linked to FTD2XX during compilation. LibFTDI is licensed under the GNU Lesser General Public License v2.1. Information on LGPL v2.1 is available at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2. windows系统下的使用
window python ftdi
原文链接: https://blog.csdn.net/witner_dm/article/details/82732476
此方案自己没有试通,python调用时出现了大概DLL找不到的问题,
还是用自己编写DLL的方式给python用靠谱点。