STM32 Serial Communication
STM32 micros just like any other micro provide hardware for serial communication. As we all know serial communication is a very important tool for debugging, connecting with external hardware like RFID, GPS, GSM modems, etc. and for performing other communication-related tasks. STM32s have several hardware serial (USART) ports. The number of ports available in a STM32 micro is dependent on device family type and the device itself. Typically there are at least 5 serial ports. Apart from the basic serial communication needs, STM32’s USART hardware also have support for LIN, one-wire, smart card protocols, SPI and IrDA. We can even utilize STM32’s DMA controller with USART hardware to achieve high speed automated data communication. Thus these hardware are truly universal synchronous-asynchronous receiver-transmitters.
In any standard serial communication, we need three wires – TX, RX and GND. TX pin is an output pin and transmits data serially to another device’s RX pin. RX pin is an input pin and is responsible for receiving data from another device’s TX pin. The two devices connected in this way must have same ground (GND). There are other pins like CTS and RTS which are used for hardware flow control. Additionally there’s also another pin called CK. It is transmitter’s clock output and used usually in SPI and other modes.
Depending on package, USART pins are arranged in the following pattern:
BGA100 | LQFP100 | LQFP48 | LQFP64 | Pin Name | USART/UART |
D9 | 67 | 29 | 41 | PA8 | USART1_CK |
C10 | 70 | 32 | 44 | PA11 | USART1_CTS |
B10 | 71 | 33 | 45 | PA12 | USART1_RTS |
C9 | 68 | 30 | 42 | PA9 | USART1_TX |
D10 | 69 | 31 | 43 | PA10 | USART1_RX |
G3 | 29 | 14 | 20 | PA4 | USART2_CK |
G2 | 23 | 10 | 14 | PA0 | USART2_CTS |
H2 | 24 | 11 | 15 | PA1 | USART2_RTS |
J2 | 25 | 12 | 16 | PA2 | USART2_TX |
K2 | 26 | 13 | 17 | PA3 | USART2_RX |
K8 | 51 | 25 | 33 | PB12 | USART3_CK |
J8 | 52 | 26 | 34 | PB13 | USART3_CTS |
H8 | 53 | 27 | 35 | PB14 | USART3_RTS |
J7 | 47 | 21 | 29 | PB10 | USART3_TX |
K7 | 48 | 22 | 30 | PB11 | USART3_RX |
B8 | 79 | – | 52 | PC11 | UART4_RX |
B9 | 78 | – | 51 | PC10 | UART4_TX |
B7 | 83 | 54 | PD2 | UART5_RX | |
C8 | 80 | – | 53 | PC12 | UART5_TX |
Personally I’m interested in LQFP packages, particularly 48 and 64 packages as they are mostly used in the most common STM32 development boards. I suggest locating USART/UART pins before working with them.