Debug best practice
Posted: 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
thread_reference_t powerButtonThread;
Button press handler
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();
}