Page 1 of 1

_unhandled_exception (GCC) is not a weak symbol

Posted: Thu Sep 10, 2015 3:06 pm
by ulikoehler
Hi,

_unhandled_exception is defined in os/common/ports/ARMCMx/compilers/GCC/vectors.c and is called when any interrupt vector is called that does not have a definition (vectors themselves, e.g. Vector50, are weak symbols).

Code: Select all

void _unhandled_exception(void) {
/*lint -restore*/

  while (true) {
  }
}

_unhandled_exception sends the system in an infinite loop. In my case, this is a dangerous behaviour, as it means the system will wait until IWDG (up to 1-2 seconds).

I'd define it like that:

Code: Select all

void _unhandled_exception(void) {
/*lint -restore*/
  __BKPT();
  NVIC_SystemReset();
}


This just resets the system, but causes a debugger breakpoint (__BKPT instruction is ignored if no debugger is attached).
I am not sure if this approach is fine for all applications so I'll assume it is not.

Currently it is impossible to redefine _unhandled_exception outside of vectors.c because it is not a weak symbol. I therefore propose to change

Code: Select all

void _unhandled_exception(void) {


into

Code: Select all

__attribute__((weak)) void _unhandled_exception(void) {


Best regards, Uli