Debugging Mailboxes ChibiOS

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Debugging Mailboxes ChibiOS

Postby BMWPower » Sat Aug 26, 2017 1:19 am

Hi all,

I have some sensors who are read by ChibiOS and every sensor is Posting messages. This every 24 seconds. All seems to work well, but after some hours then the mailbox is going into "idle". So the STM is still working (heartbeat led), but the mailboxes seem to go into idle.

How could I best debug this? To find out what is going on?

I am using the GNU-ARM Toolchain (GCC).

Thanks

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Debugging Mailboxes ChibiOS

Postby Giovanni » Sat Aug 26, 2017 6:46 am

Hi,

What version are you using? mailboxes have been rewritten recently?

Also, try to describe what "idle" is, is the mailbox that stops working or the thread that stops fetching from the mailbox? do you have debug options enabled?

Giovanni

BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Debugging Mailboxes ChibiOS

Postby BMWPower » Sat Aug 26, 2017 9:53 pm

I am using: ChibiOS_16.1.6 --> transformation to ChibiOS_17.6.0 is planned, but has some impact.

The STM, in gdb (GNU-ARM Tool STM on Linux), is is telling me that the STM is in idle state (esp8266.c thread)

The code I am using is (esp8266.c):
Code in Pastebin

BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Debugging Mailboxes ChibiOS

Postby BMWPower » Sat Aug 26, 2017 9:59 pm

In gdb:

_idle_thread.lto_priv.69 (p=0x0) at ../../../os/rt/src/chsys.c:65
65 static void _idle_thread(void *p) {

BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Debugging Mailboxes ChibiOS

Postby BMWPower » Tue Aug 29, 2017 12:25 am

I have got ChibiOS Studio working with gdb and openocd. If i "suspend" it will take me in Tread#1

_idle_thread.lto_priv.78() at chsys.c:65 0x8001eb0 --> static void _idle_thread(void *p) in chsys.65

I do not have and variable ch.dbg.panic_msg with a value SV#X

I will keep on searching.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Debugging Mailboxes ChibiOS

Postby Giovanni » Tue Aug 29, 2017 7:19 am

Hi,

If it is in the idle thread then the application is running. Probably your problem is that some thread is stuck posting/fetching the mailbox because the other side is not posting/fetching so the queue stays full or empty.

Giovanni

BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Debugging Mailboxes ChibiOS

Postby BMWPower » Sat Sep 02, 2017 4:58 pm

Oke tried everything I can think of. When I implement 2 Threads which are posting and I use no timers or delays. It all seems wel.... seems. But when I put some delays in (because every Thread is representing a sensor) all is going fault. The chMBFetch seems to be the problem.

I expect that the chMBFetch Thread is waiting (even when the queue is empty) for a message to be posted. But it seems like it is going into idle...

This cannot be this difficult..... or are mailboxes not for this purpose? So it seems to work, but I want to put some delays into the Threads ... how can I achieve this?

code Thread1 posting:

Code: Select all

/* The thread continuous which is reading the sensor values and is posting a message in the mailbox */
static THD_WORKING_AREA(waPOSTMESSAGETOMBTEMP, 512);
static THD_FUNCTION(POSTMESSAGETOMBTEMP, arg)
{
   (void)arg;

   static char charbuf;
    chRegSetThreadName("GETMESSAGEFROMSENSORTEMP");

   systime_t time = chVTGetSystemTimeX(); // T0
   time += MS2ST(500);

    while(true) {

      msg_t msg, result;
      
      //chprintf((BaseSequentialStream*)&SD6,"print('GMState Thread 2: %d')\r\n",esp_state);
      //chThdSleepMilliseconds(100);
      
      DSMessage dsmi = {};

      dsmi.state = 26;
      dsmi.url = "http://io.adafruit.com/api/v2/url/feeds/cabinet.temperature/data";
         
      chMBPost(&msgs, (msg_t) &dsmi, MS2ST(10));

      
      chThdYield();
      //chThdSleepUntil(time);
   }
}


Thread 2:

Code: Select all

/* The thread continuous which is reading the sensor values and is posting a message in the mailbox */

static THD_WORKING_AREA(waPOSTMESSAGETOMBHUM, 512);
static THD_FUNCTION(POSTMESSAGETOMBHUM, arg)
{
   (void)arg;

   static char charbuf;
    chRegSetThreadName("GETMESSAGEFROMSENSORHUM");

   systime_t time = chVTGetSystemTimeX(); // T0
   time += MS2ST(200);;

    while(true) {

      msg_t msg, result;
      
      //chprintf((BaseSequentialStream*)&SD6,"print('GMState Thread 3: %d')\r\n",esp_state);
      //chThdSleepMilliseconds(100);
      
      DSMessage dsm = {};
      
      dsm.state = 62;
      dsm.url = "http://io.adafruit.com/api/v2/url/feeds/cabinet.humidity/data";
      
      chMBPost(&msgs, (msg_t) &dsm, MS2ST(10));
      chThdYield();

      //chThdSleepUntil(time);
            
   }
}


And Fetch Thread:

Code: Select all

/* The thread continuous which is fetching a message */
static THD_WORKING_AREA(waGETMESSAGEFROMMB, 512);
static THD_FUNCTION(GETMESSAGEFROMMB, arg)
{
   (void)arg;
    chRegSetThreadName("GETMESSAGE");
    systime_t time = chVTGetSystemTimeX(); // T0

   msg_t current_message;
      
   /* Waiting for a message.*/

   chprintf((BaseSequentialStream*)&SD6,"print('GMState: %d')\r\n",esp_state);
   chThdSleepMilliseconds(100);
   
   //time += S2ST(5);
   
   while(TRUE) {
      msg_t msg, result;
      //The ampersand & symbol should be read as "the address of..". The star *
      //symbol should be read as "the contents of the address...".
        //[A] result = chMBFetch(&msgs, (msg_t *)&msg,TIME_INFINITE);
      //result = chMBFetch(&msgs, (msg_t *)&msg ,TIME_IMMEDIATE);
      while(chMBFetch(&msgs, (msg_t *)&msg, MS2ST(1))!= MSG_OK);
      
      
         
        //if(msg & 1)
        chprintf((BaseSequentialStream*)&SD6,"print('Inside loop %d')\r\n",((DSMessage *)msg)->state);
      chThdSleepMilliseconds(100);
      chprintf((BaseSequentialStream*)&SD6,"print('Inside loop %s')\r\n",((DSMessage *)msg)->url);
      chThdSleepMilliseconds(100);

      chThdYield();
      //chThdSleepUntil(time);
    }
}      
   

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Debugging Mailboxes ChibiOS

Postby Giovanni » Sat Sep 02, 2017 5:38 pm

Because your use timeouts your threads can use the CPU without releasing it because stuck in an infinite while, this can cause other threads to never execute leading to deadlock.

Giovanni

BMWPower
Posts: 24
Joined: Mon Oct 24, 2016 10:27 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Debugging Mailboxes ChibiOS

Postby BMWPower » Sat Sep 02, 2017 11:42 pm

What could I use instead of timeouts?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Debugging Mailboxes ChibiOS

Postby Giovanni » Sun Sep 03, 2017 11:18 am

TIME_INFINITE, it means no timeouts.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 55 guests