I wish to register a function to be used as the error handler during booting, for use in detecting CRC errors.
Since I want this function to perform my own actions I cannot use the default ROM function, and as such I need to first load the error handler function into L1/2/3 memory so that it can be called later (I think it should be possible to load the error handler into SDRAM after the init block is called - as far as I know I cannot install my own error handler any earlier than the first init block anyway).
My question is, is there a clever way to ensure that my error handler isn't overwritten by the application code during booting? Or do I need to ensure that the error handler code and the application code do not overlap, since there may be an error even when loading the last application block?
For example, would I be best to place the error handler code in the upper 16kB of L1 instruction memory which will be used as cache once the executable has booted? My only concern is that I am designing a firmware upgrade system and in the future I may change the behaviour of that L1 memory from cache to bootloaded code, in which case the error handler will not outlive the last loaded block of the executable.
My intuition tells me I should just reserve some memory at the start of my SDRAM for the error handler and put it there and make sure that it isn't overwritten by the executable.
Thanks for your advice!