Safe chprintf outside shell loop

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Safe chprintf outside shell loop

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Safe chprintf outside shell loop

Post by Giovanni »

Could it be a stack overflow problem there? try enabling debug options in chconf.h.

Giovanni
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Re: Safe chprintf outside shell loop

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Safe chprintf outside shell loop

Post 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
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Re: Safe chprintf outside shell loop

Post by kab »

removed my stupid code
Post Reply