zigbert wrote:
Has anyone had experience modularizing a section of code such that it could be replaced on the fly using the SCI interface (like a boot_loader that targets only parts of the code)?
For instance, I have an ISR that is triggered by the TPM comparator. It is less than 500 bytes so it could reside on a single flash page by itself. That way a bug fix could occur by replacing the ISR page. AND if I give all 1600 processors a common "bug fix" address, I could do the repair to all of the devices at once.
There's really no end to the possibilities one can come up with, and here's some:
Don't count on any scheme based on the current ISR's size. A possible future bug fix could make the code larger than a Flash page, and your original strategy might fail.
Are you interested in being able to update only the specific ISR, or any part of your code? If any part of the code is a candidate, it won't be easy to break your code into about 32 distinct sections (your MCU's max Flash pages, I assume) to support your current strategy.
Is this going to be a 'live' update (meaning, while the rest of the code is executing)? In this case, if you want to replace a single ISR for example, you can have a RAM pointer to it, and always make calls to it thru that pointer. Once a possible update is finished, you only need to write the new entry address to that pointer (with an atomic instruction, such as STHX), and your code will continue running with the new version. This way, the updated code can be located anywhere in Flash, not just in a fixed page, and be any size (within availability of unused Flash). The original code space now becomes available again for a another possible update. This method means you need as many pointers as the sections of code which are predefined as upgradeable.
By far, the hardest part is doing a concurrent update to all modules. Sending code to all of them is certainly easy, but guaranteeing that all modules will receive it without errors and no need for 'packet' retransmits, is a problem. It's like UDP broadcasts. You can the send packets but there are no guarantees there will be received by all devices. You need something like TCP, but that means one at a time, if you don't want to end up with 1600 'sockets' open at once.
Assuming they do not all need to be synchronized with the new code, but you're only trying to simplify the process by sending the update once and have all devices get updated, I'd go a different route. Send the update to device 1 (using some protocol which, like TCP, 'guarantees' [timeouts not withstanding] the successful delivery of your data), and once that device is done updating itself, it will be responsible to send the update to device 2 (again using the same protocol), and so on. The update packets should be designated as such so the device will know to pass it on, rather than consume it and stop. The cascade time might take a while but you'll only worry about sending the update once. If there is a failure at some node (e.g., comms timeout), you can have it report this back to the main PC (where the update began), so you can try again (once the comms problem is fixed) starting with that node's address. I've actually done this scheme with a HC11 based network, and it worked very well (under my RTOS).