USB-CDC threading question

For some reason I can't get around a USB problem.  I've cloned the example where LEDs on the S5D9 board are selectively toggled using the host keyboard input and results sent back to terminal emulator.

Basically this code works like:
while (1) /  read USB  /  switch on received byte  /  execute code under switch option

And that works fine.  The problem occurs when I try to add another thread.  If the read-usb thread has a higher priority then the new-thread never executes, presumably because the while(1) loop.  Adding a thread_sleep at the end didn't help (Q: does thread_sleep allow lower priority threads to fire off?).  If I make new-thread a higher priority, then it tends to operate most of the time and read-usb thread doesn't run.

I tried to fix this by adding a timer and putting the read-usb code in a callback routine, but then the read-usb only occurs if it runs at the same time an input byte appears (basically if I hold down the key on keyboard).

What I'm trying to achieve here is to check the USB 2 to 4 times per second and otherwise monitor other inputs and send messages over USB as needed, or ideally run an interrupt when a minimum number of bytes are received (not just when there are incoming bytes).  Perhaps I'm missing some subtlety regarding threading and/or USB... anyway, ideas appreciated on this problem.

  • Hi cam,

    Yes, suspending factors like sleeping (tx_thread_sleep) allows other threads (also those of lower priorities) to be fired off. Have you requested the thread to sleep for one tick or more? This is important, because ThreadX can wake up threads up to one tick earlier, so tx_thread_sleep(1) can return immediately.

    I'm also not sure which example project you're referring to, could you provide a link?

    Regards,
    adboc
  • In reply to adboc:

    Thanks for reply.
    I had a tx_thread_sleep(100) in there but need to re-test this as I also had a timed ADC acquisition running on the same thread that I neglected to turn off.

    The example is:
    www.renesas.com/.../r11an0136eu0100-synergy-sf-el-ux-comms-mod-guide.pdf
  • In reply to cam:

    Hi cam,

    You can use RTOS Resource tab to verify run counts of each thread.

    To enable this tab, please suspend the application and select Renesas Views > Partner OS > RTOS Resources. Confirm you use ThreadX and resume the application. Next time you suspend the app it will show filled tables.

    Regards,
    adboc