STM32F072 crashes... But wehre ?

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

Moderators: RoccoMarco, barthess

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

STM32F072 crashes... But wehre ?

Postby rew » Thu Jun 17, 2021 3:07 pm

I have a difficult problem. My program iterates across doing stuff with (currently not attached) SPI devices on different CS pins.

After doing about 5 / 14 devices it crashes:

Code: Select all

continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
_unhandled_exception () at chibios/os/common/startup/ARMCMx/compilers/GCC/vectors.c:46
46      void __attribute__((weak)) _unhandled_exception(void) {
(gdb) where
#0  _unhandled_exception () at chibios/os/common/startup/ARMCMx/compilers/GCC/vectors.c:46
#1  <signal handler called>
#2  0xfffffffe in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)


Any suggestions on how i can figure out where the crash happens?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32F072 crashes... But wehre ?

Postby Giovanni » Thu Jun 17, 2021 4:11 pm

Hi,

On exception Cortex-M cores save a context structure on the PSP or MSP (depending if it was in process or exception context already), the PC is stored in that structure, you need to inspect memory starting at the xPSP value.

The structure is like this:

struct port_extctx {
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr_thd;
uint32_t pc;
uint32_t xpsr;
};

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F072 crashes... But wehre ?

Postby rew » Thu Jun 17, 2021 4:48 pm

Thanks! Found it on the PSP stack. Aligns perfectly that LR and PC end up being in flash, and a couple of the registers match with what GDB tells me, i.e. unchanged since dumped on the stack... Investigating.... :-)

Update:

The crash happens in "gosleeptimout" called from "gosleep" called from chThdSleepMilliseconds called from my Blinky thread:

Code: Select all

static THD_WORKING_AREA(waBlinky, 256);
static THD_FUNCTION (Blinky, arg)
{
  int i;

  (void)arg;
  chRegSetThreadName("blinky");
  make_output (MYLED2);
  while (TRUE) {
    chThdSleepMilliseconds(1000);
    for (i=4;i;i--) {
      clr_bit (MYLED2); // turn on led
      chThdSleepMilliseconds (250);
      set_bit (MYLED2); // turn led off
      chThdSleepMilliseconds (250);
    }
  }
}
(This code was copied from an application where it would blink the state of the main statemachine, but here it just blinks the constant "4" (there is no main statemachine).

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: STM32F072 crashes... But wehre ?

Postby electronic_eel » Sat Jun 19, 2021 6:02 pm

What compiler version exactly are you using?
It could be some version that is affected by these bugs: http://forum.chibios.org/viewtopic.php?t=5281

Does the bug also appear when you disable all optimization in the compiler (-O0)?

Have you tried running your program with Chibi-assertions and checks enabled (CH_DBG_SYSTEM_STATE_CHECK, CH_DBG_ENABLE_CHECKS, CH_DBG_ENABLE_ASSERTS, CH_DBG_ENABLE_STACK_CHECK)? With these options you get a fault whenever you use some os function the wrong way, fill up your stack or similar.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32F072 crashes... But wehre ?

Postby Giovanni » Sat Jun 19, 2021 6:03 pm

Hi,

You should check for stack overflows too.

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: STM32F072 crashes... But wehre ?

Postby rew » Mon Jun 21, 2021 1:34 pm

Yup stack overflow.
:-/


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 18 guests