cancel
Showing results for 
Search instead for 
Did you mean: 

USE MCU LIKE PL2303A

arduo
Senior

Hi everyone!

How can i use my MCU STM32F407IG like a PL2303 FTDI. Like basically how can i use my mcu as a usb to uart converter? I already worked with the usb device cdc example and i send data to uart tx everything is fine an working but somehow what is working with my pl2303 is not with the mcu. What do i need to implement in my mcu code to make it work exactly like a pl2303?

6 REPLIES 6

What does working vs not working mean in this context?

The USB CDC/VCP delivers blocks of data for you to process. You need to adapt your methodology to handle data differently, using buffers and code that doesn't block in callback/interrupt context.​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

I use HAL_Transmit_DMA for transmitting every byte that is send over COM Port. I have connected another chip (HD64F2166) with rx and tx and the communication between MCU and the Chips doesnt work over USB FS but works over USB to UART with PL2303A that's my issue now. Do i have to change the example of the buffer method for transmitting data?

If that function blocks, I could see it failing, the CDC/VCP can also deliver multiple bytes. ​

I would use buffering so as not to stall real-time operation of USB​.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len)
{
 
	HAL_UART_Transmit_DMA(&UartHandle, Buf, *Len);
	//HAL_UART_Receive_DMA(&UartHandle,x Buf, *Len);
	CDC_Transmit_FS(Buf, *Len);
 
  return (USBD_OK);
}

That is my function and i am using the standard example cdc standalone usb device

HAL_UART_Transmit_DMA doesn't block, but you don't check for errors, nor handle the sequencing/completion.

It also pays no attention to the lifespan of the buffer, which one should assume vapourizers once the function returns, or at the very least assume is volatile.

If you have a lot of data you want going out a USART, queue it in a buffer, and manage dispatch in the USART IRQ handler.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Ok thanks another thing:

How can i transmit the data received over my UART RX Pin to vcp?