Best way to automate firmware with a variable that changes each compile?

Status
Not open for further replies.
By serial# I meant the teensy MAC factory ID - I see you get KUIR as well. While you get that you can also get the serial#.
serial in my edit is what USB 'serial monitor' refers to - but I think that was cross posted when I realized you might be after something else.
 
@Frank B

that mod for the loader seems to work :)

Teensy Loader, Command Line, Version 2.0
Read "demo.cpp.hex": 42464 bytes, 16.2% usage
Soft reboot is not implemented for Win32
Waiting for Teensy device...
(hint: press the reset button)
Found HalfKay Bootloader
Read "pinDMD3.cpp.hex": 42464 bytes, 16.2% usage
Programming..........................................
Booting

Only problem is it needs me to press the reset button on the teensy to initiate the upload. The GUI version seems to do this automatically? Can we enable this soft reset for windows?

Regards
Russell Pirie
 
@Frank B

that mod for the loader seems to work :)

Only problem is it needs me to press the reset button on the teensy to initiate the upload. The GUI version seems to do this automatically? Can we enable this soft reset for windows?

Regards
Russell Pirie

Maybe.......
 
hmmm no windows command line teensy loader for 3.1 kinda puts a stop to my plan though! lol

You can use the teensy_post_compile.exe utility to automate informing the Teensy Loader of which hex file you want. This utility also puts Teensy Loader into auto mode, so the hex file is automatically programmed onto the next Teensy to appear (in bootloader mode).

Then you can use teensy_reboot.exe to search for a connected Teensy and request it to reboot into bootloader mode. When (if) the Teensy appears, Teensy Loader does the rest.

These 2 command line utilities are how Arduino does things, when you click the Upload button. You can use them too. Look for them in Arduino's hardware/tools folder.
 
However, if you have more than 1 Teensy connected, which one the teensy_reboot.exe utility finds is pretty much random. Well, not random, but depends on the order they're found when querying Windows for device lists, which isn't really random, but it is pretty much outside of your control.

This is also why Upload from Arduino really only works well with 1 Teensy connected. It's just running those 2 command line utilities.
 
Another way to do this is to have the download be a two step process.

You add code to init, to read a chunk of bytes from the EEPROM and compare it to __DATE__, __TIME__, and perhaps a version number in the source. If those values do not match, you assume that the Teensy needs to use the USB serial connection to get the appropriate information and store it in another area of EEPROM.

Then when you reprogram the Teensy, it will connect to your system, and your application can supply the information, and you write that information plus __DATE__, __TIME__, etc. to EEPROM. There after, it uses the information that you programmed.

Note, that the LC has very little EEPROM, and that the number of rewrites that it supports is fairly low. If you are going to be programming the Teensy often, it is probably better to use the 3.1/3.2.
 
Thanks Paul that is indeed another route I can take :) (I was wondering how Ardunio talked to that loader!)
(I only ever have one teensy connected at a time)
 
It would be nice to use the cli loader i prefer to go this route but it needs to be fully automated. I have compiled the source my self as well. Could you share all your changes you did to get it working? :)
Im not sure how you would go about forcing a reset on the teensy though?
 
Are there any pre compiled versions of this tool or do i need to compile it my self?

Regards
Russell
 
It is included in the TyQt archive, the latest version is available at https://github.com/Koromix/ty/releases/tag/v0.6.3.

Use 'tyc upload filename.hex (or .elf)' to upload a firmware to the first available Teensy. If you want to upload to a specific board, use 'tyc upload --board "#serial_number" filename.hex'. The documentation is kinda wrong because it omits the '#' prefix before the serial number, and that's because the README refers to the next version (0.7.0) where the syntax will change. But my free time is very limited right now, and this update is overdue.
 
Ah perfect and this will reset the teensy as well so i can just run this command and it will do the rest? :)
 
Yes. And you can use "tyc list --verbose" to list the available Teensies and print the associated COM port, among others... Which may help you with your other question/topic.
 
Ah cool so there is a way to find out which com port the teensy has been assigned this is good to know :) i will only ever be dealing with one teensy at a time.

Regards
Russell
 
It would be nice to use the cli loader i prefer to go this route but it needs to be fully automated. I have compiled the source my self as well. Could you share all your changes you did to get it working? :)
Im not sure how you would go about forcing a reset on the teensy though?
Hi,

Ok, first and obvious, the makefile must be edited :)
-then, remove the #ifdef in the MCUs array
- in write_usb_device() (windows-portion of sourcecode), the tmpbuffer is too small - i enlarged it to 1090.
last.. hm..there is a problem with the timeout/waiting in write_usb_device() - it does not work.
i spent 1/2 hour to find the reason, but without success. i never used the winapi in c. so..maybe you want to find a better way than mine.
quickly, i found a solution that is not good, but good enough*. :) - Add "Sleep(100);" before " if (!GetOverlappedResult(..."
that's it.

For the reset: Hm, the linuxpart shows how this has to be done. For windows, this does not work - as you can see, if you try the "hard reset" ("-r")
I think, some kind of waiting in the reset functions has to be done.

Frank

edit:* it works - for me.
 
Last edited:
-r option does not work, it can never find the teensy 3.1 device :(

On another note the Koromix - TYC works very well :)

Regards
Russell
 
Last edited:
Frank B

I have nearly got my batch script setup like yours


rem Edit this Line:
set arduino=c:\arduino
rem

set arduinotools=%arduino%\hardware\tools\arm\bin\
dir /s /b /o-d %temp%\build*.tmp>%temp%\builds
set /p lastbuilddir=<%temp%\builds
dir /s /b /o-d %lastbuilddir%\*.elf>%temp%\elfs
set /p lastbuild=<%temp%\elfs
gsar -f -s"rEpLac" -r"123456" %lastbuild% out.elf
%arduinotools%\arm-none-eabi-objcopy.exe -S -R .eeprom -v -O ihex -p out.elf out.hex


I have noticed arm-none-eabi-objcopy.exe reports File format not recognized once passed through the gsar tool. Also noticed just editing the file my self same result even if i just open the file and save it (no changes) does that tool edit the file in another way? that is upsetting arm-none-eabi-objcopy.exe
 
Ah sorry my fault. Me opening the file in windows trashed it! oopsy (changes carriage returns)
If I leave it alone it all works great :)
 
Status
Not open for further replies.
Back
Top