Page 1 of 1

Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 5:28 pm
by Korken
Hi all!

I have always had something like a blinking LED in the while-loop in main, but now it was time to remove this.
So I just have an while(1) loop with nothing in it.
The thing is, when I do this the USB stops working (even if I disable the Idle thread).

So the first question is, why does it stop working?
As the while(1) loop is not a thread it should not congest the USB data pump thread.

Second question, what should you have in the loop to not have this problem?
I can't find any example for this.

Thanks in advance!

Best Regards
Emil

Re: Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 7:18 pm
by Giovanni
Hi,

The main() function IS a thread with priority NORMALPRIO so it do congest the USB pump thread. This is why all demos have chThdSleep() calls in the main() loop. It is not like the micro has another CPU just for the main.

Giovanni

Re: Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 7:37 pm
by Korken
Aha! I must have misunderstood the usage of the main loop.
I had understood that as being the Idle thread, but then it must be running somewhere else (maybe only accessible from the idle hook?).

But thanks for the clarification Giovanni! Now it is perfectly clear. :)

Re: Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 7:43 pm
by Giovanni
By default it is a normal thread in RT, there is an OPTION to make it the idle thread, in that case the empty loop is OK.

I recommend the default settings.

Giovanni

Re: Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 7:59 pm
by Korken
Thanks for the clarification!
But what is the default? chconf.h only has:

Code: Select all

/**
 * @brief   Idle thread automatic spawn suppression.
 * @details When this option is activated the function @p chSysInit()
 *          does not spawn the idle thread. The application @p main()
 *          function becomes the idle thread and must implement an
 *          infinite loop. */
#define CH_CFG_NO_IDLE_THREAD               FALSE

Re: Nothing in idle, blocks USB?

Posted: Thu Mar 26, 2015 8:07 pm
by Giovanni
The default is FALSE and means that main() is a normal thread.

Giovanni