Debugging unhandled exception.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

duststorm
Posts: 11
Joined: Tue May 03, 2016 4:47 pm
Has thanked: 3 times

Re: Debugging unhandled exception.

Post by duststorm »

Sorry to be digging up an old thread, but I'm having trouble debugging unhandled exceptions and perhaps someone can help.

Observation: as soon as I change any of the aliases (that all point to the same _unhandled_exception function) then the program no longer works. It gets stuck in the _unhandled_exception trap as soon as I continue from the ResetHandler using the debugger. I have not been able to find an instruction that is executed before it goes into error mode.

What I did was the following modifications to vectors.c:

Code: Select all

/**
 * @brief   Unhandled exceptions handler.
 * @details Any undefined exception vector points to this function by default.
 *          This function simply stops the system into an infinite loop.
 *
 * @notapi
 */
/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
void _unhandled_exception(void) {
/*lint -restore*/

  while (true) {
  }
}

/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
void _hard_fault(void) {
/*lint -restore*/

  while (true) {
  }
}

void Reset_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void NMI_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
//void HardFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void HardFault_Handler(void) __attribute__((weak, alias("_hard_fault")));
void MemManage_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void BusFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void UsageFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));



If I try defining some of the error functions, instead of using the alias declarations, like ulikoehler suggested, I get a different but similar issue. The debugger gets stuck in the __DSB(); function of NVIC_SystemReset() and blocks indefinitely.

Using ChibiOS 3.0.2

Does someone have an idea what might be going wrong?
duststorm
Posts: 11
Joined: Tue May 03, 2016 4:47 pm
Has thanked: 3 times

Re: Debugging unhandled exception.

Post by duststorm »

This is probably a false alarm. Perhaps using the debugger too intensively for longer times somehow brought chaos.
I backed of the changesets, hard powered down the development board, made sure all gdb and stm link processes were exited. Then after reapplying my changesets one by one and testing it seems my code came back to life.
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: Debugging unhandled exception.

Post by steved »

If your problems recur, there's a version of vectors.c in this thread which I found very useful, since the debugger breaks as soon as the exception is encountered, with various useful information stored.
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: Debugging unhandled exception.

Post by russian »

BRILLIANT! Thank you very much! This should be in ChibiOS by default, this improves my HardFault comfort so much!
Post Reply