_unhandled_exception (GCC) is not a weak symbol

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
Post Reply
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Been thanked: 3 times

_unhandled_exception (GCC) is not a weak symbol

Post 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
Post Reply