Program Teensy 3.2 from within my own (windows) program

Status
Not open for further replies.

dlchambers

Well-known member
Is it possible to incorporate Teensy 3.2 programming into my custom Windows app?

I want to distribute my own updater (a .NET application) which can determine (via USB serial talking to my Teensy-based program) if an update is needed, and when it is, push a new .hex file from Windows down into the Teensy via USB.

Any help/ideas would be greatly appreciated.

Thanks,
-Dave
 
Seems simple enough - that's really what teensy_loader_cli wraps.
It seems that the VID/PID of 0x16C0/0x0478 is still used by for the 3.2.

Question: How does the Windows app put the Teensy into bootloader mode?
0x16C0/0x0478 isn't active until you press the button on the Teensy, but the Teensy loader is able to activate the bootloader from the Windows end.
 
Last edited:
Question: How does the Windows app put the Teensy into bootloader mode?
0x16C0/0x0478 isn't active until you press the button on the Teensy, but the Teensy loader is able to activate the bootloader from the Windows end.
If the USB serial interface is enabled, the baud rate is set to 134 on the Windows side. This triggers a USB CDC control request which is detected by the Teensy USB stack.

If RawHID is active, a HID message with a magic number (0xA945C26B) is sent to the SEREMU interface (special HID endpoint to emulate serial console).

All this is handled in "hardware/teensy/avr/cores/teensy3/usb_dev.c", look for "usb_reboot_timer".
 
@luni: That's EXACTLY what I was looking for.
It works beautifully - THANKS!!!
Another win for the PJRC community.
 
TeensyWatcher provides a Serial number for each Teensy (eg. 2030840 decimal).
I see the source of this (in the .NET code) is the registry entry (via a ManagementObject)

Follow-on questions:
1) Is this indeed a unique # for each Teensy?
2) How can one retrieve it from within a Teensy C++ program (Teensyduino sketch, in my case)?
 
Inside each teensy (except for a few of the early beta boards) is a unique number meant to be used for an ethernet MAC address. This thread addresses how to get the unique number along with the changes needed for Teensy 3.5/3.6: https://forum.pjrc.com/threads/91-teensy-3-MAC-address.

Obviously, whatever your software that connects to the Windows/Linux/Mac system can get the value and write it out.
 
I'm finding that my .hex works perfectly when written by Teensy.exe, but does not work when written by TeensySharp's 02_FirmwareDownloadConsole.
When the hex is written by TeensySharp, the COM port never mounts, and it can take 2 presses of the upload button to get the bootloader to function.
TeensySharp will correctly write all my smaller/simpler programs (eg. something that justs open USBSerial and flashes the LED), but when I add size/complexity it stops working.

Anyone else seen anything like this?
How do Teensy.exe and TeensySharp differ in their mechanisms for writing the hex?


I'm using Arduino 1.6.9 on Win10 with a Teensy 3.2 running "USBSerial" and "72MHz reduce code size".

The program opens Serial at 38400 and, as a diagnostic, blinks an LED on pin 17. The LED is on solid for the 1st couple seconds during setup() then blinks each time it does loop()

The hex file is in the attached ZIP, just in case anyone wants to try it :)

Thanks,
-Dave
 

Attachments

  • myhex.zip
    77.2 KB · Views: 69
Dave, I'm using the library quite heavily in my own applications. Never had any issues. Did it report any errors during/after the upload?
Lutz
 
Ok, I'll have a look at the code.
Hope it is not too urgent, I'm quite busy the next days. The file is quite large, maybe there is a Hex-Decoding bug which didn't show up for smaller files.
 
Think I already found it. There is a silly bug in the calculation of the segment address (SEGBA) in the hex file, it only affects hex files with addresses larger than 0xFFFF. I checked my largest firmware files, they are all below 0xFFFF so I never saw this bug.
I'll try to fix it tomorrow.
Sorry for that
Lutz
 
Great, that was an easy one :)

I'll add support for T3.5 and T3.6 as soon as I find some time.
 
I finally updated TeensySharp to be compatible with Teensy 3.5 and Teensy 3.6. Per request it now also handles Teensies without serial number (e.g. Teensies on a selfmade board)
Any feedback, bugreports and improvement requests welcome.

https://github.com/luni64/TeensySharp
 
Status
Not open for further replies.
Back
Top