Page 1 of 1

USB_CDC output buffer status.

Posted: Fri Feb 19, 2021 2:14 pm
by rew
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).

Re: USB_CDC output buffer status.

Posted: Fri Feb 19, 2021 2:44 pm
by Giovanni
You could try a non blocking TIME_IMMEDIATE write or a write with a small timeout.

Giovanni

Re: USB_CDC output buffer status.

Posted: Sat Feb 20, 2021 2:45 pm
by rew
OK! How do I instruct "chprintf" to do that?

Re: USB_CDC output buffer status.

Posted: Sat Feb 20, 2021 3:07 pm
by Giovanni
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