USB_CDC output buffer status.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

USB_CDC output buffer status.

Postby rew » Fri Feb 19, 2021 2:14 pm

I have several applications where my application on the STM32 provides an USB_CDC commandline interface to the user.

So during development I have a terminal program to type commands and see responses.

But then for "internal applications" I might want to automate something through the module I've created and "for now" I don't care about what's coming back.

I then send: "please do this, please do that" to the device, and 1) the characters are echoed back and 2) output is produced.

This tends to "lock up" the device after a while when the USB output buffer fills up: My input-processing (and echo-ing) process ends up in a "write" call that blocks.

Is there an api call that allows me to determine the status of the output buffer? If the output buffer is over say 25% full I want to stop echo-ing characters and output data. (If I do this say in the input processing thread, say after getting a new character, then I hope I don't accidentally activate this with normal interactive work: A command can still output say multiple buffers of data, and the user is unlikely to type a new command before the output buffer has been mostly cleared).

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB_CDC output buffer status.

Postby Giovanni » Fri Feb 19, 2021 2:44 pm

You could try a non blocking TIME_IMMEDIATE write or a write with a small timeout.

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: USB_CDC output buffer status.

Postby rew » Sat Feb 20, 2021 2:45 pm

OK! How do I instruct "chprintf" to do that?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB_CDC output buffer status.

Postby Giovanni » Sat Feb 20, 2021 3:07 pm

You need to create a "stream" object performing writes with timeout internally, you may use memstream as a template, then pass your object to chprintf for output.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 8 guests