cancel
Showing results for 
Search instead for 
Did you mean: 

VCom port, emptying buffer.

PG.1
Associate III

Hello!

Not sure it's the right place to post.

I have a custom board based on STM32F767.

I'm using USB with VCOM port to communicate by UART. Basically it works (I mean, I can receive bytes

from a terminal (I'm working on Ubuntu with STM32CubeIDE v. 1.15).

So what I do is that as soon as I receive a message, I reply with a "OK!\n" to the terminal.

1. In usbd_cdc_if.c, in the receive function is implemented like this:

static uint8_t CDC_Receice_FS(uint8 * Buf, uint32 * Len) {

USBD_CDC_SetRXBuffer(&hUsbDeviceFS, &Buf[0]);

USBD_CDC_ReceivePacket(&hUsbDeviceFS);

// Added to the code:

CDC_RxCpltCallback(Buf, *Len);

return USBD_OK;

}

2. Start the program.

Set a breakpoint in the above CDC_Recive_FS function.

If I open 2 terminals (Linux) like this:

first terminal: cat < /dev/ttyACM1

second terminal : echo cmd > /dev/ttyACM1

then as long as I don't launch the echo command, the breakpoint is not hit and the cat

command doesn't print anything.

Then if I enter anything in the first terminal, for example echo GO! > /dev/ttyACM1, then the

interrupt gets it, and if I contunue I get "OK\n" printed in the second terminal which looks normal.

But it immediately stops again at the breakpoint (although I don't echo in the first terminal).

At first stop at the breakpoint, the Buf contains "Go!" and *Len contains 3, which is the length

of "Go!". But the subsequent stops contained "\r\n" (length = 2), then "^\n!" with a length of 1,

which isn't even right.

Can anybody explain me how to get what I sent and only what I sent? Do I have to clear

some buffer or issue some kind of acknowledge to the VCom port so that it knows it has to

wait for the next data?

Thanks.

2 REPLIES 2
FBL
ST Employee

Hi @PG.1 

If still having the same issue, could you attach your project?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


PG.1
Associate III

Hello!

Thanks for your reply and sorry for the delay. I had to work on other things and months passed...

Yes, I have the same problem.

Once the connection is setup, on my first buffer send (cat something > dev/ttyAcm1), the interrupt

is triggered, and then it loops forever. So I suspect I have to reset a flag somewhere so that the input

becomes idle again, but I have no idea where it could be.

Here is the demo. I have made a completely new project with a board you certainly have in your lab,

the nucleo 767.

So basically you just build it and launch the debugger to run it.

Open a terminal, run cat < /dev/ttyACM0 (or whatever port it connects to)

Open another terminal, run echo "Hello" > /dev/ttyACM0

You will hit the breakpoint at CDC_receive_FS in usbd_cdc_if.c which is normal.

Then press continue. The receiving terminal (with the cat command) will echo a string, and the command

CDC_receive_FS will be called again although the echo command is finished.

Question: how to call the CDC_Receive_FS only once when something was sent by cat, and then return

to the idle mode and wait for the next command.

Thanks for any hint!

PG