chSyshalt with reason "chThdResumeI" from SPID1

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

Moderators: RoccoMarco, barthess

totalkrill
Posts: 12
Joined: Thu Jul 09, 2015 2:21 pm

chSyshalt with reason "chThdResumeI" from SPID1

Postby totalkrill » Wed Oct 14, 2015 9:08 am

Hi!

I am having a problem where the microcontroller is ending up in a chSysHalt because of chThdResumeI. What i am using is a rising edge pin-interrupt to send an event to a thread to make that specific code run. This code uses a lot of SPI commands. The first thing the thread does is to access the SPI. This has worked for a long time, but now that i am trying to put the SPI slave into 'sleep' mode, the IRQ pin is getting a noisy signal straight after this is happening. I do not really understand how this can happen. Help would be much appreciated!

IRQ event thread code:

Code: Select all

THD_FUNCTION(myThread, arg) {
  (void)arg;
    chRegSetThreadName("DW1000 interrupt thread");
    trp = chThdGetSelfX();
  while (true) {

    /* Waiting for the IRQ to happen.*/
      //TODO: check correct event
    chEvtWaitAny(1);
    /* Perform processing here.*/
    dw1000_irq_event(&dw);
  }
}

void start_thd(void){

    chThdCreateStatic(mythreadwa, sizeof(mythreadwa),
                          HIGHPRIO, myThread, NULL);
}

void extcb1(EXTDriver *extp, expchannel_t channel) {
  (void)extp;
  (void)channel;
  chSysLockFromISR();
  //chThdResumeI(&trp, (msg_t)0x1337);  /* Resuming the thread.*/
  if( trp != NULL)
  {
    chEvtSignalI(trp, 1);
  }
  chSysUnlockFromISR();
}

void start_interrupt_handler(){
    // start thread to be activated by interrupt.
    start_thd();
    extStart(&EXTD1, &extcfg);
}



We suspect that the cause may be that the interrupt tries to wake/resume the thread when it has been suspended by the SPI. If this feasible and how should we prevent this?

Backtrace:

Code: Select all

(gdb) bt
#0  chSysHalt (reason=reason@entry=0x8008bf0 <__func__.6511> "chThdResumeI")
    at ../ChibiOS/os/rt/src/chsys.c:179
#1  0x08001690 in chThdResumeI (trp=trp@entry=0x200011b0 <SPID1+8>, msg=msg@entry=0)
    at ../ChibiOS/os/rt/src/chthreads.c:572
#2  0x0800530c in osalThreadResumeI (msg=0, trp=0x200011b0 <SPID1+8>)
    at ../ChibiOS/os/hal/osal/rt/osal.h:728
#3  spi_lld_serve_rx_interrupt (spip=0x200011a8 <SPID1>, flags=<optimized out>)
    at ../ChibiOS/os/hal/ports/STM32/LLD/SPIv1/spi_lld.c:149
#4  0x08003fe0 in Vector120 () at ../ChibiOS/os/hal/ports/STM32/LLD/DMAv2/stm32_dma.c:269
#5  0xffffffec in ?? ()


- Kristoffer

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: chSyshalt with reason "chThdResumeI" from SPID1

Postby Giovanni » Wed Oct 14, 2015 9:39 am

Hi,

You cannot use chThdResumeI() to wakeup a thread waiting for events. The assertion is very clear:

Code: Select all

void chThdResumeI(thread_reference_t *trp, msg_t msg) {

  if (*trp != NULL) {
    thread_t *tp = *trp;

    chDbgAssert(tp->p_state == CH_STATE_SUSPENDED,
                "not THD_STATE_SUSPENDED");

    *trp = NULL;
    tp->p_u.rdymsg = msg;
    (void) chSchReadyI(tp);
  }
}


If you use events the call to chEvtSignalI() is sufficient from the ISR, you are mixing two different mechanisms.

See this article: http://chibios.org/dokuwiki/doku.php?id ... tos:wakeup

Giovanni

totalkrill
Posts: 12
Joined: Thu Jul 09, 2015 2:21 pm

Re: chSyshalt with reason "chThdResumeI" from SPID1

Postby totalkrill » Wed Oct 14, 2015 10:16 am

I am not sure i follow, i am personally not using any chThdResumeI, to wake the thread i am only using the chEvtSignalI(trp,1) call. That is one of the reason the error is so confusing. The only mechanism i am using is the chEvtWaitAny, and the chEvtSignalI that i showed from the code. I am doing as the article shows now and added the CH_IRQ_EPILOGUE(); and CH_IRQ_EPILOGUE();. Now i get a stack overflow instead in the CH_IRQ_EPILOGUE(); instead.

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: chSyshalt with reason "chThdResumeI" from SPID1

Postby Giovanni » Wed Oct 14, 2015 10:48 am

Hi,

Your stack trace shows that it is the serial driver calling chThdResumeI() and that it is failing because the state is not the right one. The code you posted do not explain how that could happen, the problem is likely somewhere else, is the state checker enabled in chconf.h?

Giovanni

totalkrill
Posts: 12
Joined: Thu Jul 09, 2015 2:21 pm

Re: chSyshalt with reason "chThdResumeI" from SPID1

Postby totalkrill » Wed Oct 14, 2015 10:57 am

Yes the state checker is enabled.

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: chSyshalt with reason "chThdResumeI" from SPID1

Postby Giovanni » Wed Oct 14, 2015 12:37 pm

You should check for stack overflows, something gets corrupted probably.

Giovanni

chradev
Posts: 48
Joined: Sun Apr 28, 2013 6:52 am

Re: chSyshalt with reason "chThdResumeI" from SPID1

Postby chradev » Mon Feb 12, 2018 2:59 pm

Dear Kristoffer,

This thread is too old but I would like to test your DW1000 driver under latest ChibiOS.

Could you give me a permission to use your driver for DW1000: https://gitlab.com/totalkrill/dw1000-driver
and the whole project from GitLab: https://gitlab.com/totalkrill/fresknode/tree/master

Thank you in advance
Chris


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 14 guests