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.
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.
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!
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!