Firmware hangs when idle thread is disabled

Discussions and support about ChibiOS/RT, the free embedded RTOS.
nullbert
Posts: 19
Joined: Tue Aug 30, 2016 7:12 pm
Been thanked: 1 time

Firmware hangs when idle thread is disabled

Postby nullbert » Wed Mar 25, 2020 11:11 pm

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?

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

Re: Firmware hangs when idle thread is disabled

Postby Giovanni » Thu Mar 26, 2020 7:20 am

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

nullbert
Posts: 19
Joined: Tue Aug 30, 2016 7:12 pm
Been thanked: 1 time

Re: Firmware hangs when idle thread is disabled

Postby nullbert » Thu Mar 26, 2020 7:52 am

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?

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

Re: Firmware hangs when idle thread is disabled

Postby Giovanni » Thu Mar 26, 2020 8:09 am

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

nullbert
Posts: 19
Joined: Tue Aug 30, 2016 7:12 pm
Been thanked: 1 time

Re: Firmware hangs when idle thread is disabled

Postby nullbert » Thu Mar 26, 2020 6:13 pm

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?

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

Re: Firmware hangs when idle thread is disabled

Postby Giovanni » Thu Mar 26, 2020 6:56 pm

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


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 2 guests