teensy_loader_cli issues with Teensy 4.0

aae

Member
New to the forum, new to Teensy, so I might be missing something small and dumb. I would like to use the CLI to load a new hex file on the Teensy 4.0 without needing to push the reset button.

Using the teensy_loader_cli I can load new hex files onto my Teensy 4.0, but it REQUIRES a push of the reset button. I've traced this down to the usb device not opening correctly, and it seems like product id that is hardcoded (0x0478 see below) does not work for the 4.0, which has product id 0x0486 I believe. So, the loader waits, hinting to press the button, which then does succeed.

Code:
int teensy_open(void)
{
    teensy_close();
    libusb_teensy_handle = open_usb_device(0x16C0, 0x0478);
    if (libusb_teensy_handle)
        return 1;
    return 0;
}

So, if I change the above to use 0x0486 instead, it appears to open the device fine without a button push, and then it goes on to try to write to the teensy. However, it fails to actually write, and usb_control_msg (see below) returns -32. At this point, I have no idea what this error means.

Code:
int teensy_write(void *buf, int len, double timeout)
{
	int r;

	if (!libusb_teensy_handle) return 0;
	while (timeout > 0) {
		r = usb_control_msg(libusb_teensy_handle, 0x21, 9, 0x0200, 0,
			(char *)buf, len, (int)(timeout * 1000.0));
		if (r >= 0) return 1;
		//printf("teensy_write, r=%d\n", r);
		usleep(10000);
		timeout -= 0.01;  // TODO: subtract actual elapsed time
	}
	return 0;
}


So, I'm looking for insight into what might be going on here to prevent the teensy from accepting the writes, that for some reason does not happen when the button is pushed. Thoughts on what that error code means would be good as well.
Thanks!
 
On linux (perhaps mac?) this is easy to do.
First know the com port, e.g. /dev/ttyACM0
Then send the following to boot to the bootloader
stty -F /dev/ttyACM0 134
 
134 baud *is* a standard rate.
The standard low-end baud rates are:
75
110
134.5
150
300
600

One of the modifications that we did many years ago on the Decwriter IV TTY was to add a switch to allow 134.5.
(yes, I am that old)
The time base came from either 1.843200MHz or 3.686400Mhz crystal.
Another hack we used to do it actually replace the crystal to get a higher baud rate.
 
Well, how about that?! I had no idea, and I'm embarrassed that I never even tried it. Thanks for enlightening me.
 
Back
Top