I am trying to write a script that will allow me to update firmware on a p1 or photon from a .bin file on an SD card. I recently asked a related question here: Using OpenLog to update Particle Firmware, but have since made progress and have a new question.
I can’t use SDFat because we only have access to UART on the current version of our board, so I’m looking trying to create a solution that uses Serial1 to communicate directly with OpenLog.
Below is a gist of what I currently have. It almost works, but the firmware flash is garbled for reasons that I don’t quite understand.
The reason that this is particularly confusing to me is that it appears to be related to when the bytes are instantiated. I reproduced the same bug in a different code base by instantiating binary in the loop instead of before it. In the following gist, one set of code is a working example of code that can be used to flash
tinker code onto a photon, and the other fails, simply because
const uint8_t tinker is defined in
flashTinker(), which lives in
loop(). Why would this cause an issue?
Thanks in advance for the help!