Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 36 of 36

Thread: Remote reboot / user code update

  1. #26
    Senior Member
    Join Date
    Jun 2013
    Posts
    323
    Quote Originally Posted by johnboiles View Post
    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

  2. #27
    Senior Member Koromix's Avatar
    Join Date
    Dec 2013
    Location
    Lille, France
    Posts
    198
    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.

  3. #28
    Senior Member
    Join Date
    Jun 2013
    Posts
    323
    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

  4. #29
    Senior Member
    Join Date
    Jun 2013
    Posts
    323
    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?

  5. #30
    Senior Member Koromix's Avatar
    Join Date
    Dec 2013
    Location
    Lille, France
    Posts
    198
    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.

  6. #31
    Senior Member
    Join Date
    Jun 2013
    Posts
    323
    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

  7. #32
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,814
    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.
    Attached Files Attached Files

  8. #33
    Senior Member
    Join Date
    Dec 2013
    Location
    Brasilia, Brazil
    Posts
    166
    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?

  9. #34
    Senior Member
    Join Date
    Dec 2013
    Location
    Brasilia, Brazil
    Posts
    166
    Koromix, I edited the issue (thrice!) and suggested a possible solution. Please check out if what works for me works for you as well: https://github.com/Koromix/ty/issues/1

  10. #35
    Senior Member
    Join Date
    Jun 2013
    Posts
    323
    Quote Originally Posted by PaulStoffregen View Post
    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 by yeahtuna; 12-29-2014 at 01:25 AM.

  11. #36
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    52
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •