Page 1 of 2

how debug unhandled exception

Posted: Mon Oct 06, 2014 12:06 am
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

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 7:53 am
by Giovanni
Are debug options enabled in chconf.h?

Giovanni

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 10:09 am
by lesto
yes, all debug option are set to true

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 12:44 pm
by Giovanni
You provided no context, how are we supposed to help?

Giovanni

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 1:32 pm
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

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 1:49 pm
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

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 4:51 pm
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

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 5:45 pm
by Giovanni
Are SPI and I2C using the same DMA channels?

Giovanni

Re: how debug unhandled exception

Posted: Mon Oct 06, 2014 9:41 pm
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)

Re: how debug unhandled exception

Posted: Tue Oct 07, 2014 8:02 am
by Giovanni
Callbacks are not ISRs, you are not supposed to use those macros there.

Giovanni