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:
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;
What else can we check / set?
Firmware hangs when idle thread is disabled
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Firmware hangs when idle thread is disabled
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
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
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?
Will the idle thread get starved if other threads never sleep or block?
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Firmware hangs when idle thread is disabled
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
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
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?
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?
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Firmware hangs when idle thread is disabled
Just a loop, I just tried this:
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
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
Who is online
Users browsing this forum: No registered users and 12 guests