Page 1 of 1

FYI: ChibiOS shell on USB virtual serial (CDC ACM) on Linux needs a delay

Posted: Tue Apr 27, 2021 7:39 am
by stapelberg
Hey!

I recently took a closer look at why the ChibiOS shell prompt would often not appear correctly on the USB virtual serial device, and wrote down the individual problems that I found, and solution I settled on:

https://michael.stapelberg.ch/posts/202 ... l-cdc-acm/

This issue was reproducible across platforms (ST32, KINETIS, MIMXRT1062), and the workaround works on Linux, macOS and Windows.

Perhaps this is something to apply to the other demos that use a USB virtual serial device, too?

Hope this helps a few people :)

Re: FYI: ChibiOS shell on USB virtual serial (CDC ACM) on Linux needs a delay

Posted: Tue Apr 27, 2021 8:18 am
by Giovanni
Hi,

Good article, have you tried to exit the shell and see if it restarts? the semaphore is not necessarily signaled again.

Giovanni

Re: FYI: ChibiOS shell on USB virtual serial (CDC ACM) on Linux needs a delay

Posted: Tue Apr 27, 2021 8:30 am
by stapelberg
Giovanni wrote:Hi,

Good article, have you tried to exit the shell and see if it restarts? the semaphore is not necessarily signaled again.

Giovanni


Unfortunately, there’s another bug with exiting the shell (causes a hardfault) that I haven’t had time to look into. Until that one is fixed, I can’t test the restart scenario.

Does resetting the semaphore not signal all waiters? Is there a better way to use a semaphore, or perhaps a different primitive, in this case?

Re: FYI: ChibiOS shell on USB virtual serial (CDC ACM) on Linux needs a delay

Posted: Tue Apr 27, 2021 8:37 am
by Giovanni
stapelberg wrote:Unfortunately, there’s another bug with exiting the shell (causes a hardfault) that I haven’t had time to look into.


Is the shell susystem initialized? (calling shellInit()).

What you could do is something like this:

Code: Select all

forever
  if USB is not active then
    wait on the semaphore
  end
  spawn shell
  wait shell
  sleep a little bit
end


This way it waits on the semaphore if USB is not active, making sure it will be signaled on the next connection. Note that the Serial_USB driver has connect/disconnect events, you may try those too (CHN_CONNECTED, CHN_DISCONNECTED).

Giovanni