bigboosted
Well-known member
Congratulations! Sometimes it helps just to know that it is possible, no?
Yes and thanks to you, jonr and all the other contributors! This would not be possible on my own!
I'm a bit confused what you mean with lower and upper. There is a nice Memory Layout picture in https://www.pjrc.com/store/teensy40.html; you'll see that all regular code is copied into RAM1 at startup, leaving only FLASHMEM code and PROGMEM variables in flash memory. Teensy 4.0 flash starts at 0x60000000 and is 0x200000 in size. So I store the new firmware as received into the region starting at 0x60100000 first ("upper"), then I check, then I move to 0x60000000 ("lower") first erasing pages as I go, then I reboot. I don't bother to erase the "upper" half after copying as I want to make the "copy to lower and reboot" as fast and robust as possible, because indeed if that goes wrong the mechanism could well get stuck and then what's left is to revert to USB programming.
In my mind, the lower was the higher number but I see now that I was wrong. I took the available memory 0x200000 subtracted the 0x10000 area and divided it into 2 leaving 0xF8000 in each section.
So I can load up to a 0xF8000 byte file. I start building the new file at 0x600F8000 and when done move it up to 0x60000000.
The only reason I erase the upper section after is the thinking of protecting my code. Also once the Lower is erased and the file is moved to 0x60000000 then if power is lost it will still work even if it's interrupted while erasing the Upper. I see no negative about erasing the upper after moving it. Please correct me if I'm wrong.
As I'm forwarding the Intel Hex format data as I receive it streamed via MQTT my sender does not need to have the full file in memory.
Interesting. I don't believe I'm talented enough to pull that off... yet.....
Yes, indeed, it's not bullet proof. More robust designs (companion uC talking CAN etc.) are surely possible, but also require a bit more effort.
I started looking into making a very simple upload sketch to replace the 4K known good blink sketch that is located at the top of the memory. However, I found a comment by Paul that this area is irreversibly fused to read-only
If there was a way to change this 4K area all I would have to expose is the button to make it so I never need the USB.
I'm also thought about using an SD card or memory chip to hold the uploaded file then send to 0x60000000.
But currently, my biggest file is only 10% of the 50% available to me with this type of upload.