Monday, 24 June 2019

Selective disconnection of FTDI_SIO serial driver from USB adapters

I mentioned recently that I have been struggling with getting the Arrow FTDI-based JTAG programmer working with Quartus for programming the MAX10 on the MEGA65 R2 main board.  The problem is that I could get Linux to either disconnect EVERY ftdi device, or none.  This sent me down a bit of a rabbit hole that warrants a few comments:

1. The 51-arrow-programmer.rules file was completely wrong and worked only through sheer luck.  The file contained Windows line termination characters, which caused all lines except the last to be ignored. That last line happened to be the one to instruct the FTDI_SIO driver to disconnect.  As a result it would ALWAYS disconnect EVERY FTDI-based serial adaptor -- including the ones I needed connected.

2. I read through lots of udev documentation and related material, and while it SHOULD make it easy to do this kind of selective work, it doesn't because by the time the FTDI_SIO driver thinks about whether to be connected, all the useful identifying information (like vendor name and serial number) have been stripped out.

3. In the end, I used the RUN directive in a udev rule to run always, just like in the broken rule file provided, but to have it run a little script I wrote that checks for the last inserted FTDI adapter that has "Arrow" as the vendor, and then work out the serial port kernel ID, and disconnect that.

Here is my rules file:

# Arrow-USB-Programmer needs to be disconnected from ftdi_sio driver
RUN="/bin/sh -c '/etc/udev/ready_arrow'"


And here is the contents of /etc/udev/ready_arrow:

#!/bin/bash
dmesg | grep `dmesg | grep "Product: Arrow USB Blaster" | tail -1 |  cut -f3 -d' ' ` | grep ftdi_sio | cut -f3 -d' '  | cut -f1-2 -d: | tail -1 | sudo tee  /sys/bus/usb/drivers/ftdi_sio/unbind


And it works like a dream.  So now I can insert the USB adapters in any USB port, in any order, and have them all in the correct state.



So now I can finally get back to what I was trying to do, which is to try my new MAX10 firmware, to see if I can get the serial monitor interface working on the MEGA65 R2 main boards...

2 comments:

  1. but it does not solve the generic issue of not enabling uart on the same adapter

    ReplyDelete
    Replies
    1. Quite true. However, it did at least get me working again.

      Delete