1
\$\begingroup\$

I generated USB VCP code for "STM32F103C8T6" with STM32CubeMX. I'm trying to send received data by STM from PC, to an Arduino board using UART. The code works good for data with little size, but when I want to send bigger data the received data in Arduino is corrupted. I'm using "Teraterm" and "Realterm" for sending data from PC to STM32. I modified the CDC_Receive_FS for sending data via UART in DMA mode, here is the code:

static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{

    HAL_UART_Transmit_DMA(&huart3, Buf,(uint16_t)* Len);/* same problem with HAL_UART_Transmit_IT*/ 
    USBD_CDC_ReceivePacket(hUsbDevice_0);//Getting ready for receiving next data
    return (USBD_OK);

}

I sent this

{1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40}

and received

{1 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 20 21 22 23 24 2}

The USART baud rate is 19200, and in STM32, size of Received buffer, APP_RX_DATA_SIZE is defined 640. What should I do?

\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

when you use uart dma or interrupt version it is not blocking , the uart function return straight away before data fully send So it happen that you get ready to receive new data from usb before previous sent on uart . As you use same buffer for usb rx and uart tx usb will start refiling buffer as it still getting send by uart (why you miss things).

if to use dma or it then handle the completion callback to restart usb reception or implement a more elaborated fifo/buffer in between usb and uart to bufferiez incoming data as it get sent.

\$\endgroup\$
2
  • \$\begingroup\$ You are right. I found this "HAL_UART_TxCpltCallback" for end of transfer in DMA mode, but couldn't make it work. Do you have any suggestion how to modify it? \$\endgroup\$
    – Mehran
    Commented Nov 23, 2016 at 7:46
  • \$\begingroup\$ Sorry but theirs not a single answer here it can be quite complicated . it's up to you to organize the it suite your app and need. \$\endgroup\$ Commented Nov 23, 2016 at 9:58
2
\$\begingroup\$

I used "HAL_UART_Transmit" for sending and it's working good but don't know what is wrong with "HAL_UART_Transmit_DMA" and "HAL_UART_Transmit_IT".

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.