【问题标题】:FTDI kernel driver after using libftdi使用 libftdi 后的 FTDI 内核驱动程序
【发布时间】:2017-08-01 12:46:42
【问题描述】:

我正在使用带有 FTDI 芯片 (FT4232) 的定制板在 Linux 系统 (Fedora 24) 上通过 USB 进行四个串行通信。插上板子后,它工作得很好,通讯端口出现了,我可以通讯了。

但是,我还需要读取EEPROM中的一些数据,并且一旦我使用libftdi1进行通信或其他任何东西,我连接的通信端口就会消失。这是lsusb -t的输出:

|__ Port 2: Dev 46, If 2, Class=Vendor Specific Class, Driver=ftdi_sio, 480M
|__ Port 2: Dev 46, If 0, Class=Vendor Specific Class, Driver=, 480M
|__ Port 2: Dev 46, If 3, Class=Vendor Specific Class, Driver=ftdi_sio, 480M
|__ Port 2: Dev 46, If 1, Class=Vendor Specific Class, Driver=ftdi_sio, 480M

所以我们看到驱动程序已被分离。我尝试按照this question 中的建议重新附加内核驱动程序,但没有任何成功。以下是重现行为的最小代码示例:

#include <stdio.h>
#include <libftdi1/ftdi.h>
#include <libusb-1.0/libusb.h>

int main(int argc, char * argv[])
{
    struct ftdi_context ftdic;
    libusb_device_handle * dev;

    ftdi_init(&ftdic);

    ftdi_usb_open(&ftdic, 0x0403, 0x6011);

    dev = ftdic.usb_dev;

    // Return error -6: LIBUSB_ERROR_BUSY
    printf("%d\n", libusb_attach_kernel_driver(dev, 0));

    ftdi_usb_close(&ftdic);

    // Return error -99: LIBUSB_ERROR_OTHER
    printf("%d\n", libusb_attach_kernel_driver(dev, 0));

    return 0;
}

简而言之:使用 libftdi1 后如何重新附加内核驱动程序?我更喜欢c 解决方案,但 bash 解决方案也不错。

【问题讨论】:

    标签: c linux libusb ftdi


    【解决方案1】:

    使用 libftdi 后,可以使用 libusb 和 libusb_attach_kernel_driver 函数重新连接原始驱动程序。

    
    #define DEVICE_VID 0x0403
    #define DEVICE_PID 0x6015
    
    int libftdireset() {
      libusb_context * context = NULL;
      libusb_device_handle * dev_handle = NULL;
      int rc = 0;
      rc = libusb_init( &context);
    
      dev_handle = libusb_open_device_with_vid_pid(context, DEVICE_VID, DEVICE_PID);
      /*Check if kenel driver attached*/
      if (libusb_kernel_driver_active(dev_handle, 0)) {
        rc = libusb_detach_kernel_driver(dev_handle, 0); // detach driver
      }
      libusb_reset_device(dev_handle);
      libusb_attach_kernel_driver(dev_handle, 0);
      libusb_close(dev_handle);
      libusb_exit(context);
      return 0;
    }
    

    【讨论】:

    • 自从我 3 年前提出这个问题以来,我无法使用硬件进行测试,但看起来它可以工作......谢谢
    猜你喜欢
    • 2011-04-24
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 2012-06-07
    • 2015-10-12
    相关资源
    最近更新 更多