AnsweredAssumed Answered

STM32F4 USB CDC Communication transfers only specific characters without noise?

Question asked by Orhan on Aug 1, 2016
Latest reply on Aug 2, 2016 by Orhan

I'm working with STM32F407VET6 board. And I'm trying to make communication 
between my PC and Micro Controller via sample which transmits what it receives 
through USB. I've created USB Device example via STM32CubeMX 
Version 4.16.0 and FW_F4 1.13.0.

My problem is very fantastic and I don't know how to google it. I'm using;

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) 
and
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) 
functions.

I'm listening outputs from /dev/ttyACM0 via CuteCom. 
Also, sending commands through it. If I put some string to buffer,
it doesn't send without noise. But it sends this caharacters correctly(!):


DEC   OCT    HEX    BINARY   CHARACTER   DESCRIPTION
-------------------------------------------------------
63    077    3F    00111111      ?       Question Mark
71    107    47    01000111      G       Uppercase G
75    113    4B    01001011      K       Uppercase K
83    123    53    01010011      S       Uppercase S
99    143    63    01100011      c       Lowercase c
111   157    6F    01101111      o       Lowercase o
119   167    77    01110111      w       Lowercase w

Also I read this characters on buffer if the string which I sent via CuteCom 
ends with one of them. If I only listen port, doesn't send anything,
first string is changing and turns to tilde(
~) character after several 
transmits. Here, I'm starting application, waiting, and sending string 
in order of: 
"w""c""asdfw""a""b""c""G" :

USB_Tx_buf: STRING_OF_TRANSMIT_BUFFER
USB_Rx_buf: STRING_OF_RECEIVE_BUFFER
-----------------------------------
USB_Tx_buf: E�L
USB_Rx_buf: 1�k
-----------------------------------
USB_Tx_buf: 0@�
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: A��
USB_Rx_buf: TA@
-----------------------------------
USB_Tx_buf:  Ag
USB_Rx_buf: E�L
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: A��
-----------------------------------
USB_Tx_buf: E�L
USB_Rx_buf: 1�k
-----------------------------------
USB_Tx_buf: 0@�
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: 
�z
USB_Rx_buf: 
�z
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: ~
-----------------------------------
USB_Tx_buf: ~
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: c
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: c
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: c
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: w
-----------------------------------
USB_Tx_buf: w
USB_Rx_buf: a�Wc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: a�Wc~���CEIVE_BUFFER
USB_Rx_buf: a�Wc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: a�Wc~���CEIVE_BUFFER
USB_Rx_buf: a�Wc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: b�Vc~���CEIVE_BUFFER
USB_Rx_buf: b�Vc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: b�Vc~���CEIVE_BUFFER
USB_Rx_buf: b�Vc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: b�Vc~���CEIVE_BUFFER
USB_Rx_buf: b�Vc~���CEIVE_BUFFER
-----------------------------------
USB_Tx_buf: b�Vc~���CEIVE_BUFFER
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: c
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: c
USB_Rx_buf: c
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
-----------------------------------
USB_Tx_buf: G
USB_Rx_buf: G
...


And here is communication part of code:

...
 
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();
 
/* USER CODE BEGIN startUSBTask */
uint8_t USB_TX_buf[MAX_COMMAND_STR_SIZE];
sprintf ( ( char * ) USB_TX_buf, "STRING_OF_TRANSMIT_BUFFER\r" );
sprintf ( USB_RX_BUF, "STRING_OF_RECEIVE_BUFFER" );
/* Infinite loop */
for ( ;; )
{
    CDC_Transmit_FS ( USB_TX_buf, ( uint16_t ) strlen ( ( char * ) USB_TX_buf ) );
    osDelay ( 10 );
    if (DEBUG) printf ( "USB_TX_buf: %s\nUSB_Rx_buf: %s\n", ( char * ) USB_TX_buf, USB_RX_BUF );
      if (DEBUG)printf("-----------------------------------\n");
}
/* USER CODE END startUSBTask */
...
Here is some lines of usbd_cdc_if.c, 84 to 89:
/* Received Data over USB are stored in this buffer       */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
char USB_RX_BUF[APP_RX_DATA_SIZE];
 
/* Send Data over USB CDC are stored in this buffer       */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
251 to 262:
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
    /* USER CODE BEGIN 6 */
    USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
    USBD_CDC_ReceivePacket(&hUsbDeviceFS);
    sprintf(USB_RX_BUF, (char*)Buf);
    return (USBD_OK);
    /* USER CODE END 6 */
}
Where should I look for solution? Or How can i search it on Google?


Outcomes