2024-04-07 06:11 PM - last edited on 2024-04-08 12:46 AM by Peter BENSCH
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.