tinyfpga / TinyFPGA-BX

Other
268 stars 96 forks source link

Solution for serial port difficulties with Linux #4

Closed DavidAntliff closed 5 years ago

DavidAntliff commented 5 years ago

Posting this in case someone else has the same experience.

When I connect the board (with supplied firmware) to Ubuntu 16.04 via USB I see this in my Linux kernel log:

[2157524.597052] usb 1-1: new full-speed USB device number 40 using xhci_hcd
[2157524.737724] usb 1-1: New USB device found, idVendor=1209, idProduct=2100
[2157524.737730] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[2157524.738464] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
[2157536.029885] cdc_acm 1-1:1.1: urb 2 failed submission with -19
[2157536.029905] usb 1-1: USB disconnect, device number 40
[2157536.029919] cdc_acm 1-1:1.1: urb 3 failed submission with -19
[2157536.029956] cdc_acm 1-1:1.1: urb 4 failed submission with -19
[2157536.029996] cdc_acm 1-1:1.1: urb 5 failed submission with -19
[2157536.030036] cdc_acm 1-1:1.1: urb 6 failed submission with -19
[2157536.030077] cdc_acm 1-1:1.1: urb 7 failed submission with -19
[2157536.030118] cdc_acm 1-1:1.1: urb 8 failed submission with -19
[2157536.030140] cdc_acm 1-1:1.0: failed to set dtr/rts
[2157536.030160] cdc_acm 1-1:1.1: urb 9 failed submission with -19
[2157536.030199] cdc_acm 1-1:1.1: urb 10 failed submission with -19
[2157536.436674] usb 1-1: new full-speed USB device number 41 using xhci_hcd
[2157536.577210] usb 1-1: New USB device found, idVendor=1209, idProduct=2100
[2157536.577216] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[2157536.577957] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

This sort of thing appears every few seconds in the dmesg log.

Running tinyprog -m results in one of three different results:

$ tinyprog -m
[
  {
    "boardmeta": {
      "name": "TinyFPGA BX",
      "fpga": "ice40lp8k-cm81",
      "hver": "1.0.0",
      "uuid": "03cfce7b-b1d9-467a-a05e-1a08839f1786"
    },
    "bootmeta": {
      "bootloader": "TinyFPGA USB Bootloader",
      "bver": "1.0.1",
      "update": "https://tinyfpga.com/update/tinyfpga-bx",
      "addrmap": {
        "bootloader": "0x000a0-0x28000",
        "userimage": "0x28000-0x50000",
        "userdata": "0x50000-0x100000"
      }
    },
    "port": "/dev/ttyACM0"
  }
]

Or:

$ tinyprog -m
Traceback (most recent call last):
  File "/home/dantliff/.pyenv/versions/3.6.5/envs/tinyfpga-3.6.5/lib/python3.6/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Device or resource busy: '/dev/ttyACM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dantliff/.pyenv/versions/tinyfpga-3.6.5/bin/tinyprog", line 11, in <module>
    sys.exit(main())
  File "/home/dantliff/.pyenv/versions/3.6.5/envs/tinyfpga-3.6.5/lib/python3.6/site-packages/tinyprog/__main__.py", line 226, in main
    with serial.Serial(port, timeout=1.0, writeTimeout=1.0) as ser:
  File "/home/dantliff/.pyenv/versions/3.6.5/envs/tinyfpga-3.6.5/lib/python3.6/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/home/dantliff/.pyenv/versions/3.6.5/envs/tinyfpga-3.6.5/lib/python3.6/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'

Or:

$ tinyprog -m
[]

After creating the following file:

$ cat /etc/udev/rules.d/90-tinyfpga-bx.rules
ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", 
ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", 
ENV{MTP_NO_PROBE}="1"

Then sudo udevadm control --reload, dmesg settles down with just:

[2157750.872236] usb 1-1: USB disconnect, device number 56
[2157751.277717] usb 1-1: new full-speed USB device number 57 using xhci_hcd
[2157751.418324] usb 1-1: New USB device found, idVendor=1209, idProduct=2100
[2157751.418330] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[2157751.419205] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

Now tinyprog -m produces consistent and reproducible output:

$ tinyprog -m
[
  {
    "boardmeta": {
      "name": "TinyFPGA BX",
      "fpga": "ice40lp8k-cm81",
      "hver": "1.0.0",
      "uuid": "03cfce7b-b1d9-467a-a05e-1a08839f1786"
    },
    "bootmeta": {
      "bootloader": "TinyFPGA USB Bootloader",
      "bver": "1.0.1",
      "update": "https://tinyfpga.com/update/tinyfpga-bx",
      "addrmap": {
        "bootloader": "0x000a0-0x28000",
        "userimage": "0x28000-0x50000",
        "userdata": "0x50000-0x100000"
      }
    },
    "port": "/dev/ttyACM0"
  }
]
DavidAntliff commented 5 years ago

Turns out that the User Guide has a step that does all this for you: apio drivers --serial-enable, creates:

$ cat /etc/udev/rules.d/80-fpga-serial.rules 
# Disable ModemManager for BlackIce
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1"
# Disable ModemManager for TinyFPGA B2
ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", ENV{ID_MM_DEVICE_IGNORE}="1"
# Disable ModemManager for TinyFPGA BX
ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="6130", ENV{ID_MM_DEVICE_IGNORE}="1"

Which seems to stabilise the driver as well.

DavidAntliff commented 5 years ago

I'm going to close this as it's not really an "issue" that needs to be fixed.

MCDELTAT commented 5 years ago

Confirmed as a fix for me on Lint Mint 19.1 (Ubuntu 18.04) as well.

paulo-raca commented 5 years ago

I faced the same issue on Ubuntu 19.04 -- It crashes and re-enumerates every few seconds:

[ 1563.376825] usb 1-9: USB disconnect, device number 92
[ 1563.377078] cdc_acm 1-9:1.0: failed to set dtr/rts
[ 1563.797511] usb 1-9: new full-speed USB device number 93 using xhci_hcd
[ 1563.954415] usb 1-9: New USB device found, idVendor=1209, idProduct=2100, bcdDevice= 0.00
[ 1563.954423] usb 1-9: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 1563.956735] cdc_acm 1-9:1.0: ttyACM1: USB ACM device

I've tried apio drivers --serial-enable and manually setting ENV{ID_MM_DEVICE_IGNORE}="1"/ENV{MTP_NO_PROBE}="1" without luck.

Assuming something else is trying to use the port (Since tinyprog says "Device Busy"), I tried changing it's permissions so that system services couldn't access it:

ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", OWNER="paulo", GROUP="paulo"

Surprisingly, this worked for me, but I guess there must be a better solution ;)

pamdemonia commented 4 years ago

I know this is closed, but thank you for this! It was the only thing that worked for me!

I'm on Ubuntu 19.04 for any searchers to come.

ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2100", OWNER="paulo", GROUP="paulo" OWNER="paulo", GROUP="paulo"



Surprisingly, this worked for me, but I guess there must be a better solution ;)
paulo-raca commented 4 years ago

I'm glad it was helpful :)

DaveMcEwan commented 4 years ago

I had this same problem on Ubuntu18.04. It looked like ModemManager wouldn't stop trying to use the device, despite the udev rules. Just removing it completely with sudo apt-get purge modemmanager solved the problem and allowed consistent use of tinyprog.

SamWibatt commented 4 years ago

sudo apt purge modemmanager worked for me, too (Ubuntu 18.04). Thank you very much, DaveMcEwan!

kvrineet26 commented 4 years ago

removing modemmanager worked for me. I am also unit Ubuntu 18.04. Thanks Dave.

HHelmius commented 4 years ago

Thank you so much DaveMcEwan! This solved a similar issue with an Arduino Nano I was trying to get working.