Remote reboot / user code update

Status
Not open for further replies.
Changing that to
Code:
    char reboot_command = 134;
    int response = usb_control_msg(serial_handle, 0x21, 0x20, 0, 0, &reboot_command, 1, 10000);
Seems to work! I'll clean up my code and submit a pull request.

Any idea how to implement this on windows. I have built a firmware loading routing based on teensy_loader_cli and for the life of me I can't figure out how to get the teensy to reboot. Do I need to use libusb?

Regards,
Rob
 
No you don't have to, whether you consider Linux or Windows. Actually you should not use libusb for this because to use it you need to detach the kernel driver (cdc_atm on Linux in serial mode) and do weird stuff on Windows. This is not what libusb is good for.

There are currently two ways to trigger the soft reboot of a Teensy device, depending on the USB mode it's running:
- in Serial mode, just switch the baud rate to 134 on the serial device, using SetCommState on Win32 or tcsetattr on POSIX systems
- in HID mode, send an HID feature report containing the magic string {0xA9, 0x45, 0xC2, 0x6B} to the device (with a report number of 0)

Of course you have to open the device before you do that. If it's a serial device, on Windows, just find the corresponding COM port. Other cases are more complicated, libusb can help to enumerate devices but last I checked it does not readily expose the device file path.

Should you be interested, I've made a "cross-platform" (no Mac OS X support) library to deal with Teensy devices. You can use it to list and detect Teensy devices dynamically, reboot/program them and communicate serially (for real or using the HID emulation, transparently). It has no external dependency. It's also incomplete and pretty much undocumented but I don't have much (any) time for it at the moment, unfortunately.

https://github.com/Koromix/ty

You can use it directly or simply read it to find how to do this stuff yourself. The code should be simple enough to read but as I said before, it's not documented.
 
Hi,

Thanks for the help. My devices are configured as rawhid / MIDI and I have an application that communicates with the boards already. I read though some of your code, which is very well formatted and easy to read, however I could track down the code I was looking for.

Based on your reply and a google search, I suspect I need to use the HidD_SetFeature method. I'll start looking there, but if you could point to the method that has the relevent code in your repository, that would help. I did find the ty_board_reboot method, but I wasn't able to track that back to relevant code.

Regards,
Rob
 
I managed to find the relevant code and tried the following:

Code:
static unsigned char seremu_magic[] = { 0, 0xA9, 0x45, 0xC2, 0x6B };

HANDLE h = get_hid(curDevice)->handle;

HidD_SetFeature(h, seremu_magic, sizeof(seremu_magic));

Unfortunately, this did not work :( HidD_SetFeature returns false and the HANDLE is none zero. Any thoughts?
 
Forgot to say in my previous post, the HID magic has to be done on the correct USB interface, the SEREMU one (interface number 1 for both RawHID and MIDI), and not the RawHID or MIDI one (interface 0). That's a crucial and very annoying detail under Windows because finding the device file path for a given interface is rather tricky there.

As far as I know you have to rely on the SetupAPI and/or Configuration Manager dark corners of the Win32 API. Although you can (maybe) try to build the correct path manually depending on what info you already have for your device. It looks something like "\\.\HID#VID_16C0&PID_0485&MI_01#7&38903001&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}".

Meanwhile you can use the tyc.exe in the release section (v0.2.1) on GitHub to list devices with the SEREMU device file path. It's a console program, list devices with "tyc list --verbose". It'll show you what device you have to open, so you can at least get the first part of the problem (rebooting the device) right.
 
Seems like a whole lot of hassle. Sure wish Paul would release the source code for the reboot app. Not sure it's worth the effort. While early releases of my firmware don't have this function, later releases support rebooting by listening for a special command that's sent via raw_hid_send. I think I'm just going to force users with legacy firmware to manually update. Thanks for your help.

Regards,
Rob
 
Here is the source code.

Please understand this is unsupported. I'm not going to answer questions about it, and quite frankly, I'm reluctant to release stuff like this because it pretty much always turns into more tech questions for me and probably not much value for anyone as just the raw source without documentation or a makefile or other stuff to help you use it.
 

Attachments

  • teensy_reboot.c
    35.9 KB · Views: 386
Koromix, I'm getting compiler errors when cross-compiling ty for win32 or win64 on my Fedora21 system. I posted an issue on github.

Do you plan to make ty available for MacOS?
 
Here is the source code.

Please understand this is unsupported. I'm not going to answer questions about it, and quite frankly, I'm reluctant to release stuff like this because it pretty much always turns into more tech questions for me and probably not much value for anyone as just the raw source without documentation or a makefile or other stuff to help you use it.

Thanks a million, Paul. That has all the information I need. It appears that I was looking for the wrong uagepage.
 
Last edited:
Hello Paul, Sorry this is so late, 8 years after your post. We're running into an issue with the Teensy 4.0 on a new project. in the above 'simple & cheap' version, should you catch the Teensy program with interrupts disabled, would it be possible to retry & succeed? Also, if your Teensy were streaming data continuously out through the USB port, would that be a problem, and could one solve that by just stopping that streaming without closing the USB uart?
Thank You,
John
 
Status
Not open for further replies.
Back
Top