how debug unhandled exception

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

Moderator: RoccoMarco

lesto
Posts: 55
Joined: Thu May 22, 2014 11:27 am

how debug unhandled exception

Post by lesto »

hi,
my code is getting unhandled exception, but i can't understand why.
what is the approact to find out what is causing this?

it seems to happen inside a i2cMasterTransmitTimeout
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: how debug unhandled exception

Post by Giovanni »

Are debug options enabled in chconf.h?

Giovanni
lesto
Posts: 55
Joined: Thu May 22, 2014 11:27 am

Re: how debug unhandled exception

Post by lesto »

yes, all debug option are set to true
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: how debug unhandled exception

Post by Giovanni »

You provided no context, how are we supposed to help?

Giovanni
lesto
Posts: 55
Joined: Thu May 22, 2014 11:27 am

Re: how debug unhandled exception

Post by lesto »

well, i down't know how provide context :)

there are 2 thread, the "main thread", witch every 3 ms check if there is new data and print it by USB (worked fine)
the "read thread" witch wait for an event (send by 2 interrupt) and make a SPI a I2C read.
Basically the board's sensor of the STM32f3discovery end the data redy interrupt, the interrupt send an event to the "read thread", witch start the reading. code https://github.com/MauroMombelli/testCh ... d_thread.h

the reading (i haven't upload the code yesterday) is a basic

Code: Select all

spiAcquireBus(&SPID1);
   spiStart(&SPID1, &spi1cfg);
   spiSelect(&SPID1);

   spiExchange(&SPID1, 8, txbuf, rxbuf);

   spiUnselect(&SPID1);
   spiStop(&SPID1);
   spiReleaseBus(&SPID1);


and should be correct as initial configuration of the sensor are fine.

the point is i don't think to had change the code of the sensor, so i may had done something wrong with somehow trigger the reading error.
reading sensor:
https://github.com/MauroMombelli/testCh ... l3g4200d.c
and
https://github.com/MauroMombelli/testCh ... sm303dlh.c
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: how debug unhandled exception

Post by Giovanni »

lesto wrote:well, i down't know how provide context :)


This is a problem. If you are going to ask for help it is your best interest:
1) Provide enough data or help cannot be given.
2) Don't give not relevant data or the message is lost in the noise.

In general:
3) Make the simplest program that shows the problem and post just that.

About the code, why post SPI code if the problem seems to be I2C?

I recommend single step into the functions and see where it fails, this should give an hind about the problem. Usually a good approach is to remove everything and start reintegrating parts and see where it fails (divide et impera).

Giovanni
lesto
Posts: 55
Joined: Thu May 22, 2014 11:27 am

Re: how debug unhandled exception

Post by lesto »

problem appear with i2c and spi.

i'll try to strip down thing, but i would like to understand if there is a "error message", maybe even a stack trace to find out what i'm dong wrong, or at least point me in the right direction.

ps. the forum seems really unstable, it gives error 500
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: how debug unhandled exception

Post by Giovanni »

Are SPI and I2C using the same DMA channels?

Giovanni
lesto
Posts: 55
Joined: Thu May 22, 2014 11:27 am

Re: how debug unhandled exception

Post by lesto »

yes, but they are sequental, in the same thread, just because this..

BTW edbugghing here and there i found out what was causing the issue:

Code: Select all

void unkonw_interrupt(EXTDriver *extp, expchannel_t channel) {
   /* Wakes up the thread.*/
   (void) extp;
   (void) channel;

   //CH_IRQ_PROLOGUE();

   interruptCounter[channel]++;

   //CH_IRQ_EPILOGUE();

}


commenting out CH_IRQ_PROLOGUE and CH_IRQ_EPILOGUE seems to fix the behavior. Is this correct?
Is EXTDriver taking care of it?

Btw the problem is never, or very rare with SPI, using I2C after some hundred read it break.

weird thing is that sometimes i got a unhandled_exception and sometimes port_halt, seems to depend on with part of code i enable (reading to accelerometer i2c or magnetometer i2c)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: how debug unhandled exception

Post by Giovanni »

Callbacks are not ISRs, you are not supposed to use those macros there.

Giovanni
Post Reply