2025-12-12 11:49 AM - edited 2025-12-15 1:34 AM
Hi!
EDIT: WARNING! This is no real fix... The bug remains...
With STM32Cube_FW_F2_V1.9.0 and CDC's /dev/ttyACM0 I had funny glitches on VoidLinux, when i tried full duplex communication (host<>device):
DeepSeek suggested to choose different endpoints for data in and out... like this:
#define CDC_IN_EP 0x81U /* EP1 for data IN */
#define CDC_OUT_EP 0x02U /* EP2 for data OUT */
#define CDC_CMD_EP 0x83U /* EP3 for CDC commands */it seems like those glitches disappeared now... Or i did not dare to test it hard enough...
Why is CDC_OUT_EP 0x01U by default, although DeepSeek thinks, that the STM32F207 hardware cannot cope with that, because IN&OUT stream share somehow the same hardware elements, if they are configured for the same endpoint?
It was easy to fix, after i found Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h , but i wonder now, if i really found the bug...
Seems like i am the only one, who had this problem... On the USB host i use 2 posix threads to read&write to /dev/ttyACM0... And on the USB device I use this:
u8 tx[7+255];
bool usbdTxIdle() {
if (udev.dev_state!=USBD_STATE_CONFIGURED) return false;
USBD_CDC_HandleTypeDef * hcdc = (USBD_CDC_HandleTypeDef*) udev.pClassData;
return hcdc && !hcdc->TxState && !hcdc->RxState;
}
u32 usbdrbx(const u32 rbt, const u32 rbf, u32 l) {
if (l==0) return 0;
if (!usbdTxIdle()) return 0;
if (l>sizeof(tx)-7) l=sizeof(tx)-7;
u64 v=((rbf<<16)|rbt); v<<=(8+16); v|=(l<<16); *(u64*)tx=v;
memcpy(tx+7,rb.b+rbf,l); // rb.b is COBS encoded with a single NUL between messages
USBD_CDC_SetTxBuffer(&udev,tx,7+l);
if (unlikely(USBD_CDC_TransmitPacket(&udev)!=USBD_OK)) return 0;
return l;
} Thx.
Bye
2025-12-15 12:54 AM
hello @RRIDDICC
I think we need to understand first how endpoint works and how they are configured.
endpoints are virtual communication channels defined by a UNIQUE address and direction used for data transfer between the USB device and host. So, two endpoints cannot share the same address and direction within the same device.
The endpoint address is an 8-bit value that contains both the endpoint number and the direction of data transfer. The format is as follows:
Endpoint numbers typically range from 1 to 15 (0 is reserved for control endpoints). The definition of endpoint numbers must respect the order of classes instantiation.
you can read this article to learn more about endpoints.
Hope that clarifies things for you
Gyessine
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.
2025-12-15 1:33 AM
hi @Gyessine
u r right...
my "fix" is no fix... the bug remains...
it still drops bytes sometimes...
should i cope with that at application layer? (maybe i could wait for a receipt for 10msec? and if it does not arrive, i resend the message? (that is how i do it with CAN...))
or should i try to find the reason, why some bytes never arrive, although i sent them?
Thx.
Bye.