USB_CDC output buffer status.

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

Moderator: RoccoMarco

Post Reply
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

USB_CDC output buffer status.

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

Re: USB_CDC output buffer status.

Post by Giovanni »

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

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: USB_CDC output buffer status.

Post by rew »

OK! How do I instruct "chprintf" to do that?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB_CDC output buffer status.

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