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

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
stapelberg
Posts: 10
Joined: Wed Jun 03, 2020 9:17 pm
Has thanked: 4 times
Been thanked: 3 times

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

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

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

Post 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
stapelberg
Posts: 10
Joined: Wed Jun 03, 2020 9:17 pm
Has thanked: 4 times
Been thanked: 3 times

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

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

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

Post 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
Post Reply