11 years, 5 months ago.

Reset stack in error(...) handler

Hey guys. I'm trying to add a custom error(...) function to a project of mine that redirects the error message to EEPROM, but I'm running into a (potential) issue with memory consumption. My function requires a 256B RAM buffer to construct the message, but there's the possibility of error(...) being called from a thread with less than 256B of stack, or worse yet, being called by the RTOS in an out of memory situation. Seeing as how the system just resets after error(...) completes, is there anything wrong with disabling interrupts and resetting the main stack pointer using __set_MSP() to the top of the RAM? I don't want to use a static 256B buffer since it's a waste of resources.

EDIT: I forgot, error(...) is a variadic function, so the arguments are going to have to come in on the stack... Any other suggestions?

Be the first to answer this question.