Debug best practice

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

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

nonameletters
Posts: 7
Joined: Fri Aug 25, 2017 1:07 pm

Debug best practice

Postby nonameletters » Mon Oct 02, 2017 8:48 am

Hello. I am using a thread to handle button press interrupt EXTI on STM MCU.
The thread wakes up when button pressed and goes sleep after it finishes. But some times it enters in undefined state. What is the best practice to do this and debug.
This is thread

Code: Select all

static THD_WORKING_AREA(waButtonPowerThread, 256);
static __attribute__((noreturn)) THD_FUNCTION(ButtonPowerThread, arg)
{
    (void)arg;
    chRegSetThreadName("ButtonPowerThread");

   BaseSequentialStream *outChannel2 = shell_cfg1.sc_channel;

   chSysLock();
   for(;;)
   {
         chThdSuspendTimeoutS(&powerButtonThread, TIME_INFINITE);
      chSysUnlock();
         chprintf(outChannel2, " Power on was pressed \r\n");
         idtOnOff();
         powerToggle();
      chSysLock();
   }
}


thread_reference_t powerButtonThread;

Button press handler

Code: Select all

static void btn_do(void *arg)
{
  (void)arg;

  chSysLockFromISR();
     if (powerButtonThread != NULL)
     {
        chThdResumeI(&powerButtonThread, MSG_OK);
     }
     else
     {
        powerButtonThreadNullCount++;
     }

  chSysUnlockFromISR();

}

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: Debug best practice

Postby Giovanni » Mon Oct 02, 2017 9:48 am

Hi,

You should define this undefined state :) is the thread suspended, crashed or something else?

Try to look at the threads state and the trace buffer using the ChibiStudio debug plugin plugin.

Also make sure to enable the usual debug options: assertions, checks, state checker.

Giovanni

nonameletters
Posts: 7
Joined: Fri Aug 25, 2017 1:07 pm

Re: Debug best practice

Postby nonameletters » Mon Oct 02, 2017 10:28 am

I noticed that powerButtonThread becomes NULL. Interrupt handler works fine. Pressing button I enter into handler, and when I check powerButtonThread it is NULL. This is global variable. It is used to control thread. I check its usage. Only 3 place where it used:
1. Defenition
2. Thread to enter suspend mode
3. Button handler to wake up thread

How can I guaranty the atomicity of thread?

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: Debug best practice

Postby Giovanni » Mon Oct 02, 2017 10:41 am

If that variable is not NULL then the thread is not suspended but stuck/looping/waiting in some other place, you need to focus on that.

Giovanni

nonameletters
Posts: 7
Joined: Fri Aug 25, 2017 1:07 pm

Re: Debug best practice

Postby nonameletters » Tue Oct 03, 2017 9:06 am

I have a strange scheduler behavior.
2 threads. first blinker with NORMALPRIO. Second Message Box listener with NORMALPRIO+1. Second listens button presses. After some period second thread doesn't get execution. When I pressing button interrupt happens. In debugger I see that I don't enter thread. But if I send some thing in CLI thread starts execute and I see all messages.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 17 guests