Page 1 of 1
Firmware hangs when idle thread is disabled
Posted: Wed Mar 25, 2020 11:11 pm
by nullbert
Hello,
For our application (STM32f042) we want to disable the idle thread to save flash space.
When we disable it via chconf.h, our firmware hangs (never starts up).
Our main() implements an infinite loop, like so:
[font=Courier New]while (true) {
chThdSleepMilliseconds(MAIN_THREAD_CHECK_INTERVAL_MS); //1000 ms
stats_check += MAIN_THREAD_CHECK_INTERVAL_MS;
if (stats_check > MAIN_THREAD_SLEEP_NORMAL_MS) {
/* TODO re-enable this when we have safe I2C / CAN simultaneous operation */
broadcast_stats();
stats_check = 0;
}
check_system_state();
}
return 0;[/font]
What else can we check / set?
Re: Firmware hangs when idle thread is disabled
Posted: Thu Mar 26, 2020 7:20 am
by Giovanni
Hi,
If you disable the idle thread then the main() becomes the idle thread, you cannot call any function that changes the thread state from there like that chThdSleepMilliseconds().
If you need delays there then you can implement a polled delay on the system time counter.
Giovanni
Re: Firmware hangs when idle thread is disabled
Posted: Thu Mar 26, 2020 7:52 am
by nullbert
Thank you. I assume you mean allow the thread to run at maximum speed, since it is now the idle thread and will run at a lower priority than other threads.
Will the idle thread get starved if other threads never sleep or block?
Re: Firmware hangs when idle thread is disabled
Posted: Thu Mar 26, 2020 8:09 am
by Giovanni
Hi,
Threads not releasing CPU (not sleeping) block lower priority threads.
The general rule is: the thread in execution is always the ready one with highest priority.
Giovanni
Re: Firmware hangs when idle thread is disabled
Posted: Thu Mar 26, 2020 6:13 pm
by nullbert
Thanks.
So, I changed the main() loop to a simple infinite loop and the firmware still hangs.
What should the main() implement besides a simple infinite loop?
Re: Firmware hangs when idle thread is disabled
Posted: Thu Mar 26, 2020 6:56 pm
by Giovanni
Just a loop, I just tried this:
Code: Select all
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/*
* Activates the serial driver 3 using the driver default configuration.
*/
sdStart(&LPSD1, NULL);
/*
* Creates the example thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
/*
* Idle loop.
*/
while (true) {
}
}
Enable assertions, checks and state checker in chconf.h and see if something is caught. Make sure you don't have some other state-changing code in the main.
Giovanni