
Originally Posted by
Frank B
I have an Idea.. I could extend the Hardfaults for a kind of "user" exceptions.
It would need a macro that prints the userdefined text together with the GCC macros
__FILE__, __func__, __LINE__
Probably similar to this:
Code:
//Macro test
//#define DIE_WITH_PATH
#if !defined(DIE_WITH_PATH)
#define _FILENAME_ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__) )
#define DIE(msg) _die(_FILENAME_, __func__, __LINE__, msg)
#else
#define DIE(msg) _die(__FILE__, __func__, __LINE__, msg)
#endif
FLASHMEM
void _die(const char *file, const char *func, unsigned line, const char *msg)
{
//Testing only. This should reset and print these texts _after_that.
//Does not use printf on purpose.
while(!Serial);
Serial.println(file);
Serial.print("Function \"");
Serial.print(func);
Serial.print("\" died in line ");
Serial.println(line);
if ( msg != nullptr ) {
Serial.print("Last words:\"");
Serial.print(msg);
Serial.print("\"\n");
}
while(1) asm("wfi");
}
void setup() {DIE("I felt it was time.");}
void loop() {}