Page 1 of 1

canReceive random chSysHalt in osal

Posted: Wed Sep 23, 2015 3:09 pm
by Wafelijzer
Hi,

I'm facing random chSysHalt SV#10 and SV#11 when I enable checking (even stack overflow check).
My backtrace:

Code: Select all

#0  0x080032b4 in chSysHalt (reason=0x80096f0 "SV#11") at ChibiOS/os/rt/src/chsys.c:175
#1  chDbgCheckClassS () at ChibiOS/os/rt/src/chdebug.c:253
#2  0x0800334e in chSchGoSleepTimeoutS (newstate=newstate@entry=4 '\004', time=10) at ChibiOS/os/rt/src/chschd.c:332
#3  0x080034ce in chThdEnqueueTimeoutS (tqp=<optimized out>, timeout=<optimized out>) at ChibiOS/os/rt/src/chthreads.c:652
#4  0x0800520c in osalThreadEnqueueTimeoutS () at ChibiOS/os/hal/osal/rt/osal.h:784
#5  canReceive (canp=<optimized out>, mailbox=0, timeout=10, crfp=0x20001614 <dncm_can_reader_thr_wa+420>) at ChibiOS/os/hal/src/can.c:224
#6  dncm_can_reader_thr.lto_priv.137 (arg=<optimized out>) at src/can.c:58
#7  0x080002f6 in _port_thread_start ()


Code: Select all

static THD_WORKING_AREA(dncm_can_reader_thr_wa, 128);
static THD_FUNCTION(dncm_can_reader_thr, arg)
{
        (void)arg;
        CANRxFrame msg;
        msg_t rc;

        chRegSetThreadName("can_rx");

        while (1) {
                rc = canReceive(&CAND1, CAN_ANY_MAILBOX, &msg, MS2ST(1));
                if (rc == MSG_OK)
                        di_can_receive(msg.EID, msg.data8, msg.DLC);
                chThdYield();
        }
}

void dncm_can_init(void)
{
        CANConfig cfg = {
        /*.mcr = */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
        /*.btr = */ CAN_BTR_SJW(0) | CAN_BTR_TS2(4) | CAN_BTR_TS1(14) | CAN_BTR_BRP(1)
        };

        palSetPadMode(DNCM_CAN_PORT, DNCM_CAN_PIN_LOW,  DNCM_CAN_PIN_LOW_PAL_MODE);
        palSetPadMode(DNCM_CAN_PORT, DNCM_CAN_PIN_HIGH, DNCM_CAN_PIN_HIGH_PAL_MODE);

        canStart(&DNCM_CAN_DEV, &cfg);

        chThdCreateStatic(dncm_can_reader_thr_wa, sizeof(dncm_can_reader_thr_wa), NORMALPRIO,
                          dncm_can_reader_thr, NULL);
        chThdCreateStatic(dncm_can_pub_thr_wa, sizeof(dncm_can_pub_thr_wa), NORMALPRIO,
                          dncm_can_pub_thr, NULL);
}


I'm uncertain it has to do with my code and where to look because almost nobody is using CAN.

Re: canReceive random chSysHalt in osal

Posted: Wed Sep 23, 2015 4:52 pm
by Giovanni
The problem I can see is that your CANConfig structure is an automatic variable, the driver continues to refer it after canStart() but the variable is gone after dncm_can_init() exits.

Try making it static const.

Giovanni

Re: canReceive random chSysHalt in osal

Posted: Wed Sep 23, 2015 6:54 pm
by Wafelijzer
I really missed that one, that maybe explains random system hangs at different places because it is on the stack and is overwritten somewhere, sometime.
Now it is at the top of the file declared as static.

Thanks for catching that one, for now it seems to run fine!