Electronic – How to design an STM32 board with UART over a USB connection

microcontrollerpcbstm32uartusb

Sorry if this seems a stupid question but I'm designing a custom PCB based on the STM32F303RE microcontroller and am slightly confused as to how the UART should be connected in the hardware in order to communicate via serial over USB.

I have a microUSB connector on board, should the UART pins be connected directly to this connector? Or do I need to use the USB pins on the STM32 and set up the micro controller as a USB device and connect the UART to these pins somehow (or not use them at all)?

I started with a Nucleo board for development and can communicate via UART on there (using HAL UART functions) but looking at the schematic is confusing due to the on-board ST-LINK. As far as I can see, the UART signal of the STM32 is passed to the UART pins of the ST-LINK MCU and the USB pins of the ST-LINK MCU are connected to the MicroUSB port but I'm not sure how the data is passed through? Is it in fact using the USB HAL functions to convert the received UART data?

Best Answer

You can't connect the UART Rx/Tx directly to the DP/DN signals on the USB connector.

You basically have two options:

  1. Add software to your application to use the USB peripheral on your STM32 to implement a virtual COM port. ST has some example projects for this, so it isn't terribly difficult, but will likely take some software time to implement. I think there is example software here: https://www.st.com/en/embedded-software/stsw-stm32121.html. In this case, you would wire the USB pins on the STM32 to the USB connector.

  2. You can buy a chip to provide a USB-to-UART bridge. FTDI makes several versions of this, such as this one: https://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT230X.pdf

    This requires an extra chip, but it is probably the easier option to get working. In this case, you would wire the UART pins to the Rx/Tx pins of the FTDI chip, and then wire the USB pair on the FTDI chip to the USB connector.

  3. I guess there is an option 3, as well. You could buy a USB to TTL UART cable and connect this to your board, instead of putting the USB connector on your board, if you wanted to get as simple as possible with both software and the PCB design. FTDI cable assemblies: https://www.ftdichip.com/Products/Cables/USBTTLSerial.htm.

Related Topic