2017-08-07 11:40 AM
I have created a simple project in cubemx, with usb fs device (CDC).
But i see an strange behavior: The buffer of CDC_Receive_FS contains (bytes sent from PC + 1 extra byte)
On example, when sending 0x32 0x33 in buffer i got 0x32 0x33 0xee
0x32 0x34 -> 0x32 0x34 0xaf
0x32 0x35 -> 0x32 0x35 0x6e
etc..
Why can this happen?
2017-08-07 04:03 PM
Hello !!
The CDC_Receive_FS function you mention, is called from lower layers and contains as parameter a pointer to received length.
Is this received *length equal to 3? or as you wrote before , just contained in buffer?
Your hardware is unknown to us, provide some information about it
2017-08-07 09:48 PM
MCU is STM32F103R8T6
UserRxBufferFS size is 64
USB_OTG_MAX_EP0_SIZE is 64
USB_OTG_FS_MAX_PACKET_SIZE is 64
Received *Len contains ''5'', but *Buf contains 6 bytes.
With even number of bytes there is no problems:
1 byte sent, 2 bytes in buffer, Len is 1
2 bytes sent, 2 bytes in buffer, Len is 2 == OK3 bytes sent, 4 bytes in buffer, Len is 34 bytes sent, 4 bytes in buffer, Len is 4== OK
5 bytes sent, 6 bytes in buffer, Len is 56 bytes sent, 6 bytes in buffer, Len is 6== OK
7 bytes sent, 8 bytes in buffer, Len is 78 bytes sent, 8 bytes in buffer, Len is 8== OK
9 bytes sent, 10 bytes in buffer, Len is 910 bytes sent, 10 bytes in buffer, len is 10== OK
2017-08-08 06:35 AM
Hello again!!
You wrote... '1 byte sent, 2 bytes in buffer, Len is 1
2 bytes sent, 2 bytes in buffer, Len is 2 == OK3 bytes sent, 4 bytes in buffer, Len is 3'Two bytes in a 64 byte size buffer means nothing. the (buffer allways contains 64 bytes)
Usually the buffers has as initial values per byte ,0x00
With a 'normal' debuger is posible to see oly the bytes>0x20 . But this does not mean that the rest bytes don't exist.
The internal structure of USB CDC modules is 'unknown' to the highest layer user.
The knowledge of the user must be , only , the number of bytes received and the buffer pointer to take theese determined bytes. The remaining of the buffer is not guaranteed to conforms with something determined or not.
So, this the normal behaviour of this callback function.