zsa / docs

Misc ErgoDox EZ Files
http://www.ergodox-ez.com
162 stars 23 forks source link

"Device found but unable to open" error with teensy-loader-cli on Linux #14

Closed rzetterberg closed 6 years ago

rzetterberg commented 6 years ago

Problem description

When using teensy-loader-cli to flash a layout I get the following error when I press the reset button on my Ergodox EZ:

$ teensy-loader-cli --mcu=atmega32u4 -w -v ergodox_ez_firmware_zeds_layout_mggjzw.hex -v
Teensy Loader, Command Line, Version 2.1
Read "ergodox_ez_firmware_zeds_layout_mggjzw.hex": 25854 bytes, 80.2% usage
Waiting for Teensy device...
 (hint: press the reset button)
Found device but unable to open
Found device but unable to open

Steps to reproduce

Here are the exact steps I take:

  1. Plug in the Ergodox EZ USB-cable into my computer
  2. Verify that the Ergodox EZ is initialized and appears as a new USB device (using dmesg)
  3. Run teensy-loader-cli --mcu=atmega32u4 -v -w ergodox_ez_firmware_zeds_layout_mggjzw.hex
  4. Verify that teensy-loader-cli is running and that it has output Waiting for Teensy device...
  5. Press reset pint on Ergodox EZ with a paperclip

Troubleshooting

What I have tried the following without success:

Solution

After reading the following PJRC forum post I tried adding the mentioned UDEV rules, and that solved the problem for me:

$ teensy-loader-cli --mcu=atmega32u4 -v -w ergodox_ez_firmware_zeds_layout_mggjzw.hex
Teensy Loader, Command Line, Version 2.1
Read "ergodox_ez_firmware_zeds_layout_mggjzw.hex": 25854 bytes, 80.2% usage
Waiting for Teensy device...
 (hint: press the reset button)
Found HalfKay Bootloader
Read "ergodox_ez_firmware_zeds_layout_mggjzw.hex": 25854 bytes, 80.2% usage
Programming..........................................................................................................................................................................................................
Booting

I'm closing this ticket directly since the problem is solved. The only reason I created it was so that anyone else faced with the same problem will easily find this ticket while searching for "Ergodox EZ found device unable to open" or similar search terms.

For maximum convenience, here's a script that will install the UDEV rules for you (unless you are using NixOS):

install-teensy-udev-rules.sh

#!/usr/bin/env bash

#
# Script that installs PJRC UDEV rules for allowing to use Teensy-based devices.
# Downloads the rules file, checks that it matches the SHA256 checksum in this
# script and then moves the downloaded UDEV file
# to "/lib/udev/rules.d/49-teensy.rules".
#
# Note: you need to be able to run sudo to use this script.
#
# Run without providing any arguments:
#
# ./install-teensy-udev-rules.sh
#

set -e

UDEV_RULES_NAME="49-teensy.rules"
UDEV_RULES_URL="https://www.pjrc.com/teensy/$UDEV_RULES_NAME"
UDEV_RULES_SHA256="031de0b26991b5a3b19c497d9c0a17f86c40c55d925b9d07d19ab89f2286469d  $UDEV_RULES_NAME"
UDEV_RULES_DEST="/lib/udev/rules.d/49-teensy.rules"

WORK_DIR=$(mktemp -d)

function finish {
  echo ">> Cleaning up work dir"
  popd
  rm -rf "$WORK_DIR"
  echo "-- Clean up done"
}
trap finish EXIT

pushd "$WORK_DIR"

echo ">> Downloading UDEV rules file"

curl "$UDEV_RULES_URL" --output "$UDEV_RULES_NAME"
echo "031de0b26991b5a3b19c497d9c0a17f86c40c55d925b9d07d19ab89f2286469d  $UDEV_RULES_NAME" > "$UDEV_RULES_NAME.sha256"

sha256sum -c "$UDEV_RULES_NAME.sha256"

if [ -f "$UDEV_RULES_DEST" ]; then
    echo "UDEV rule '$UDEV_RULES_DEST' is already installed, quitting."
    exit
fi

echo ">> Installing UDEV rules file"

sudo install -o root -g root -m 0664 "$UDEV_RULES_NAME" "$UDEV_RULES_DEST"
sudo udevadm control --reload-rules
sudo udevadm trigger

echo "-- Installation complete"

If you are using NixOS you simply add this to your /etc/nixos/configuration.nix file and run nixos-rebuild switch:

    services.udev.extraRules = ''
      # UDEV rules for Teensy USB devices
      ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", ENV{ID_MM_DEVICE_IGNORE}="1"
      ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789A]?", ENV{MTP_NO_PROBE}="1"
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789ABCD]?", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", MODE:="0666"
    '';
rzetterberg commented 6 years ago

Closing since the problem is solved. See "Solution" above. :point_up:

pitosalas commented 2 years ago

Thanks for the script. I am getting:

sha256sum: WARNING: 1 computed checksum did NOT match

And then, when I try to load the firmware using platformIO I still get the error as before:

Read ".pio/build/teensy36/firmware.hex": 77812 bytes, 7.4% usage
Found device but unable to open
Error opening USB device: Resource temporarily unavailable
Waiting for Teensy device...
 (hint: press the reset button)
Found device but unable to open
rzetterberg commented 2 years ago

Thanks for the script. I am getting:

The the file that the script downloads have changed since I wrote the script, which makes the script exit and do nothing. Since nothing have changed from running the script, you still get the same error.

Have a look at the file it downloads and see what have changed. Then you can download the appropriate file and just run this part of the script to install it:

sudo install -o root -g root -m 0664 "[name-of-downloaded-file]" "/lib/udev/rules.d/[name-of-downloaded-file]"
sudo udevadm control --reload-rules
sudo udevadm trigger
pitosalas commented 2 years ago

Thank you! I did part of that. Just copied the file to /lib/udev/rules.d but I just used a mv command and didn’t do the reload-rules or trigger. It seemed to work but I will do those steps too! Thank you!

Pito Salas Faculty, Computer Science Brandeis University

On Feb 3, 2022, at 5:47 AM, Richard Zetterberg @.***> wrote:

Thanks for the script. I am getting:

The the file that the script downloads have changed since I wrote the script, which makes the script exit and do nothing. Since nothing have changed from running the script, you still get the same error.

Have a look at the file it downloads and see what have changed. Then you can download the appropriate file and just run this part of the script to install it:

sudo install -o root -g root -m 0664 "[name-of-downloaded-file]" "/lib/udev/rules.d/[name-of-downloaded-file]"

sudo udevadm control --reload-rules sudo udevadm trigger

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

marthinwurer commented 2 years ago

I found the instructions on the teensyduino installation page for installing the udev rules to be useful:

https://www.pjrc.com/teensy/td_download.html

Once that's installed, remember to press the reset button!