Nothing in idle, blocks USB?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Nothing in idle, blocks USB?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Nothing in idle, blocks USB?

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Nothing in idle, blocks USB?

Post 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. :)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Nothing in idle, blocks USB?

Post 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
User avatar
Korken
Posts: 270
Joined: Wed Apr 02, 2014 4:09 pm
Has thanked: 5 times
Been thanked: 6 times

Re: Nothing in idle, blocks USB?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Nothing in idle, blocks USB?

Post by Giovanni »

The default is FALSE and means that main() is a normal thread.

Giovanni
Post Reply