Page 1 of 1

Safe chprintf outside shell loop

Posted: Sun Apr 06, 2014 4:17 pm
by kab
hiya!

I have a problem with chprintf function which crash shell thread.
I have casual shell thread (like in USB-CDC example) and normal thread:

Code: Select all

static WORKING_AREA(waMsgThread, 128);
static msg_t mMsgThread(void *arg) {

  (void)arg;
  Thread *t;
  msg_t msg;
  packet_t pkt;
  char buf[6];

  chRegSetThreadName("MsgProc");
  while (TRUE)
  {
     t=chMsgWait();
     msg = chMsgGet(t);
     memcpy(&pkt, (void *)msg, sizeof(packet_t));
     chMsgRelease(t, msg);

     if (shelltp)
     {
        chprintf((BaseSequentialStream *)&SDU1, "....");
                  ... a lot of chprintf here ...
     }
  }
}


If i disable chprintf - all working fine, but i need to do output to USB console outside shell thread.
What i do wrong? May be some kind of lock required to notify system shell thread to suspend any action?

Re: Safe chprintf outside shell loop

Posted: Sun Apr 06, 2014 6:07 pm
by Giovanni
Could it be a stack overflow problem there? try enabling debug options in chconf.h.

Giovanni

Re: Safe chprintf outside shell loop

Posted: Sun Apr 06, 2014 7:30 pm
by kab
Seems that you absolutely correct!
I've increased stack space and problem is gone.

Thanks a lot!

p.s. How to detect stack problems in future? Debug checks in chconf.h is set. Set breakpoint to what function? Is there some special function which got control when stack overflow detected?

Re: Safe chprintf outside shell loop

Posted: Sun Apr 06, 2014 7:57 pm
by Giovanni
The ChibiOS debug plugin for Eclipse (included in ChibiStudio) allows to measure the actual stack usage, without that you have to inspect the memory and measure it (in both cases you need to use the stack-filling option in chconf.h).

Giovanni

Re: Safe chprintf outside shell loop

Posted: Mon Apr 07, 2014 5:42 pm
by kab
removed my stupid code