ekawahyu wrote:@Vassilis: I can see that the USBSerial has RX (and potentially TX) buffers, but I also see that usb_cdc_if.c has both RX and TX buffers declared instead of pointing to the USBSerial's. What is your plan with this? Which one you would get rid of?
Well, the usb_cdc_if.c
uses its own rx and tx buffers for each incoming/out-coming data batch. That means, if you send 4 bytes from your serial terminal to the STM32 those bytes will be written into the UserRxBufferFS[APP_RX_DATA_SIZE]
buffer. If you send another 4 after a time period (for example 1 second) the previous 4 bytes will be overwritten by the new bytes.
For that reason you need a second buffer (ring_buffer rx_buffer
) to write every unread incoming byte up to the size of the second buffer.
The same principles exist to the txbuffer that I have not finished yet.
You will say, why you use 128 bytes for the first buffer (UserRxBufferFS[APP_RX_DATA_SIZE]
) and 128 for the second buffer (rx_buffer
The answer is that the USB needs a big enough buffer to receive one data batch. For example, if you send 32 bytes from your serial terminal and the UserRxBufferFS buffer has only 4 bytes length (CubeMX default value), then the STM32 will be stuck.
In programming there are many ways to do the same thing. As a start I chose to use that way (2 buffers). If you have another solution, a more efficient approach, we can talk about it. The solution must include the tx buffer that has not been implemented yet.