Is there no simple working example for this library? OK I'm not very clever, but I would like to have a sketch to install on the master Teensy and a sketch to install on the slave Teensy and a script or whatever to run on my PC that picks up a compiled hex file from the PC, passes it to the master, the master passes it to the slave and the slave installs the new hex file and reboots. FlasherX.ino is a single sketch. Surely there needs to be a master sketch and a slave sketch, both or which also include so 'normal' stuff like blinking leds or sending Midi?
FlasherX.ino seems to be the sketch that goes in the slave, but where does MY actual sketch go... not inside FlasherX.ino's void loop() because that seems busy moving data around and rebooting. So if it's not an example of the slave sketch, are there examples somewhere that I've missed that operate in the required master and slave roles? If someone has got this to work and is able to have something like a slave sketch flashing a led at 1Hz and to send a new sketch to it that flashes at 2Hz, then please share the sketches because I really don't understand what FlasherX does! Thanks.
@AndyA provides a good answer to your question, and I can add a little more.
FlasherX can be used in many different ways. There's no way I could provide a "simple working example" for every possible usage. The core functionality of FlasherX is the low-level stuff:
- with new firmware stored on Teensy (RAM, Flash, SD, etc.)
- erase old firmware from boot memory
- copy new firmware from storage location to boot memory
- erase new firmware from storage location (if stored in flash)
- reboot to run new firmware
What FlasherX does NOT do is specify HOW to get the new firmware into the target Teensy.
The example sketch is designed to show the low-level stuff works, and supports these simple options for getting the new firmware into the target:
- transfer via USB or hardware serial and buffer in Flash or RAM
- read file from built-in SD
These are not production solutions. For the USB or hardware serial transfer, the sketch reads the new firmware via a serial stream. This allows someone to send the new firmware using something like a terminal emulator that supports "file send", so that no custom client is required. The user manually confirms that the file has been transferred correctly.
In my own applications, I generally have a custom Windows client that sends the new firmware to the Teensy with a packet-based protocol. The target Teensy sketch contains code to read the packets, extract the payload and add it to the buffer. When the entire firmware has been transferred, the Windows client and Teensy do a handshake to confirm that the new firmware is correct and complete, and if so, the Windows client sends a command to tell the Teensy to go ahead with the update.
I don't know a lot about Ethernet, but I think you could do something relatively low-level, like what I do but over Ethernet instead of serial, or something higher-level such as having your master Teensy be an FTP server that can receive a file from an FTP client and write it to SD. Once you have the file on your master Teensy's SD, the master can open the file, read it block-by-block, and sending each block to the slave Teensy over serial or whatever interface you have between master and slave. The slave Teensy could have something like the FlasherX example sketch, receiving the new firmware over serial, buffering in Flash or RAM. The one thing you would have to add is a way for the slave to know that the transfer is complete, and hopefully a way to compute and test a checksum or CRC. It's pretty important for the target to confirm that the firmware is correct and complete before erasing the existing firmware and writing the new firmware to program flash.
One thing I would like to add is an example where the Teensy sends it's own firmware to itself, such as send on Serial1 and receive on Serial2, and update when complete. The "new" firmware would be the same as the old firmware, but it would show how to implement send/receive using a library like SerialTransfer, which can send/receive packets containing arbitrary data, in this case I would have each packet contain one line of the hex file.