Unable to upload code in Teensy 4.1. "Teensy did not respond to a USB based request" error

I am new to programming and started to work with Teensy 4.1 for my university project. I am working on Ubuntu 22.04 virtual machine and followed all the installation procedures in the pjrc website. But when I try to upload the code, I get this error,

Code:
Opening Teensy Loader...
Memory Usage on Teensy 4.1:
  FLASH: code:9100, data:4044, headers:8356   free for files:8104964
   RAM1: variables:4832, code:6464, padding:26304   free for local variables:486688
   RAM2: variables:12416  free for malloc/new:511872
Teensy did not respond to a USB-based request to enter program mode.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
Failed uploading: uploading error: exit status 1


System details:

Operating system: Ubuntu 22.04 (Virtual Machine)
Arduino IDE version: Arduino IDE 2.2.1
Teensyduino version: Teensy 1.58.1

Observations:

I tried using the same Arduino IDE and Teensyduino version in my host Windows 11 and I can upload the sketch without any issues. So I can deduce from this that there is no issue with Teensy hardware or the USB cable.

I have installed the 00-teensy.rules in etc/udev/rules.d/ but still the issue is not resolved.

I have attached the screenshot of my IDE window before and after uploading the code. I noticed that the Teensy is getting disconnected during the reboot but that doesnt happen iwhen I upload the code from IDE in host windows 11. You can see that in the attached screenshots (Before and after Uploading the program). Could this be a possible issue?

Before uploading:

Before uploading.png


After Uploading: (See bottom right corner that Teensy is disconnected)


After uploading.png


I have followed your instruction on https://forum.pjrc.com/index.php?th...1-not-responding-to-usb-based-requests.72471/
I am attaching my system log information below,

Code:
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.419Z daemon INFO time="2023-12-30T22:29:20+01:00" level=info msg="from discovery builtin:serial-discovery received message type: add, port: /dev/ttyACM0"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.421Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[],"port":{"address":"/dev/ttyACM0","label":"/dev/ttyACM0","protocol":"serial","protocolLabel":"Serial Port (USB)","propertiesMap":[["pid","0x0483"],["serialNumber","14905000"],["vid","0x16c0"]],"hardwareId":"14905000"}},"error":""}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.421Z daemon INFO time="2023-12-30T22:29:20+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: add, port: usb1/1-2"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.423Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[{"name":"Teensy 4.1","fqbn":"teensy:avr:teensy41","isHidden":false}],"port":{"address":"usb1/1-2","label":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","propertiesMap":[["modelID","0x25"],["name","Teensy 4.1"]],"hardwareId":""}},"error":""}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.424Z daemon INFO time="2023-12-30T22:29:20+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: add, port: usb1/1-2"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.428Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[{"name":"Teensy 4.1","fqbn":"teensy:avr:teensy41","isHidden":false}],"port":{"address":"usb1/1-2","label":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","propertiesMap":[["modelID","0x25"],["name","Teensy 4.1"]],"hardwareId":""}},"error":""}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.431Z daemon INFO time="2023-12-30T22:29:20+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: add, port: usb1/1-2"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:20+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: add, port: usb1/1-2"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.433Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[{"name":"Teensy 4.1","fqbn":"teensy:avr:teensy41","isHidden":false}],"port":{"address":"usb1/1-2","label":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","propertiesMap":[["modelID","0x25"],["name","Teensy 4.1"]],"hardwareId":""}},"error":""}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.433Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[{"name":"Teensy 4.1","fqbn":"teensy:avr:teensy41","isHidden":false}],"port":{"address":"usb1/1-2","label":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","propertiesMap":[["modelID","0x25"],["name","Teensy 4.1"]],"hardwareId":""}},"error":""}
Dec 30 22:29:20 srini-VirtualBox snapd[644]: hotplug.go:200: hotplug device add event ignored, enable experimental.hotplug
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.523Z daemon INFO time="2023-12-30T22:29:20+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: add, port: usb1/1-2"
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.524Z discovery-log INFO {"eventType":"add","port":{"matchingBoardsList":[{"name":"Teensy 4.1","fqbn":"teensy:avr:teensy41","isHidden":false}],"port":{"address":"usb1/1-2","label":"/dev/ttyACM0 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","propertiesMap":[["modelID","0x25"],["name","Teensy 4.1"]],"hardwareId":""}},"error":""}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.628Z root WARN Detected a new port that has been already discovered. The old value will be overridden. Old value: {"port":{"address":"usb1/1-2","addressLabel":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}},"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}]}, new value: {"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}],"port":{"address":"usb1/1-2","addressLabel":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}}}
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: message repeated 2 times: [ 2023-12-30T21:29:20.628Z root WARN Detected a new port that has been already discovered. The old value will be overridden. Old value: {"port":{"address":"usb1/1-2","addressLabel":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}},"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}]}, new value: {"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}],"port":{"address":"usb1/1-2","addressLabel":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}}}]
Dec 30 22:29:20 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:20.628Z root WARN Detected a new port that has been already discovered. The old value will be overridden. Old value: {"port":{"address":"usb1/1-2","addressLabel":"/dev/bus/usb/001/007 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}},"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}]}, new value: {"boards":[{"fqbn":"teensy:avr:teensy41","name":"Teensy 4.1"}],"port":{"address":"usb1/1-2","addressLabel":"/dev/ttyACM0 Serial","protocol":"teensy","protocolLabel":"Teensy Ports","properties":{"modelID":"0x25","name":"Teensy 4.1"}}}
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:30.888Z daemon INFO time="2023-12-30T22:29:30+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:30+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:30.888Z daemon INFO time="2023-12-30T22:29:30+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:30+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:30+01:00" level=info msg="Adding libraries dir" dir=/home/srini/.arduino15/libraries location=ide
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:30+01:00" level=info msg="Adding libraries dir" dir=/home/srini/.arduino15/packages/teensy/hardware/avr/1.58.1/libraries location=platform
Dec 30 22:29:30 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:30+01:00" level=info msg="Adding libraries dir" dir=/home/srini/Arduino/libraries location=user
Dec 30 22:29:32 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:32.704Z root INFO Executing 'arduino.languageserver.notifyBuildDidComplete' with "file:///tmp/arduino/sketches/3DFF84284A9102989DC43E3B51072EF0"
Dec 30 22:29:32 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:32.867Z daemon INFO time="2023-12-30T22:29:32+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:32 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:32+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:33.826Z daemon INFO time="2023-12-30T22:29:33+01:00" level=info msg="from discovery builtin:serial-discovery received message type: remove, port: /dev/ttyACM0"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:33.827Z discovery-log INFO {"eventType":"remove","port":{"matchingBoardsList":[],"port":{"address":"/dev/ttyACM0","label":"","protocol":"serial","protocolLabel":"","propertiesMap":[],"hardwareId":""}},"error":""}
Dec 30 22:29:33 srini-VirtualBox kernel: [ 3726.218722] usb 1-2: USB disconnect, device number 7
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:33.834Z daemon INFO time="2023-12-30T22:29:33+01:00" level=info msg="from discovery teensy:teensy-discovery received message type: remove, port: usb1/1-2"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:33.835Z discovery-log INFO {"eventType":"remove","port":{"matchingBoardsList":[],"port":{"address":"usb1/1-2","label":"","protocol":"teensy","protocolLabel":"","propertiesMap":[],"hardwareId":""}},"error":""}
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:33.898Z daemon INFO time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-compile@11.3.1"
Dec 30 22:29:33 srini-VirtualBox arduino.desktop[4396]: time="2023-12-30T22:29:33+01:00" level=info msg="Required tool" tool="teensy:teensy-tools@1.58.0"
Dec 30 22:29:39 srini-VirtualBox arduino.desktop[4396]: 2023-12-30T21:29:39.437Z daemon INFO time="2023-12-30T22:29:39+01:00" level=error msg="Upload port detection failed, watcher closed" task=port_detection

Please help.
 
Virtual machines are often problematic. USB isn't "pass through" as VM vendors might like you to believe. Quite a bit of software sits between the real USB and VM's emulated USB host controller.

Blind guess... maybe your VM is configured to automatically connect USB serial devices but not USB HID protocol which is used during programming.

During upload, Teensy always disconnects and then reconnects as USB HID with VID 16C0 / PID 0478. This is done with Windows, Linux and MacOS. Usually it happens so quickly you don't notice. But it's pretty important, since Teensy could be all sorts of USB things (from the Tools > USB Type menu) while running. The disconnect and reconnect are needed so your PC (or VM) sees it as USB HID which Teensy Loader uses.

For the sake of testing, keep the small Teensy Loader window visible on your screen. Turn off "Auto" mode. Make sure it is running inside your VM, and not running on the PC host. Then press the button on your Teensy. Teensy Loader should go from showing the "Press Button..." message to showing a bright image of your Teensy. Since it's not in Auto mode, it won't immediately program and reboot your Teensy, allowing you time to see it detected.

What you need to do to make your VM work, I don't know. The best I can do is describe how things you and what you should look at while testing. If you do figure out the exact setting needed to make it work with your VM, I hope you'll share that insight and specific info about which VM and other software. Maybe it will help others who have this same problem (VM issues have come up many times and rarely do we hear about the way they're actually solved).
 
Virtual machines are often problematic. USB isn't "pass through" as VM vendors might like you to believe. Quite a bit of software sits between the real USB and VM's emulated USB host controller.

Blind guess... maybe your VM is configured to automatically connect USB serial devices but not USB HID protocol which is used during programming.

During upload, Teensy always disconnects and then reconnects as USB HID with VID 16C0 / PID 0478. This is done with Windows, Linux and MacOS. Usually it happens so quickly you don't notice. But it's pretty important, since Teensy could be all sorts of USB things (from the Tools > USB Type menu) while running. The disconnect and reconnect are needed so your PC (or VM) sees it as USB HID which Teensy Loader uses.

For the sake of testing, keep the small Teensy Loader window visible on your screen. Turn off "Auto" mode. Make sure it is running inside your VM, and not running on the PC host. Then press the button on your Teensy. Teensy Loader should go from showing the "Press Button..." message to showing a bright image of your Teensy. Since it's not in Auto mode, it won't immediately program and reboot your Teensy, allowing you time to see it detected.

What you need to do to make your VM work, I don't know. The best I can do is describe how things you and what you should look at while testing. If you do figure out the exact setting needed to make it work with your VM, I hope you'll share that insight and specific info about which VM and other software. Maybe it will help others who have this same problem (VM issues have come up many times and rarely do we hear about the way they're actually solved).
Thanks for your quick reply.

I tried testing what you told. Teensy disconnects as soon as i press the button. And both the Teensy and Teensy loader stays the same way.

So in short my Teensy is connected to my VM only when it is running an already loaded program and disconnects as soon as I enter program mode.

Could there be some other issue that causes it? I searched through multiple forums but could not find any solution. Can downgrading to Arduino IDE version 1.8 resolve the issue?
 
On Linux inside the VM, in a terminal run "sudo tail -f /var/log/syslog".

You're looking for the kernel's message about when it detects USB device connect and disconnect.

You could also try running Teensy Loader on the host OS and run the VM as a window rather than full screen, so you're able to see both Teensy Loader windows at the same time. As before, turn off Auto mode (for both of them). When you press the button, if the native host instance detects Teensy and the VM sees nothing, that's a very sure sign you need to work on your VM's configuration to take control of that USB device. Your VM probably provides some way to configure which USB devices it grabs versus which it doesn't touch so the native host can still use them. Maybe Google searches or reading the VM's documentation might turn it up?
 
Maybe <this> old thread may provide some helpful clues . . .

Mark J Culross
KD5RXT
Thanks for your reply. I wish I saw your post early. This worked for me.

As Paul said, the Teensy toggles between Serial and HID modes and after claiming control manually it worked. I straightaway added both the USB mode to my VM USB filter to reconnect automatically. Posting the image here so that someone encountering this can figure it out.

ss.png
 
On Linux inside the VM, in a terminal run "sudo tail -f /var/log/syslog".

You're looking for the kernel's message about when it detects USB device connect and disconnect.

You could also try running Teensy Loader on the host OS and run the VM as a window rather than full screen, so you're able to see both Teensy Loader windows at the same time. As before, turn off Auto mode (for both of them). When you press the button, if the native host instance detects Teensy and the VM sees nothing, that's a very sure sign you need to work on your VM's configuration to take control of that USB device. Your VM probably provides some way to configure which USB devices it grabs versus which it doesn't touch so the native host can still use them. Maybe Google searches or reading the VM's documentation might turn it up?
Mark's solution worked for me. And you are right my VM didnt grab the USB Halfkay Bootloader. It worked after I took control of that.

Thanks for your support.
 
Thanks for your reply. I wish I saw your post early. This worked for me.

As Paul said, the Teensy toggles between Serial and HID modes and after claiming control manually it worked. I straightaway added both the USB mode to my VM USB filter to reconnect automatically. Posting the image here so that someone encountering this can figure it out.

Good to know that the info from the quoted thread still applies & works !! That, combined with your description for capturing the USB connection modes will likely prove useful to others in the future. Thanks for your follow-up report !!

Mark J Culross
KD5RXT
 
Back
Top