20. Universal synchronous asynchronous receiver transmitter (USART)

20.1 USART introduction

The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format. The USART offers a very wide range of baud rates using a fractional baud rate generator.

It supports synchronous one-way communication and half-duplex single-wire communication. It also supports the LIN (local interconnection network), smartcard protocol and IrDA (infrared data association) SIR ENDEC specifications, and modem operations (CTS/RTS). It also supports multiprocessor communications.

High speed data communication is possible by using the DMA (direct memory access) for multi-buffer configuration.

20.2 USART main features

20.3 USART extended features

20.4 USART implementation

Table 60. USART/LPUART features describes the USART and LPUART implementation on the STM32WB07xC and STM32WB06xC devices.

Table 60. USART/LPUART features

USART modes/features (1)USARTLPUART
Hardware flow control for modemXX
Continuous communication using DMAXX
Multiprocessor communicationXX
Synchronous mode (master/slave)X-
Smartcard modeX-
Single-wire half-duplex communicationXX
IrDA SIR ENDEC blockX-
LIN modeX-
Dual clock domainXX
Receiver timeout interruptX-
Modbus communicationX-
Auto baud rate detectionX-
Driver enableXX
USART data length7, 8 and 9 bits
Tx/Rx FIFOXX
Tx/Rx FIFO size8

1. X=supported.

20.5 USART functional description

Any USART bidirectional communication requires a minimum of two pins: receive data in (RX) and transmit data out (TX):

Serial data are transmitted and received through these pins in normal USART mode. The frames are comprised of:

Refer to Section 20.7: USART registers for the definitions of each bit.

The following pin is required to interface in synchronous mode and smartcard mode:

In smartcard mode, SCLK output can provide the clock to the smartcard.

The following pins are required in RS232 hardware flow control mode:

The following pin is required in RS485 hardware control mode:

Note: DE and nRTS share the same pin.

Note: NSS and nCTS share the same pin.

Figure 113. USART block diagram Figure 113. USART block diagram. This is a complex block diagram of the USART peripheral. At the top, there are two data registers: 'Transmit data register (TDR/TXFIFO)' and 'Receive data register (RDR/RXFIFO)'. Data is written to the TDR and read from the RDR. Below these are 'Transmit shift register' and 'Receive shift register'. To the left is an 'IrDA SIR ENDEC block' connected to TX and RX pins. On the right is an 'SCKL control' block connected to the SCLK pin. Below the shift registers are control and configuration registers: 'USART_CR1 register', 'USART_CR2 register', 'USART_CR3 register', and 'USART_GTPR register' (containing GT and PSC). A 'Hardware flow controller' is connected to nRTS, /DE, and nCTS pins. Below the registers are 'Transmit control', 'Wake-up unit', and 'Receiver control' blocks. These are connected to 'USART_ISR register' and 'USART interrupt control'. At the bottom is a 'Conventional baud rate generator' containing 'USART_BRR register', 'Transmitter rate controller', 'Receiver rate controller', and 'BRR[15:0]'. It is connected to a clock divider block labeled '/USARTDIV or 2/USARTDIV (depending on the oversampling mode) (Note 1)'. The input clock is fCK (Note 2).
Figure 113. USART block diagram. This is a complex block diagram of the USART peripheral. At the top, there are two data registers: 'Transmit data register (TDR/TXFIFO)' and 'Receive data register (RDR/RXFIFO)'. Data is written to the TDR and read from the RDR. Below these are 'Transmit shift register' and 'Receive shift register'. To the left is an 'IrDA SIR ENDEC block' connected to TX and RX pins. On the right is an 'SCKL control' block connected to the SCLK pin. Below the shift registers are control and configuration registers: 'USART_CR1 register', 'USART_CR2 register', 'USART_CR3 register', and 'USART_GTPR register' (containing GT and PSC). A 'Hardware flow controller' is connected to nRTS, /DE, and nCTS pins. Below the registers are 'Transmit control', 'Wake-up unit', and 'Receiver control' blocks. These are connected to 'USART_ISR register' and 'USART interrupt control'. At the bottom is a 'Conventional baud rate generator' containing 'USART_BRR register', 'Transmitter rate controller', 'Receiver rate controller', and 'BRR[15:0]'. It is connected to a clock divider block labeled '/USARTDIV or 2/USARTDIV (depending on the oversampling mode) (Note 1)'. The input clock is fCK (Note 2).

Note: For details on coding USARTDIV in the USARTx_BRR register, refer to Section 20.5.5: Baud rate generation .

Note: \( f_{CK} \) is 16 MHz.

20.5.1 USART character description

The word length can be selected as being either 7 or 8 or 9 bits by programming the M bits (M0: bit 12 and M1: bit 28) in the USART_CR1 register (see Figure 114. Word length programming ).

Note: In 7-bits data length mode, the smartcard mode, LIN master mode and auto baud rate (0x7F and 0x55 frames detection) are not supported.

In default configuration, the signal (TX or RX) is in low state during the start bit. It is in high state during the stop bit.

These values can be inverted, separately for each signal, through polarity configuration control.

An Idle character is interpreted as an entire frame of “1”s. (The number of “1”s includes the number of stop bits).

A Break character is interpreted on receiving “0”s for a frame period. At the end of the break frame, the transmitter inserts 2 stop bits.

Transmission and reception are driven by a common baud rate generator, the clock for each is generated when the enable bit is set respectively for the transmitter and receiver.

The details of each block is given below.

Figure 114. Word length programming

Timing diagrams for 9-bit, 8-bit, and 7-bit word lengths showing data frames, idle frames, and break frames relative to a clock signal.

The diagram illustrates three word length configurations for the USART:

** LBCL bit controls last data clock pulse

Timing diagrams for 9-bit, 8-bit, and 7-bit word lengths showing data frames, idle frames, and break frames relative to a clock signal.

20.5.2 FIFOs and thresholds

The USART can operate in FIFO mode, with the FIFO buffers having a depth of 16 bytes (8 bytes TX, 8 bytes RX).

The USART comes with a transmit FIFO (TXFIFO) and a receive FIFO (RXFIFO). The FIFO mode is enabled by setting the bit 29 FIFOEN in the USARTx_CR1 register.

The FIFO mode is supported only on UART, SPI and smartcard modes.

Being 9 bits the maximum data word length, the TXFIFO is 9-bits wide. However the RXFIFO is by default 12-bits wide. This is due to the fact that the receiver does not only put the data in the FIFO, but also the error flags associated to each character (Parity error, Noise error and Framing error flags).

Note: The received data is stored in the RXFIFO with its flags. But If you read RDR, you read just the data. The status flags are available in the USART_ISR register.

It is possible to define the TXFIFO and RXFIFO levels at which the Tx and RX interrupt are triggered. These thresholds are programmed through bit fields RXFTCFG and TXFTCFG in USARTx_CR3 control register.

In this case:

RXFIFO threshold

The RXFIFO threshold is configured using the RXFTCFG bits fields in the USARTx_CR3 register.

When the number of received data is equal to the programmed RXFTCFG, the flag RXFT in the USART_ISR register is set.

Having RXFT flag set means that there are RXFTCFG data received: 1 data in USARTx_RDR and (RXFTCFG - 1) data in the RXFIFO. So, when the RXFTCFG is programmed to «101», the RXFT flag is set when 8 data are received: 7 data in the RXFIFO and 1 data in the USARTx_RDR. Consequently, the 9 th received data do not set the overrun flag.

20.5.3 Transmitter

The transmitter can send data words of either 7 or 8 or 9 bits depending on the M bit status. The transmit enable bit (TE) must be set in order to activate the transmitter function. The data in the transmit shift register is output on the TX pin and the corresponding clock pulses are output on the SCLK pin.

Character transmission

During an USART transmission, data shifts out least significant bit first (default configuration) on the TX pin. In this mode, the USARTx_TDR register consists of a buffer (TDR) between the internal bus and the transmit shift register.

When FIFO mode is enabled, data written to the transmit data register USART_TDR, is queued in the TXFIFO.

Every character is preceded by a start bit which is a logic level low for one bit period. The character is terminated by a configurable number of stop bits.

The following stop bits are supported by USART: 0.5, 1, 1.5 and 2 stop bits.

Note: The TE bit must be set before writing the data to be transmitted to the USART_TDR. The TE bit should not be reset during transmission of data. Resetting the TE bit during the transmission corrupts the data on the TX pin as the baud rate counters get frozen. The current data being transmitted are lost. An idle frame is sent after the TE bit is enabled.

Configurable stop bits

The number of stop bits to be transmitted with every character can be programmed in control register 2, bits 13,12.

An idle frame transmission includes the stop bits.

A break transmission is 10 low bits (when M[1:0] = 00) or 11 low bits (when M[1:0] = 01) or 9 low bits (when M[1:0] = 10) followed by 2 stop bits (see Figure 115. Configurable stop bits ). It is not possible to transmit long breaks (break of length greater than 9/10/11 low bits).

Figure 115. Configurable stop bits

Timing diagrams for 1 and 2 stop bits. Diagram (a) shows a data frame with start bit, 8 data bits (Bit0-Bit7), a possible parity bit, 1 stop bit, and the start bit of the next frame. Diagram (b) shows a data frame with start bit, 8 data bits (Bit0-Bit7), a possible parity bit, 2 stop bits, and the start bit of the next frame. Both diagrams include a CLOCK signal line with a note that the LBCL bit controls the last data clock pulse.

8-bit Word length (M[1:0]=00 bit is reset)

a) 1 Stop bit

The diagram shows the sequence of bits for a data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Possible parity bit, Stop bit, and the start bit of the next data frame. A CLOCK signal is shown with pulses corresponding to each bit. A note indicates that the LBCL bit controls the last data clock pulse.

b) 2 Stop bits

The diagram shows the sequence of bits for a data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Possible parity bit, 2 Stop bits, and the start bit of the next data frame. A CLOCK signal is shown with pulses corresponding to each bit.

Timing diagrams for 1 and 2 stop bits. Diagram (a) shows a data frame with start bit, 8 data bits (Bit0-Bit7), a possible parity bit, 1 stop bit, and the start bit of the next frame. Diagram (b) shows a data frame with start bit, 8 data bits (Bit0-Bit7), a possible parity bit, 2 stop bits, and the start bit of the next frame. Both diagrams include a CLOCK signal line with a note that the LBCL bit controls the last data clock pulse.

Character transmission procedure

  1. 1. Program the M bits in USART_CR1 to define the word length.
  2. 2. Select the desired baud rate using the USART_BRR register.
  3. 3. Program the number of stop bits in USART_CR2.
  4. 4. Enable the USART by writing the UE bit in USART_CR1 register to 1.
  5. 5. Select DMA enable (DMAT) in USART_CR3 if multi-buffer communication is to take place. Configure the DMA register as explained in multi-buffer communication.
  6. 6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
  7. 7. Write the data to send in the USART_TDR register. Repeat this for each data to be transmitted in case of single buffer.
    1. a. When FIFO mode is disabled, writing a data in the USART_TDR clears the TXE flag.
    2. b. When FIFO mode is enabled, writing a data in the USART_TDR adds one data to the TXFIFO and write operations in the USART_TDR are made when TXFNF flag is set. This flag remains set until the TXFIFO is full.
  8. 8. After writing the last data into the USART_TDR register, wait until TC=1.
    • – When FIFO mode is disabled, this indicates that the transmission of the last frame is complete.
    • – When FIFO mode is enabled, this indicates that both TXFIFO and shift register are empty.

Single byte communication

clearing the TXE flag is always performed by a write to the transmit data register. The TXE flag is set by hardware and it indicates:

This flag generates an interrupt if the TXEIE bit is set.

When a transmission is taking place, a write instruction to the USARTx_TDR register stores the data in the TDR register and which is copied in the shift register at the end of the current transmission.

When no transmission is taking place, a write instruction to the USARTx_TDR register places the data in the shift register, the data transmission starts, and the TXE bit is set.

When the TXFIFO is not full, the TXFNF flag stays at 1 even after a write in USART_TDR . It is cleared when the TXFIFO is full.

This flag generates an interrupt if the TXFNFIE bit is set.

Alternatively, interrupts can be generated and data can be written into FIFO when the TXFIFO threshold is reached. In this case, the CPU can write a block of data defined by the programmed trigger level.

If a frame is transmitted (after the stop bit) and the TXE flag (TXFE in case of FIFO mode) is set, the TC flag goes high. An interrupt is generated if the TCIE bit is set in the USART_CR1 register.

After writing the last data in the USART_TDR register, it is mandatory to wait for TC=1 before disabling the USART or causing the microcontroller to enter the low-power mode (see Figure 116. TC/TXE behavior when transmitting ).

Figure 116. TC/TXE behavior when transmitting

Timing diagram showing TX line, TXE flag, USART_DR, and TC flag signals during the transmission of three frames (Frame 1, Frame 2, Frame 3) following an idle preamble. The diagram illustrates the software control flow for waiting on TXE and TC flags.

The diagram illustrates the timing and control signals for transmitting three frames (Frame 1, Frame 2, Frame 3) after an idle preamble. The signals shown are:

Software control flow:

Timing diagram showing TX line, TXE flag, USART_DR, and TC flag signals during the transmission of three frames (Frame 1, Frame 2, Frame 3) following an idle preamble. The diagram illustrates the software control flow for waiting on TXE and TC flags.

Note: When FIFO management is enabled, the TXFNF flag is used for data transmission.

Break characters

Setting the SBKRQ bit transmits a break character. The break frame length depends on the M bit (see Figure 114. Word length programming).

If a '1' is written to the SBKRQ bit, a break character is sent on the TX line after completing the current character transmission. The SBKF bit is set by the write operation and it is reset by hardware when the break character is completed (during the stop bits after the break character). The USART inserts a logic 1 signal (STOP) for the duration of 2 bits at the end of the break frame to guarantee the recognition of the start bit of the next frame.

When the SBKRQ bit is set, the break character is sent at the end of the current transmission.

When FIFO mode is enabled, sending the break character has priority on sending data even if the TXFIFO is full.

Idle characters

Setting the TE bit drives the USART to send an idle frame before the first data frame.

20.5.4 Receiver

The USART can receive data words of either 7 or 8 or 9 bits depending on the M bits in the USART_CR1 register.

Start bit detection

The start bit detection sequence is the same when oversampling by 16 or by 8. In the USART, the start bit is detected when a specific sequence of samples is recognized. This sequence is: 1 1 1 0 X 0 X 0X 0X 0 X 0X 0.

Figure 117. Start bit detection when oversampling by 16 or 8

Timing diagram for start bit detection with oversampling. It shows RX state (Idle to Start bit), RX line (voltage levels), Ideal sample clock (16 pulses per bit), and Real sample clock (pulses at 1/16 intervals). Sampling points are marked at 3rd, 5th, 7th, 8th, 9th, and 10th pulses. Conditions to validate the start bit are shown as a sequence of 1s and 0s with annotations for falling edge detection and 'At least 2 bits out of 3 at 0'.

The diagram illustrates the start bit detection process. The RX line transitions from Idle (high) to Start bit (low). Ideal sample clock has 16 pulses per bit period. Real sample clock has pulses at 1/16 intervals. Sampling points are marked at 3rd, 5th, 7th, 8th, 9th, and 10th pulses. Conditions to validate the start bit are shown as a sequence of 1s and 0s with annotations for falling edge detection and 'At least 2 bits out of 3 at 0'.

Conditions to validate the start bit1110X0X0X000XXXXXX
Falling edge detectionAt least 2 bits out of 3 at 0At least 2 bits out of 3 at 0
Timing diagram for start bit detection with oversampling. It shows RX state (Idle to Start bit), RX line (voltage levels), Ideal sample clock (16 pulses per bit), and Real sample clock (pulses at 1/16 intervals). Sampling points are marked at 3rd, 5th, 7th, 8th, 9th, and 10th pulses. Conditions to validate the start bit are shown as a sequence of 1s and 0s with annotations for falling edge detection and 'At least 2 bits out of 3 at 0'.

Note: If the sequence is not complete, the start bit detection aborts and the receiver returns to the idle state (no flag is set), where it waits for a falling edge.

The start bit is confirmed (RXNE flag set, interrupt generated if RXNEIE=1 (RXFNE flag set, interrupt generated if RXFNEIE=1 if FIFO mode is enabled) if the 3 sampled bits are at 0 (first sampling on the 3rd, 5th and 7th bits finds the 3 bits at 0 and second sampling on the 8th, 9th and 10th bits also finds the 3 bits at 0).

The start bit is validated but the NF noise flag is set if,

  1. 1. for both samplings, 2 out of the 3 sampled bits are at 0 (sampling on the 3rd, 5th and 7th bits and sampling on the 8th, 9th and 10th bits)
    or
  2. 2. for one of the samplings (sampling on the 3rd, 5th and 7th bits or sampling on the 8th, 9th and 10th bits), 2 out of the 3 bits are found at 0.

If neither conditions, 1 or 2, are met, the start detection aborts and the receiver returns to the idle state (no flag is set).

Character reception

During a USART reception, data shifts in least significant bit first (default configuration) through the RX pin.

Character reception procedure

  1. 1. Program the M bits in USART_CR1 to define the word length
  2. 2. Select the desired baud rate using the baud rate register USART_BRR
  3. 3. Program the number of stop bits in USART_CR2
  4. 4. Enable the USART by writing the UE bit in USART_CR1 register to 1
  5. 5. Select DMA enable (DMAR) in USART_CR3 if multi-buffer communication is to take place. Configure the DMA register as explained in multi-buffer communication
  6. 6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a start bit.

When a character is received

Break character

When a break character is received, the USART handles it as a framing error.

Idle character

When an idle frame is detected, there is the same procedure as for a received data character plus an interrupt if the IDLEIE bit is set.

Overrun error

An overrun error occurs when a character is received when RXNE has not been reset. Data cannot be transferred from the shift register to the RDR register until the RXNE bit is cleared. The RXNE flag is set after every byte received. An overrun error occurs if RXNE flag is set when the next data is received or the previous DMA request has not been serviced. When an overrun error occurs:

  1. 1. The ORE bit is set.
  2. 2. The RDR content is not lost. The previous data is available when a read to USARTx_RDR is performed.
  3. 3. The shift register is overwritten. After that point, any data received during overrun is lost.
  4. 4. An interrupt is generated if either the RXNEIE bit is set or EIE bit is set.

An overrun error occurs when the shift register is ready to be transferred when the receive FIFO is full. Data can not be transferred from the shift register to the USARTx_RDR register until there is one free location in the RXFIFO. The RXFNE flag is set when the RXFIFO is not empty. An overrun error occurs if the RXFIFO is full and the shift register is ready to be transferred. When an overrun error occurs:

  1. 1. The ORE bit is set.
  2. 2. The first entry in the RXFIFO is not lost. It is available when a read to USART_RDR is performed.
  3. 3. The shift register is overwritten. After that point, any data received during overrun is lost.
  4. 4. An interrupt is generated if either the RXFNEIE bit is set or EIE bit is set.

The ORE bit is reset by setting the ORECF bit in the USARTx_ICR register.

Note: The ORE bit, when set, indicates that at least 1 data has been lost. When the FIFO mode is disabled, there are two possibilities

Selecting the clock source and the proper oversampling method

The clock source frequency is \( f_{CK} \) (16 MHz).

The \( f_{CK} \) can be divided by a programmable factor in the USARTx_PRESC register.

Figure 118. usart_ker_ck clock divider block diagram

Block diagram of the usart_ker_ck clock divider. An input signal 'usart_ker_ck' enters a large grey box. Inside the box, the signal first passes through a block labeled 'USARTx_PRESC[3:0]'. The output of this block, labeled 'usart_ker_ck_pres', then enters another block labeled 'USARTx_BRR register and oversampling'.
Block diagram of the usart_ker_ck clock divider. An input signal 'usart_ker_ck' enters a large grey box. Inside the box, the signal first passes through a block labeled 'USARTx_PRESC[3:0]'. The output of this block, labeled 'usart_ker_ck_pres', then enters another block labeled 'USARTx_BRR register and oversampling'.

MSv40855V1

The communication speed range (specially the maximum communication speed) is also determined by the clock source.

The receiver implements different user-configurable oversampling techniques (except in synchronous mode) for data recovery by discriminating between valid incoming data and noise. This allows a trade off between the maximum communication speed and noise/clock inaccuracy immunity.

The oversampling method can be selected by programming the OVER8 bit in the USART_CR1 register and can be either 16 or 8 times the baud rate clock (Figure 119. Data sampling when oversampling by 16 and Figure 120. Data sampling when oversampling by 8).

Depending on the application:

where \( f_{CKPRES} \) is the USART input clock divided by a prescaler.

Programming the ONEBIT bit in the USART_CR3 register selects the method used to evaluate the logic level. There are two options:

When noise is detected in a frame:

The NF bit is reset by setting NFCF bit in the ICR register.

Note: Noise error is not supported in SPI mode.

Note: Oversampling by 8 is not available in the smartcard, IrDA and LIN modes. In those modes, the OVER8 bit is forced to '0' by hardware.

Figure 119. Data sampling when oversampling by 16

Timing diagram for oversampling by 16. It shows the RX line and Sample clock. The RX line has a falling edge followed by a rising edge. The Sample clock has 16 rising edges labeled 1 through 16. The first three rising edges are shaded gray. The 'sampled values' are indicated by a bracket over the 8th, 9th, and 10th rising edges. The 'One bit time' is marked by a double-headed arrow spanning from the first rising edge to the 16th. The duration from the first rising edge to the start of the sampled values is labeled 7/16. The duration from the start of the sampled values to the 16th rising edge is labeled 6/16. The duration from the 10th rising edge to the 16th rising edge is labeled 7/16.
Timing diagram for oversampling by 16. It shows the RX line and Sample clock. The RX line has a falling edge followed by a rising edge. The Sample clock has 16 rising edges labeled 1 through 16. The first three rising edges are shaded gray. The 'sampled values' are indicated by a bracket over the 8th, 9th, and 10th rising edges. The 'One bit time' is marked by a double-headed arrow spanning from the first rising edge to the 16th. The duration from the first rising edge to the start of the sampled values is labeled 7/16. The duration from the start of the sampled values to the 16th rising edge is labeled 6/16. The duration from the 10th rising edge to the 16th rising edge is labeled 7/16.

Figure 120. Data sampling when oversampling by 8

Timing diagram for oversampling by 8. It shows the RX line and Sample clock (x8). The RX line has a falling edge followed by a rising edge. The Sample clock has 8 rising edges labeled 1 through 8. The first three rising edges are shaded gray. The 'sampled values' are indicated by a bracket over the 4th, 5th, and 6th rising edges. The 'One bit time' is marked by a double-headed arrow spanning from the first rising edge to the 8th. The duration from the first rising edge to the start of the sampled values is labeled 3/8. The duration from the start of the sampled values to the 8th rising edge is labeled 2/8. The duration from the 6th rising edge to the 8th rising edge is labeled 3/8.
Timing diagram for oversampling by 8. It shows the RX line and Sample clock (x8). The RX line has a falling edge followed by a rising edge. The Sample clock has 8 rising edges labeled 1 through 8. The first three rising edges are shaded gray. The 'sampled values' are indicated by a bracket over the 4th, 5th, and 6th rising edges. The 'One bit time' is marked by a double-headed arrow spanning from the first rising edge to the 8th. The duration from the first rising edge to the start of the sampled values is labeled 3/8. The duration from the start of the sampled values to the 8th rising edge is labeled 2/8. The duration from the 6th rising edge to the 8th rising edge is labeled 3/8.

Table 61. Noise detection from sampled data

Sampled valueNE statusReceived bit value
00000
00110
01010
01111
10010
10111
11011
11101

Framing error

A framing error is detected when the stop bit is not recognized on reception at the expected time, following either a de-synchronization or excessive noise.

When the framing error is detected:

The FE bit is reset by writing 1 to the FECF in the USART_ICR register.

Note: Framing error is not supported in SPI mode.

Configurable stop bits during reception

The number of stop bits to be received can be configured through the control bits of control register 2 - it can be either 1 or 2 in normal mode and 0.5 or 1.5 in smartcard mode.

20.5.5 Baud rate generation

The baud rate for the receiver and transmitter (Rx and Tx) are both set to the same value as programmed in the USART_BRR register.

The equation below is baud rate for standard USART (SPI mode included) (OVER8= 0 or 1).

In case of oversampling by 16, the equation is:

\[ Tx/Rxbaud = \frac{f_{CKPRES}}{USARTDIV} \quad (4) \]

In case of oversampling by 8, the equation is:

\[ Tx/Rxbaud = \frac{2 \times f_{CKPRES}}{USARTDIV} \quad (5) \]

The equation below is baud rate in Smartcard, LIN and IrDA modes (OVER8= 0):

\[ Tx/Rxbaud = \frac{f_{CKPRES}}{USARTDIV} \quad (6) \]

\( f_{CKPRES} \) is the USART clock which is the USART input clock divided by a prescaler configured in the USART_PRES register.

USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.

Note: The baud counters are updated to the new value in the baud registers after a write operation to USART_BRR. Hence the baud rate register value should not be changed during communication. In case of oversampling by 16 and 8, USARTDIV must be greater than or equal to 16d.

How to derive USARTDIV from USART_BRR register values

Example 1

To obtain 9600 baud with \( f_{CKPRES} = 8 \) MHz.

20.5.6 Tolerance of the USART receiver to clock deviation

The asynchronous receiver of the USART works correctly only if the total clock system deviation is less than the tolerance of the USART receiver. The causes which contribute to the total deviation are:

    • • DTRA: Deviation due to the transmitter error (which also includes the deviation of the transmitter's local oscillator)
    • • DQUANT: Error due to the baud rate quantization of the receiver
    • • DREC: Deviation of the receiver local oscillator
    • • DTCL: Deviation due to the transmission line (generally due to the transceivers which can introduce an asymmetry between the low-to-high transition timing and the high-to-low transition timing)
  1. \( DTRA + DQUANT + DREC + DTCL < USART receiver tolerance. \)

The USART receiver can receive data correctly at up to the maximum tolerated deviation specified in Table 62. Tolerance of the USART receiver when BRR [3:0] = 0000 (high-density devices) and Table 63. Tolerance of the USART receiver when BRR[3:0] is different from 0000 (high-density devices) , depending on the following choices:

Table 62. Tolerance of the USART receiver when BRR [3:0] = 0000 (high-density devices)

M bitsOVER8 bit = 0OVER8 bit = 1
ONEBIT=0ONEBIT=1ONEBIT=0ONEBIT=1
003.75%4.375%2.50%3.75%
013.41%3.97%2.27%3.41%
104.164.862.774.16

Table 63. Tolerance of the USART receiver when BRR[3:0] is different from 0000 (high-density devices)

M bitsOVER8 bit = 0OVER8 bit = 1
ONEBIT=0ONEBIT=1ONEBIT=0ONEBIT=1
003.33%3.88%2%3%
013.03%3.53%1.82%2.73%
103.74.312.223.33

Note: The data specified in Table 62. Tolerance of the USART receiver when BRR [3:0] = 0000 (high-density devices) and Table 63. Tolerance of the USART receiver when BRR[3:0] is different from 0000 (high-density devices) may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit times when M bits = 00 (11-bit times when M = 01 or 9-bit times when M = 10).

20.5.7 Auto baud rate detection

The USART is able to detect and automatically set the USART_BRR register value based on the reception of one character. Automatic baud rate detection is useful under two circumstances:

The clock source frequency must be compatible with the expected communication speed (when oversampling by 16, the baud rate is between \( f_{CK}/65535 \) and \( f_{CK}/16 \) . When oversampling by 8, the baud rate is between \( f_{CK}/65535 \) and \( f_{CK}/8 \) .

Before activating the auto baud rate detection, the auto baud rate detection mode must be chosen. There are four modes based on different character patterns.

The modes can be chosen through the ABRMOD[1:0] field in the USART_CR2 register. In these auto baud rate modes, the baud rate is measured several times during the synchronization data reception and each measurement is compared to the previous one.

These modes are:

Prior to activating auto baud rate detection, the USART_BRR register must be initialized by writing a non-zero baud rate value.

The automatic baud rate detection is activated by setting the ABREN bit in the USART_CR2 register. The USART then waits for the first character on the RX line. The auto baud rate operation completion is indicated by the setting of the ABRF flag in the USART_ISR register. If the line is noisy, the correct baud rate detection cannot be guaranteed. In this case the BRR value may be corrupted and the ABRE error flag is set. This also happens if the communication speed is not compatible with the automatic baud rate detection range (bit duration not between 16 and 65536 clock periods (oversampling by 16) and not between 8 and 65536 clock periods (oversampling by 8)).

The auto baud rate detection can be re-launched later by resetting the ABRF flag (by writing a 0).

When FIFO management is disabled, in case of auto baud rate error, the ABRE flag is set with RXNE and FE.

When FIFO management is enabled, in case of auto baud rate error, the ABRE flag is set with RXFNE and FE.

In case FIFO mode is enabled, the auto baud rate detection should be made using the data on the first RXFIFO location. So, prior to launching the auto baud rate detection, the user should make sure that the RXFIFO is empty using the RXFNE flag in the USARTx_ISR register.

Note: The BRR value may be corrupted if the USART is disabled (UE=0) during an auto baud rate operation.

20.5.8 Multiprocessor communication

It is possible to perform multiprocessor communication with the USART (with several USARTs connected in a network). For instance one of the USARTs can be the master, its TX output connected to the RX inputs of the other USARTs. The others are slaves, their respective TX outputs are logically ANDed together and connected to the RX input of the master.

In multiprocessor configurations it is often desirable that only the intended message recipients should actively receive the full message contents, thus reducing redundant USART service overhead for all non addressed receivers.

The non addressed devices may be placed in mute mode by means of the muting function. In order to use the mute mode feature, the MME bit must be set in the USARTx_CR1 register.

Note: When FIFO management is enabled and MME is already set, MME bit must not be cleared and then set again quickly (within two UCLK cycles) otherwise mute mode might remain active.

In mute mode:

The USART can enter or exit from mute mode using one of two methods, depending on the WAKE bit in the USART_CR1 register:

Idle line detection (WAKE=0)

The USART enters mute mode when the MMRQ bit is written to 1 and the RWU is automatically set. It wakes up when an idle frame is detected. Then the RWU bit is cleared by hardware but the IDLE bit is not set in the USART_ISR register. An example of mute mode behavior using Idle line detection is given in Figure 121. Mute mode using Idle line detection.

Figure 121. Mute mode using Idle line detection

Timing diagram showing RX data frames (Data 1-6, IDLE) and RWU signal transitions between Mute mode and Normal mode. The RWU signal goes high when 'MMRQ written to 1' and returns low when 'Idle frame detected'. RX(F)NE flags are shown rising after Data 4 and Data 6.

The diagram illustrates the relationship between received data and the USART's mute mode. The top part shows a sequence of data frames: Data 1, Data 2, Data 3, Data 4, an IDLE frame, Data 5, and Data 6. The RX(F)NE flag is indicated by upward arrows after the reception of Data 4 and Data 6. The bottom part shows the RWU (Receiver Wake-Up) signal. When 'MMRQ written to 1' occurs, the RWU signal transitions to 'Mute mode' (high). It remains high until an 'Idle frame detected' event occurs, at which point it transitions back to 'Normal mode' (low).

Timing diagram showing RX data frames (Data 1-6, IDLE) and RWU signal transitions between Mute mode and Normal mode. The RWU signal goes high when 'MMRQ written to 1' and returns low when 'Idle frame detected'. RX(F)NE flags are shown rising after Data 4 and Data 6.

Note: If the MMRQ is set while the IDLE character has already elapsed, mute mode is not entered (RWU is not set).

Note: If the USART is activated while the line is IDLE, the idle state is detected after the duration of one IDLE frame (not only after the reception of one character frame).

4-bit/7-bit address mark detection (WAKE=1)

In this mode, bytes are recognized as addresses if their MSB is a '1' otherwise they are considered as data. In an address byte, the address of the targeted receiver is put in the 4 or 7 LSBs. The choice of 7 or 4 bit address detection is done using the ADDM7 bit. This 4-bit/7-bit word is compared by the receiver with its own address which is programmed in the ADD bits in the USART_CR2 register.

Note: In 7-bit and 9-bit data modes, address detection is done on 6-bit and 8-bit addresses (ADD[5:0] and ADD[7:0]) respectively.

The USART enters mute mode when an address character is received which does not match its programmed address. In this case, the RWU bit is set by hardware. The RXNE flag is not set for this address byte and no interrupt or DMA request is issued when the USART enters mute mode. When FIFO management is enabled, the software should ensure that there is at least one empty location in the RXFIFO before entering mute mode.

The USART also enters mute mode when the MMRQ bit is written to 1. The RWU bit is also automatically set in this case. The USART exits from mute mode when an address character is received which matches the programmed address. Then the RWU bit is cleared and subsequent bytes are received normally. The RXNE/RXFNE bit is set for the address character since the RWU bit has been cleared.

Note: When FIFO management is enabled, when MMRQ is set while the receiver is sampling the last bit of data, these data maybe be received before entering mute mode.

An example of mute mode behavior using address mark detection is given in Figure 122. Mute mode using address mark detection.

Figure 122. Mute mode using address mark detection

Timing diagram showing RX and RWU signals. RX signal shows IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. RWU signal shows Mute mode and Normal mode transitions. Mute mode starts when MMRQ is written to 1 (RXNE was cleared) and ends when a matching address (Addr=1) is received. Normal mode resumes after Addr=1 and ends when a non-matching address (Addr=2) is received, returning to Mute mode. RX(FNE) flags are shown for Addr=1, Data 3, and Data 4.

In this example, the current address of the receiver is 1 (programmed in the USART_CR2 register)

The diagram illustrates the RX and RWU signals over time. The RX signal shows a sequence of IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. The RWU signal shows Mute mode and Normal mode transitions. Mute mode starts when MMRQ is written to 1 (RXNE was cleared) and ends when a matching address (Addr=1) is received. Normal mode resumes after Addr=1 and ends when a non-matching address (Addr=2) is received, returning to Mute mode. RX(FNE) flags are shown for Addr=1, Data 3, and Data 4.

Timing diagram showing RX and RWU signals. RX signal shows IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. RWU signal shows Mute mode and Normal mode transitions. Mute mode starts when MMRQ is written to 1 (RXNE was cleared) and ends when a matching address (Addr=1) is received. Normal mode resumes after Addr=1 and ends when a non-matching address (Addr=2) is received, returning to Mute mode. RX(FNE) flags are shown for Addr=1, Data 3, and Data 4.

20.5.9 Modbus communication

The USART offers basic support for the implementation of Modbus/RTU and Modbus/ASCII protocols. Modbus/RTU is a half-duplex, block transfer protocol. The control part of the protocol (address recognition, block integrity control and command interpretation) must be implemented in software.

The USART offers basic support for the end of the block detection, without software overhead or other resources.

Modbus/RTU

In this mode, the end of one block is recognized by a “silence” (idle line) for more than 2 character times. This function is implemented through the programmable timeout function.

The timeout function and interrupt must be activated, through the RTOEN bit in the USART_CR2 register and the RTOIE in the USART_CR1 register. The value corresponding to a timeout of 2 character times (for example 22 x bit time) must be programmed in the RTO register. When the receive line is idle for this duration, after the last stop bit is received, an interrupt is generated, informing the software that the current block reception is completed.

Modbus/ASCII

In this mode, the end of a block is recognized by a specific (CR/LF) character sequence. The USART manages this mechanism using the character match function. By programming the LF ASCII code in the ADD[7:0] field and by activating the character match interrupt (CMIE=1), the software is informed when an LF has been received and can check the CR/LF in the DMA buffer.

20.5.10 Parity control

Parity control (generation of parity bit in transmission and parity checking in reception) can be enabled by setting the PCE bit in the USART_CR1 register. Depending on the frame length defined by the M bits, the possible USART frame formats are as listed in Table 64. Frame formats.

Table 64. Frame formats

M bitsPCE bitUSART frame (1)
000| SB | 8-bit data | STB |
001| SB | 7-bit data | PB | STB |
010| SB | 9-bit data | STB |
M bitsPCE bitUSART frame (1)
011| SB | 8-bit data PB | STB |
100| SB | 7-bit data | STB |
101| SB | 6-bit data | PB | STB |

1. Legends: SB: start bit, STB: stop bit, PB: parity bit. In the data register, the PB is always taking the MSB position (8 th or 7 th , depending on the M bit value).

Even parity

The parity bit is calculated to obtain an even number of “1s” inside the frame of the 6, 7 or 8 LSB bits (depending on M bit values) and the parity bit.

As an example, if data=00110101, and 4 bits are set, then the parity bit is 0 if even parity is selected (PS bit in USART_CR1 = 0).

Odd parity

The parity bit is calculated to obtain an odd number of “1s” inside the frame made of the 6, 7 or 8 LSB bits (depending on M bit values) and the parity bit.

As an example, if data=00110101 and 4 bits set, then the parity bit is 1 if odd parity is selected (PS bit in USART_CR1 = 1).

Parity checking in reception

If the parity check fails, the PE flag is set in the USART_ISR register and an interrupt is generated if PEIE is set in the USART_CR1 register. The PE flag is cleared by software writing 1 to the PECF in the USART_ICR register.

Parity generation in transmission

If the PCE bit is set in USART_CR1, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit (even number of “1s” if even parity is selected (PS=0) or an odd number of “1s” if odd parity is selected (PS=1)).

20.5.11 LIN (local interconnection network) mode

This section is relevant only when LIN mode is supported. Refer to Section 20.4: USART implementation .

The LIN mode is selected by setting the LINEN bit in the USART_CR2 register. In LIN mode, the following bits must be kept cleared:

LIN transmission

The procedure explained in Section 20.5.2: FIFOs and thresholds has to be applied for LIN Master transmission. It must be the same as for normal USART transmission with the following differences:

LIN reception

When LIN mode is enabled, the break detection circuit is activated. The detection is totally independent from the normal USART receiver. A break can be detected whenever it occurs, during idle state or during a frame.

When the receiver is enabled (RE=1 in USART_CR1), the circuit looks at the RX input for a start signal. The method to detect start bits is the same when searching break characters or data. After a start bit has been detected, the circuit samples the next bits exactly like for the data (on the 8 th , 9 th and 10 th samples). If 10 (when the LBDL = 0 in USART_CR2) or 11 (when LBDL=1 in USART_CR2) consecutive bits are detected as '0', and are followed by a delimiter character, the LBDF flag is set in USART_ISR. If the LBDIE bit=1, an interrupt is generated. Before validating the break, the delimiter is checked for as it signifies that the RX line has returned to a high level.

If a '1' is sampled before the 10 or 11 have occurred, the break detection circuit cancels the current detection and searches for a start bit again.

If the LIN mode is disabled (LINEN=0), the receiver continues working as normal USART, without taking into account the break detection.

If the LIN mode is enabled (LINEN=1), as soon as a framing error occurs (i.e. stop bit detected at '0', which is the case for any break frame), the receiver stops until the break detection circuit receives either a '1', if the break word was not complete, or a delimiter character if a break has been detected.

The behavior of the break detector state machine and the break flag is shown in Figure 123. Break detection in LIN mode (11-bit break length - LBDL bit is set).

Examples of break frames are given:

Figure 123. Break detection in LIN mode (11-bit break length - LBDL bit is set)

Case 1: break signal not long enough => break discarded, LBDF is not set

Timing diagram for Case 1: The RX line goes low for a break frame but returns high at Bit10. Capture strobes occur at regular intervals. The Break state machine transitions from Idle through Bit0 to Bit10, then returns to Idle because the sample at Bit10 is '1'. Read samples are all '0' except for the last one which is '1'.
RX lineBreak frame
Capture strobe||||||||||
Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read samples00000000001
Timing diagram for Case 1: The RX line goes low for a break frame but returns high at Bit10. Capture strobes occur at regular intervals. The Break state machine transitions from Idle through Bit0 to Bit10, then returns to Idle because the sample at Bit10 is '1'. Read samples are all '0' except for the last one which is '1'.

Case 2: break signal just long enough => break detected, LBDF is set

Timing diagram for Case 2: The RX line stays low for the full break frame duration. An immediate delimiter (high signal) follows. Capture strobes continue. The Break state machine reaches Bit10 and then returns to Idle. Read samples are all '0'. The LBDF flag transitions from low to high at the end of Bit10.
RX lineBreak frameDelimiter is immediate
Capture strobe|||||||||||
Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read samples00000000000
LBDFSet (High)
Timing diagram for Case 2: The RX line stays low for the full break frame duration. An immediate delimiter (high signal) follows. Capture strobes continue. The Break state machine reaches Bit10 and then returns to Idle. Read samples are all '0'. The LBDF flag transitions from low to high at the end of Bit10.

Case 3: break signal long enough => break detected, LBDF is set

Timing diagram for Case 3: The RX line stays low longer than the 11-bit break period. The Break state machine transitions from Bit10 to a 'wait delimiter' state while the line is still low, then to Idle once the line goes high. Read samples for Bit0-Bit10 are all '0'. The LBDF flag is set high at the end of Bit10.
RX lineBreak frame
Capture strobe||||||||||||
Break state machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10wait delimiterIdle
Read samples00000000000
LBDFSet (High)
Timing diagram for Case 3: The RX line stays low longer than the 11-bit break period. The Break state machine transitions from Bit10 to a 'wait delimiter' state while the line is still low, then to Idle once the line goes high. Read samples for Bit0-Bit10 are all '0'. The LBDF flag is set high at the end of Bit10.

Figure 124. Break detection in LIN mode vs. framing error detection

Case 1: break occurring after an Idle

Timing diagram for Case 1: break occurring after an Idle. The RX line shows a sequence of data 1, IDLE, BREAK, data 2 (0x55), and data 3 (header). The BREAK duration is 1 data time. The RXNE/FE line is high during IDLE and goes low when BREAK starts. The LBDF line is high during IDLE and goes low when BREAK starts.

The diagram shows the RX line, RXNE/FE line, and LBDF line over time. The RX line has segments for 'data 1', 'IDLE', 'BREAK', 'data 2 (0x55)', and 'data 3 (header)'. The 'BREAK' segment is labeled with a double-headed arrow indicating a duration of '1 data time'. The 'IDLE' segment between 'data 1' and 'BREAK' is also labeled with a double-headed arrow indicating a duration of '1 data time'. The RXNE/FE line is high during the 'IDLE' segment and goes low at the start of the 'BREAK' segment. The LBDF line is high during the 'IDLE' segment and goes low at the start of the 'BREAK' segment.

Timing diagram for Case 1: break occurring after an Idle. The RX line shows a sequence of data 1, IDLE, BREAK, data 2 (0x55), and data 3 (header). The BREAK duration is 1 data time. The RXNE/FE line is high during IDLE and goes low when BREAK starts. The LBDF line is high during IDLE and goes low when BREAK starts.

Case 2: break occurring while data is being received

Timing diagram for Case 2: break occurring while data is being received. The RX line shows a sequence of data 1, data 2, BREAK, data 2 (0x55), and data 3 (header). The BREAK duration is 1 data time. The RXNE/FE line is high during data 2 and goes low when BREAK starts. The LBDF line is high during data 2 and goes low when BREAK starts.

The diagram shows the RX line, RXNE/FE line, and LBDF line over time. The RX line has segments for 'data 1', 'data 2', 'BREAK', 'data 2 (0x55)', and 'data 3 (header)'. The 'BREAK' segment is labeled with a double-headed arrow indicating a duration of '1 data time'. The 'data 2' segment between 'data 1' and 'BREAK' is also labeled with a double-headed arrow indicating a duration of '1 data time'. The RXNE/FE line is high during the 'data 2' segment and goes low at the start of the 'BREAK' segment. The LBDF line is high during the 'data 2' segment and goes low at the start of the 'BREAK' segment.

Timing diagram for Case 2: break occurring while data is being received. The RX line shows a sequence of data 1, data 2, BREAK, data 2 (0x55), and data 3 (header). The BREAK duration is 1 data time. The RXNE/FE line is high during data 2 and goes low when BREAK starts. The LBDF line is high during data 2 and goes low when BREAK starts.

20.5.12 USART synchronous mode

Master mode

The synchronous master mode is selected by writing the CLKEN bit in the USART_CR2 register to 1. In synchronous mode, the following bits must be kept cleared:

In this mode, the USART can be used to control bidirectional synchronous serial communications in master mode. The SCLK pin is the output of the USART transmitter clock. No clock pulses are sent to the SCLK pin during start bit and stop bit. Depending on the state of the LBCL bit in the USART_CR2 register, clock pulses are, or are not, generated during the last valid data bit (address mark). The CPOL bit in the USART_CR2 register is used to select the clock polarity, and the CPHA bit in the USART_CR2 register is used to select the phase of the external clock (see Figure 125. USART example of synchronous master transmission and Figure 126. USART data clock timing diagram M=0).

During the idle state, preamble and send break, the external SCLK clock is not activated.

In synchronous master mode the USART transmitter works exactly like in asynchronous mode. But as SCLK is synchronized with TX (according to CPOL and CPHA), the data on TX is synchronous.

In this mode the USART receiver works in a different manner compared to the asynchronous mode. If RE=1, the data is sampled on SCLK (rising or falling edge, depending on CPOL and CPHA), without any oversampling. A setup and a hold time must be respected (which depends on the baud rate: 1/16 bit time).

Note: In master mode, the SCLK pin works in conjunction with the TX pin. Thus, the clock is provided only if the transmitter is enabled (TE=1) and data is being transmitted (the data register USART_DR written). This means that it is not possible to receive synchronous data without transmitting data.

Figure 125. USART example of synchronous master transmission

Block diagram showing USART connected to a synchronous device. The USART block has pins RX, TX, and SCLK. The Synchronous device (e.g. slave SPI) has pins Data out, Data in, and Clock. Connections: USART RX connects to Data out; USART TX connects to Data in; USART SCLK connects to Clock.
Block diagram showing USART connected to a synchronous device. The USART block has pins RX, TX, and SCLK. The Synchronous device (e.g. slave SPI) has pins Data out, Data in, and Clock. Connections: USART RX connects to Data out; USART TX connects to Data in; USART SCLK connects to Clock.

Figure 126. USART data clock timing diagram M=0

Timing diagram for USART data clock (M=0) showing four clock configurations: CPOL=0/CPHA=0, CPOL=0/CPHA=1, CPOL=1/CPHA=0, and CPOL=1/CPHA=1. The diagram shows an 8-bit data frame (bits 0 to 7) starting with an LSB and ending with an MSB. It includes signals for Data on TX (from master), Data on RX (from slave), and a Capture strobe. Vertical dashed lines indicate bit boundaries and sampling points. An asterisk (*) on the last clock pulse of each clock signal refers to the note: *LBCL bit controls last data pulse.

Idle or preceding transmission     Start     M=0 (8 data bits)     Stop     Idle or next transmission

Clock (CPOL=0, CPHA=0)

Clock (CPOL=0, CPHA=1)

Clock (CPOL=1, CPHA=0)

Clock (CPOL=1, CPHA=1)

Data on TX (from master)

Data on RX (from slave)

Capture strobe

*LBCL bit controls last data pulse

Timing diagram for USART data clock (M=0) showing four clock configurations: CPOL=0/CPHA=0, CPOL=0/CPHA=1, CPOL=1/CPHA=0, and CPOL=1/CPHA=1. The diagram shows an 8-bit data frame (bits 0 to 7) starting with an LSB and ending with an MSB. It includes signals for Data on TX (from master), Data on RX (from slave), and a Capture strobe. Vertical dashed lines indicate bit boundaries and sampling points. An asterisk (*) on the last clock pulse of each clock signal refers to the note: *LBCL bit controls last data pulse.

Figure 127. USART data clock timing diagram (M bits = 01)

Figure 127: USART data clock timing diagram (M bits = 01). The diagram shows four clock waveforms (CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; CPOL=1, CPHA=1) and two data lines (TX from master, RX from slave) over a 9-bit data sequence (0-8). The TX line shows bits 0-8 starting from a 'Start' condition. The RX line shows bits 0-8 starting from a 'Start' condition, with the first bit labeled 'LSB' and the last bit labeled 'MSB'. A 'Capture strobe' is shown as a pulse on the RX line. A note indicates that the LBCL bit controls the last data pulse.
Figure 127: USART data clock timing diagram (M bits = 01). The diagram shows four clock waveforms (CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; CPOL=1, CPHA=1) and two data lines (TX from master, RX from slave) over a 9-bit data sequence (0-8). The TX line shows bits 0-8 starting from a 'Start' condition. The RX line shows bits 0-8 starting from a 'Start' condition, with the first bit labeled 'LSB' and the last bit labeled 'MSB'. A 'Capture strobe' is shown as a pulse on the RX line. A note indicates that the LBCL bit controls the last data pulse.

Figure 128. RX data setup/hold time

Figure 128: RX data setup/hold time. The diagram shows the SCLK (capture strobe on SCLK) and Data on RX (from slave) lines. The SCLK line has a rising edge. The Data on RX line shows a 'Valid DATA bit' window. The setup time (t_SETUP) is the time before the rising edge of SCLK, and the hold time (t_HOLD) is the time after the rising edge of SCLK.
Figure 128: RX data setup/hold time. The diagram shows the SCLK (capture strobe on SCLK) and Data on RX (from slave) lines. The SCLK line has a rising edge. The Data on RX line shows a 'Valid DATA bit' window. The setup time (t_SETUP) is the time before the rising edge of SCLK, and the hold time (t_HOLD) is the time after the rising edge of SCLK.

\[ t_{\text{SETUP}} = t_{\text{HOLD}} \text{ 1/16 bit time} \]

Slave mode

The synchronous slave mode is selected by writing the SLVEN bit in the USART_CR2 register to 1. In synchronous slave mode, the following bits must be kept cleared:

In this mode, the USART can be used to control bidirectional synchronous serial communications in slave mode. The SCLK pin is the input of the USART in slave mode.

Note: When the peripheral is used in SPI slave mode, the peripheral clock source (fck_pres) must be greater than 3xSCLK input clock.

The CPOL bit in the USART_CR2 register is used to select the clock polarity, and the CPHA bit in the USART_CR2 register is used to select the phase of the external clock (see Figure 125. USART example of synchronous master transmission, Figure 126. USART data clock timing diagram M=0 and Figure 127. USART data clock timing diagram (M bits = 01)).

In slave transmission mode, an underun error flag is available. This flag is set when the first clock for data transmission appears while the software has not yet loaded any value into USARTx_TDR.

The slave supports the hardware and software NSS management.

Slave select (NSS) pin management

Hardware or software slave select management can be set using the DIS_NSS bit in the USART_CR2 register.

Note: The LBCL (used only on SPI master mode), CPOL and CPHA bits have to be selected when the USART is disabled (UE=0) to ensure that the clock pulses function correctly.

Note: When in SPI slave mode, the USART must be enabled before the master starts communication (or between frames while the clock is stable). Otherwise, if the USART slave is enabled while the master is in the middle of a frame, it becomes desynchronized with the master. The data register of the slave needs to be ready before the first edge of the communication clock or before the end of the on-going communication, otherwise SPI slave transmits zeros.

SPI slave underrun error

When an underrun error occurs, the SPI slave sends the last data until the underrun error flag is cleared in software.

The underrun flag is set at the beginning of the frame.

The underrun error flag is cleared by setting bit UDRCF in the USART_ICR register.

In underrun condition, it is allowed to write the TDR register. Clearing the underrun error would allow sending the new data.

If an underrun error occurred and there is no new data written in TDR, then the TC flag is set at the end of the frame.

Note: An underrun error may occur if the data is written in the USARTx_TDR too close to the first SCLK transmission edge. To avoid this underrun error, the USART_TDR should be written 3 UCLK cycles before the first SCLK edge.

20.5.13 Single-wire half-duplex communication

Single-wire half-duplex mode is selected by setting the HDSEL bit in the USART_CR3 register. In this mode, the following bits must be kept cleared:

The USART can be configured to follow a single-wire half-duplex protocol where the TX and RX lines are internally connected. The selection between half- and full-duplex communication is made with a control bit HDSEL in USART_CR3.

As soon as HDSEL is written to 1:

Apart from this, the communication protocol is similar to normal USART mode. Any conflicts on the line must be managed by software (by the use of a centralized arbiter, for instance). In particular, the transmission is never blocked by hardware and continues as soon as data are written in the data register while the TE bit is set.

Note: As the TX line and the RX lines are connected together, all the transmitted data are stored in the RX FIFO as the data received from an external device. The software has to take care to discard its “own” information after a transmit phase. In half-duplex mode, it is always wise to read back the transmitted data to check if they are correct as there is no hardware protection against possible collision between nodes. If the software does not want to have the RX FIFO storing the transmitted value then it has to disable the receiver part while transmitting (by clearing the RE bit in USART_CR1 register).

20.5.14 Receiver timeout

The receiver timeout feature is enabled by setting the RTOEN bit in the USART_CR2 control register.

The timeout duration is programmed using the RTO bit fields in the USARTx_RTOR register.

The receiver timeout counter starts counting

When the timeout duration has elapsed, the RTOF flag in the USARTx_ISR register is set and a timeout is generated if RTOIE bit in USARTx_CR1 register is set.

20.5.15 Smartcard mode

This section is relevant only when smartcard mode is supported. Refer to Section 20.4: USART implementation .

Smartcard mode is selected by setting the SCEN bit in the USART_CR3 register. In Smartcard mode, the following bits must be kept cleared:

The CLKEN bit may be set in order to provide a clock to the Smartcard.

The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the ISO 7816-3 standard. Both T=0 (character mode) and T=1 (block mode) are supported.

The USART should be configured as:

In T=0 (character) mode, the parity error is indicated at the end of each character during the Guard Time period.

Figure 129. ISO 7816-3 asynchronous protocol shows examples of what can be seen on the data line with and without parity error.

Figure 129. ISO 7816-3 asynchronous protocol

Timing diagram for ISO 7816-3 asynchronous protocol. It shows two scenarios: 'Without Parity error' and 'With Parity error'. In both, a character is transmitted starting with a Start bit (S), followed by 8 data bits (0-7), and a parity bit (p). A vertical dashed line marks the 'Guard time'. In the 'Without Parity error' case, the line returns to idle after the parity bit. In the 'With Parity error' case, the line is pulled low by the receiver during the stop bit period, as indicated by the text 'Line pulled low by receiver during stop in case of parity error'.
Timing diagram for ISO 7816-3 asynchronous protocol. It shows two scenarios: 'Without Parity error' and 'With Parity error'. In both, a character is transmitted starting with a Start bit (S), followed by 8 data bits (0-7), and a parity bit (p). A vertical dashed line marks the 'Guard time'. In the 'Without Parity error' case, the line returns to idle after the parity bit. In the 'With Parity error' case, the line is pulled low by the receiver during the stop bit period, as indicated by the text 'Line pulled low by receiver during stop in case of parity error'.

When connected to a Smartcard, the TX output of the USART drives a bidirectional line that is also driven by the Smartcard. The TX pin must be configured as open drain.

Smartcard mode implements a single-wire half-duplex communication protocol.

Note: A break character is not significant in smartcard mode. A 0x00 data with a framing error is treated as data and not as a break.

Note: No Idle frame is transmitted when toggling the TE bit. The Idle frame (as defined for the other configurations) is not defined by the ISO protocol.

Figure 130. Parity error detection using 1.5 stop bits details how the NACK signal is sampled by the USART. In this example the USART is transmitting data and is configured with 1.5 stop bits. The receiver part of the USART is enabled in order to check the integrity of the data and the NACK signal.

Figure 130. Parity error detection using 1.5 stop bits Timing diagram for parity error detection using 1.5 stop bits.

The diagram illustrates the timing for parity error detection. It shows a sequence of bits: Bit 7, followed by a Parity bit, and then a 1.5 Stop bit.
- The Parity bit has a duration of '1 bit time'. Sampling occurs at the 8th, 9th, and 10th clock cycles within this bit time.
- The 1.5 Stop bit has a duration of '1.5 bit time'. Sampling also occurs at the 8th, 9th, and 10th clock cycles of the first bit time of the stop bit period.
- A second row shows a '0.5 bit time' offset, followed by another '1.5 bit time' segment for the stop bit, with sampling again at the 8th, 9th, and 10th clock cycles.

Timing diagram for parity error detection using 1.5 stop bits.

The USART can provide a clock to the Smartcard through the SCLK output. In Smartcard mode, SCLK is not associated to the communication but is simply derived from the internal peripheral input clock through a 5-bit prescaler. The division ratio is configured in the prescaler register USART_GTPR. SCLK frequency can be programmed from \( f_{CKPRES}/2 \) to \( f_{CKPRES}/62 \) , where \( f_{CKPRES} \) is the peripheral input clock divided by a programmed prescaler.

Block mode (T=1)

In T=1 (block) mode, the parity error transmission can be deactivated by clearing the NACK bit in the UART_CR3 register.

When requesting a read from the Smartcard, in block mode, the software must program the RTOR register to the BWT (block wait time) - 11 value. If no answer is received from the card before the expiration of this period, a timeout interrupt is generated. If the first character is received before the expiration of the period, it is signaled by the RXNE/RXFNE interrupt.

Note: The RXNE/RXFNE interrupt must be enabled even when using the USART in DMA mode to read from the Smartcard in block mode. In parallel, the DMA must be enabled only after the first received byte.

After the reception of the first character (RXNE/RXFNE interrupt), the RTO register must be programmed to the CWT (character wait time) - 11 value, in order to allow the automatic check of the maximum wait time between two consecutive characters. This time is expressed in baudtime units. If the Smartcard does not send a new character in less than the CWT period after the end of the previous character, the USART signals this to the software through the RTOF flag and interrupt (when RTOIE bit is set).

Note: As in the Smartcard protocol definition, the BWT/CWT values should be defined from the beginning (start bit) of the last character. The RTO register must be programmed to BWT - 11 or CWT - 11, respectively, taking into account the length of the last character itself.

A block length counter is used to count all the characters received by the USART. This counter is reset when the USART is transmitting. The length of the block is communicated by the Smartcard in the third byte of the block (prologue field). This value must be programmed to the BLEN field in the USART_RTOR register. When using DMA mode, before the start of the block, this register field must be programmed to the minimum value (0x0). With this value, an interrupt is generated after the 4th received character. The software must read the LEN field (third byte), its value must be read from the receive buffer.

In interrupt driven receive mode, the length of the block may be checked by software or by programming the BLEN value. However, before the start of the block, the maximum value of BLEN (0xFF) may be programmed. The real value is programmed after the reception of the third character.

If the block is using the LRC longitudinal redundancy check (1 epilogue byte), the BLEN=LEN. If the block is using the CRC mechanism (2 epilog bytes), BLEN=LEN+1 must be programmed. The total block length (including prologue, epilogue and information fields) equals BLEN+4. The end of the block is signaled to the software through the EOBF flag and interrupt (when EOBI bit is set). In case of an error in the block length, the end of the block is signaled by the RTO interrupt (character wait time overflow).

Note: The error checking code (LRC/CRC) must be computed/verified by software.

Direct and inverse convention

The Smartcard protocol defines two conventions: direct and inverse.

The direct convention is defined as: LSB first, logical bit value of 1 corresponds to a H state of the line and parity is even. In order to use this convention, the following control bits must be programmed: MSBFIRST=0, DATAINV=0 (default values).

The inverse convention is defined as: MSB first, logical bit value 1 corresponds to an L state on the signal line and parity is even. In order to use this convention, the following control bits must be programmed: MSBFIRST=1, DATAINV=1.

Note: When logical data values are inverted (0=H, 1=L), the parity bit is also inverted in the same way.

In order to recognize the card convention, the card sends the initial character, TS, as the first character of the ATR (answer to reset) frame. The two possible patterns for the TS are: LHHL LLL LLH and LHHL HHH LLH.

Character parity is correct when there is an even number of bits set to 1 in the nine moments 2 to 10.

As the USART does not know which convention is used by the card, it needs to be able to recognize either pattern and act accordingly. The pattern recognition is not done in hardware, but through a software sequence. Moreover, supposing that the USART is configured in direct convention (default) and the card answers with the inverse convention, TS = LHHL LLL LLH => the USART received character is '03' and the parity is odd.

Therefore, two methods are available for TS pattern recognition:

Method 1

The USART is programmed in standard Smartcard mode/direct convention. In this case, the TS pattern reception generates a parity error interrupt and error signal to the card.

Alternatively, in answer to the parity error interrupt, the software may decide to reprogram the USART and also to generate a new reset command to the card, then wait again for the TS.

Method 2

The USART is programmed in 9-bit/no-parity mode, no bit inversion. In this mode it receives either of the two TS patterns as:

The software checks the received character against these two patterns and, if either of them match, then programs the USART accordingly for the next character reception.

If neither of the two are recognized, a card reset may be generated in order to restart the negotiation.

20.5.16 IrDA SIR ENDEC block

This section is relevant only when IrDA mode is supported. Refer to Section 20.4: USART implementation .

IrDA mode is selected by setting the IREN bit in the USART_CR3 register. In IrDA mode, the following bits must be kept cleared:

The IrDA SIR physical layer specifies use of a return to zero, inverted (RZI) modulation scheme that represents logic 0 as an infrared light pulse (see Figure 131. IrDA SIR ENDEC - block diagram ).

The SIR transmit encoder modulates the non-return-to-zero (NRZ) transmit bit stream output from USART. The output pulse stream is transmitted to an external output driver and infrared LED. USART supports only the bit rates up to 115.2 Kbps for the SIR ENDEC. In normal mode the transmitted pulse width is specified as 3/16 of a bit period.

The SIR receive decoder demodulates the return-to-zero bit stream from the infrared detector and outputs the received NRZ serial bit stream to the USART. The decoder input is normally high (marking state) in the idle state. The transmit encoder output has the opposite polarity to the decoder input. A start bit is detected when the decoder input is low.

IrDA low-power mode

Transmitter

In low-power mode the pulse width is not maintained at 3/16 of the bit period. Instead, the width of the pulse is 3 times the low-power baud rate which can be a minimum of 1.42 MHz. Generally, this value is 1.8432 MHz (1.42 MHz < PSC < 2.12 MHz). A low-power mode programmable divisor divides the system clock to achieve this value.

Receiver:

Receiving in low-power mode is similar to receiving in normal mode. For glitch detection the USART should discard pulses of duration shorter than 1/PSC. A valid low is accepted only if its duration is greater than 2 periods of the IrDA low-power baud clock (PSC value in the USART_GTPR).

Note: A pulse of width less than two and greater than one PSC period(s) may or may not be rejected.

Note: The receiver set-up time should be managed by software. The IrDA physical layer specification specifies a minimum of 10 ms delay between transmission and reception (IrDA is a half-duplex protocol).

Figure 131. IrDA SIR ENDEC - block diagram

Figure 131: IrDA SIR ENDEC - block diagram. The diagram shows a USART block connected to an IrDA SIR ENDEC. The USART has TX, SIREN, and RX pins. The TX pin is connected to an OR gate, which outputs to USART_TX. The SIREN pin is connected to the SIR Transmit Encoder. The RX pin is connected to a multiplexer, which outputs to USART_RX. The SIR Transmit Encoder outputs to IrDA_OUT. The SIR Receive Decoder receives input from IrDA_IN and outputs to the multiplexer.
Figure 131: IrDA SIR ENDEC - block diagram. The diagram shows a USART block connected to an IrDA SIR ENDEC. The USART has TX, SIREN, and RX pins. The TX pin is connected to an OR gate, which outputs to USART_TX. The SIREN pin is connected to the SIR Transmit Encoder. The RX pin is connected to a multiplexer, which outputs to USART_RX. The SIR Transmit Encoder outputs to IrDA_OUT. The SIR Receive Decoder receives input from IrDA_IN and outputs to the multiplexer.

Figure 132. IrDA data modulation (3/16) - normal mode

Figure 132: IrDA data modulation (3/16) - normal mode. This timing diagram shows the relationship between the TX signal, IrDA_OUT, IrDA_IN, and RX signals for a byte with value 0b01010011. The TX signal starts with a Start bit (0) and ends with a Stop bit (1). The IrDA_OUT signal is a modulated version of the TX signal. The IrDA_IN signal is the received modulated signal. The RX signal is the demodulated version of the IrDA_IN signal. The Bit period is indicated, and the 3/16 modulation ratio is shown.
Figure 132: IrDA data modulation (3/16) - normal mode. This timing diagram shows the relationship between the TX signal, IrDA_OUT, IrDA_IN, and RX signals for a byte with value 0b01010011. The TX signal starts with a Start bit (0) and ends with a Stop bit (1). The IrDA_OUT signal is a modulated version of the TX signal. The IrDA_IN signal is the received modulated signal. The RX signal is the demodulated version of the IrDA_IN signal. The Bit period is indicated, and the 3/16 modulation ratio is shown.

20.5.17 Continuous communication using DMA

The USART is capable of performing continuous communication using the DMA. The DMA requests for Rx buffer and Tx buffer are generated independently.

Note: Refer to Section 20.4: USART implementation to determine if the DMA mode is supported. If DMA is not supported, use the USART as explained in Section 20.5.4: Receiver. To perform continuous communication, when FIFO is disabled, you can clear the TXE/ RXNE flags in the USART_ISR register.

Transmission using DMA

DMA mode can be enabled for transmission by setting DMAT bit in the USART_CR3 register. Data are loaded from an SRAM area configured using the DMA peripheral (refer to Section 10: DMA controller (DMA)) to the USART_TDR register whenever the TXE flag (TXFNF flag if FIFO mode is enabled) is set. To map a DMA channel for USART transmission, use the following procedure (x denotes the channel number):

  1. 1. Write the USART_TDR register address in the DMA control register to configure it as the destination of the transfer. The data are moved to this address from memory after each TXE (or TXFNF if FIFO mode is enabled) event.
  2. 2. Write the memory address in the DMA control register to configure it as the source of the transfer. The data are loaded into the USART_TDR register from this memory area after each TXE (or TXFNF if FIFO mode is enabled) event.
  3. 3. Configure the total number of bytes to be transferred to the DMA control register.
  1. 4. Configure the channel priority in the DMA register.
  2. 5. Configure DMA interrupt generation after half/ full transfer as required by the application.
  3. 6. Clear the TC flag in the USART_ISR register by setting the TCCF bit in the USART_ICR register.
  4. 7. Activate the channel in the DMA register.

When the number of data transfers programmed in the DMA controller is reached, the DMA controller generates an interrupt on the DMA channel interrupt vector.

In transmission mode, once the DMA has written all the data to be transmitted (the TCIF flag is set in the DMA_ISR register), the TC flag can be monitored to make sure that the USART communication is complete. This is required to avoid corrupting the last transmission before disabling the USART or entering Deepstop mode. Software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the end of transmission of the last frame.

Figure 133. Transmission using DMA

Timing diagram for USART transmission using DMA showing TX line, TXE flag, DMA request, USART_DR, TC flag, DMA writes, and DMA TCIF flag over three frames (Frame 1, Frame 2, Frame 3).

The diagram illustrates the timing for USART transmission using DMA across three frames (Frame 1, Frame 2, Frame 3) following an idle preamble.

Timing diagram for USART transmission using DMA showing TX line, TXE flag, DMA request, USART_DR, TC flag, DMA writes, and DMA TCIF flag over three frames (Frame 1, Frame 2, Frame 3).

Note: When FIFO management is enabled, the DMA request is triggered by transmit FIFO not full (i.e. TXFNF = 1).

Reception using DMA

DMA mode can be enabled for reception by setting the DMAR bit in USART_CR3 register. Data is loaded from the USART_RDR register to an SRAM area configured using the DMA peripheral (refer to Section 10: DMA controller (DMA) ) whenever a data byte is received. To map a DMA channel for USART reception, use the following procedure:

  1. 1. Write the USART_RDR register address in the DMA control register to configure it as the source of the transfer. The data is moved from this address to the memory after each RXNE (RXFNE in case FIFO mode is enabled) event.
  2. 2. Write the memory address in the DMA control register to configure it as the destination of the transfer. The data is loaded from USART_RDR to this memory area after each RXNE (RXFNE in case FIFO mode is enabled) event.
  3. 3. Configure the total number of bytes to be transferred to the DMA control register.
  4. 4. Configure the channel priority in the DMA control register.
  5. 5. Configure interrupt generation after half/ full transfer as required by the application.
  6. 6. Activate the channel in the DMA control register.

When the number of data transfers programmed in the DMA controller is reached, the DMA controller generates an interrupt on the DMA channel interrupt vector.

Figure 134. Reception using DMA Timing diagram for Figure 134: Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via DMA. The TX line is shown as idle. The RXNE flag is set by hardware when a byte is received and cleared by a DMA read. The DMA request is triggered when the RXNE flag is set. The USART_DR register contains the received bytes F1, F2, and F3. The DMA reads these bytes from the USART_DR register. The DMA TCIF flag (transfer complete) is set by hardware when the transfer is complete and cleared by software. Callouts indicate: 'Software configures the DMA to receive 3 data blocks and enables the USART', 'DMA reads F1 from USART_DR', 'DMA reads F2 from USART_DR', 'DMA reads F3 from USART_DR', and 'The DMA transfer is complete (TCIF=1 in DMA_ISR)'.
Timing diagram for Figure 134: Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via DMA. The TX line is shown as idle. The RXNE flag is set by hardware when a byte is received and cleared by a DMA read. The DMA request is triggered when the RXNE flag is set. The USART_DR register contains the received bytes F1, F2, and F3. The DMA reads these bytes from the USART_DR register. The DMA TCIF flag (transfer complete) is set by hardware when the transfer is complete and cleared by software. Callouts indicate: 'Software configures the DMA to receive 3 data blocks and enables the USART', 'DMA reads F1 from USART_DR', 'DMA reads F2 from USART_DR', 'DMA reads F3 from USART_DR', and 'The DMA transfer is complete (TCIF=1 in DMA_ISR)'.

Note: When FIFO management is enabled, the DMA request is triggered by ReceiveFIFO not empty (i.e. RXFNE = 1).

Error flagging and interrupt generation in multi-buffer communication

In multi-buffer communication if any error occurs during the transaction the error flag is asserted after the current byte. An interrupt is generated if the interrupt enable flag is set. For framing error, overrun error and noise flag which are asserted with RXNE ( RXFNE in case FIFO mode is enabled) in single byte reception, there is a separate error flag interrupt enable bit ( EIE bit in the USART_CR3 register), which, if set, enables an interrupt after the current byte if any of these errors occur.

20.5.18 RS232 hardware flow control and RS485 driver enable

It is possible to control the serial data flow between 2 devices by using the nCTS input and the nRTS output. Figure 135. Hardware flow control between 2 USARTs shows how to connect 2 devices in this mode.

Figure 135. Hardware flow control between 2 USARTs Block diagram for Figure 135: Hardware flow control between 2 USARTs. It shows two USART blocks, USART 1 and USART 2. USART 1 has a TX circuit and an RX circuit. USART 2 also has a TX circuit and an RX circuit. The connections are: USART 1 TX to USART 2 RX; USART 1 nCTS (output) to USART 2 nRTS (input); USART 1 RX to USART 2 TX; and USART 1 nRTS (output) to USART 2 nCTS (input).
Block diagram for Figure 135: Hardware flow control between 2 USARTs. It shows two USART blocks, USART 1 and USART 2. USART 1 has a TX circuit and an RX circuit. USART 2 also has a TX circuit and an RX circuit. The connections are: USART 1 TX to USART 2 RX; USART 1 nCTS (output) to USART 2 nRTS (input); USART 1 RX to USART 2 TX; and USART 1 nRTS (output) to USART 2 nCTS (input).

RS232 RTS and CTS flow control can be enabled independently by writing the RTSE and CTSE bits respectively to 1 (in the USART_CR3 register).

RS232 RTS flow control

If the RTS flow control is enabled (RTSE=1), then nRTS is asserted (tied low) as long as the USART receiver is ready to receive new data. When the receive register is full, nRTS is deasserted, indicating that the transmission is expected to stop at the end of the current frame. Figure 136. RS232 RTS flow control shows an example of communication with RTS flow control enabled.

Figure 136. RS232 RTS flow control Timing diagram for RS232 RTS flow control. The RX line shows two frames: 'Start bit | Data 1 | Stop bit' followed by 'Idle', then 'Start bit | Data 2 | Stop bit'. The nRTS line is initially low. It goes high at the end of the first frame (Stop bit) and returns low at the start of the second frame (Start bit). Labels 'RXNE' with rising edge symbols are at the end of each frame. A label 'Data 1 read' with an arrow points to the falling edge of nRTS, with the text 'Data 2 can now be transmitted' below it.
Timing diagram for RS232 RTS flow control. The RX line shows two frames: 'Start bit | Data 1 | Stop bit' followed by 'Idle', then 'Start bit | Data 2 | Stop bit'. The nRTS line is initially low. It goes high at the end of the first frame (Stop bit) and returns low at the start of the second frame (Start bit). Labels 'RXNE' with rising edge symbols are at the end of each frame. A label 'Data 1 read' with an arrow points to the falling edge of nRTS, with the text 'Data 2 can now be transmitted' below it.

Note: When FIFO mode is enabled, nRTS is de-asserted only when RXFIFO is full.

RS232 CTS flow control

If the CTS flow control is enabled (CTSE=1), then the transmitter checks the nCTS input before transmitting the next frame. If nCTS is asserted (tied low), then the next data is transmitted (assuming that data is to be transmitted, in other words, if TXE/TXFE=0), otherwise the transmission does not occur. When nCTS is deasserted during a transmission, the current transmission is completed before the transmitter stops.

When CTSE=1, the CTSIF status bit is automatically set by hardware as soon as the CTS input toggles. It indicates when the receiver becomes ready or not ready for communication. An interrupt is generated if the CTSIE bit in the USART_CR3 register is set. Figure 137. RS232 CTS flow control shows an example of communication with CTS flow control enabled.

Figure 137. RS232 CTS flow control Timing diagram for RS232 CTS flow control. The nCTS line is initially low. It goes high when Data 3 is written to the TDR and returns low when the transmission of Data 2 is complete. The TDR (Transmit data register) shows 'Data 2' being transmitted, then 'empty', then 'Data 3' being written, then 'empty'. The TX line shows 'Data 1 | Stop bit | Start bit | Data 2 | Stop bit | Idle' followed by 'Start bit | Data 3'. Labels 'CTS' with rising edge symbols are on the nCTS line. A label 'Writing data 3 in TDR' points to the rising edge of nCTS. A label 'Transmission of Data 3 is delayed until nCTS = 0' points to the start of Data 3 transmission.
Timing diagram for RS232 CTS flow control. The nCTS line is initially low. It goes high when Data 3 is written to the TDR and returns low when the transmission of Data 2 is complete. The TDR (Transmit data register) shows 'Data 2' being transmitted, then 'empty', then 'Data 3' being written, then 'empty'. The TX line shows 'Data 1 | Stop bit | Start bit | Data 2 | Stop bit | Idle' followed by 'Start bit | Data 3'. Labels 'CTS' with rising edge symbols are on the nCTS line. A label 'Writing data 3 in TDR' points to the rising edge of nCTS. A label 'Transmission of Data 3 is delayed until nCTS = 0' points to the start of Data 3 transmission.

Note: For correct behavior, nCTS must be asserted at least 3 USART clock source periods before the end of the current character. In addition it should be noted that the CTSCF flag may not be set for pulses shorter than 2 x PCLK periods.

RS485 driver enable

The driver enable feature is enabled by setting bit DEM in the USART_CR3 control register. This allows the user to activate the external transceiver control, through the DE (driver enable) signal. The assertion time is the time between the activation of the DE signal and the beginning of the START bit. It is programmed using the DEAT [4:0] bit fields in the USART_CR1 control register. The de-assertion time is the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE signal. It is programmed using the DEDT [4:0] bit fields in the USART_CR1 control register. The polarity of the DE signal can be configured using the DEP bit in the USART_CR3 control register.

In USART, the DEAT and DEDT are expressed in sample time units (1/8 or 1/16 bit time, depending on the oversampling rate).

20.6 USART interrupts

Table 65. USART interrupt requests

Interrupt eventEvent flagEnable control bit
Transmit data register emptyTXETXEIE
Transmit FIFO not fullTXFNFTXFNFIE
Transmit FIFO emptyTXFETXFEIE
CTS interruptCTSIFCTSIE
Transmission completeTCTCIE
Transmission complete before Guard TimeTCBGTTCBGTIE
Receive data register not empty (data ready to be read)RXNERXNEIE
Receive FIFO not emptyRXFNERXFNEIE
Receive FIFO fullRXFFRXFFIE
Overrun error detectedORERXNEIE/RXF- NEIE
Idle line detectedIDLEIDLEIE
Parity errorPEPEIE
LIN breakLBDFLBDIE
Noise flag, overrun error and framing error in multi-buffer communicationNF or ORE or FEEIE
Character matchCMFCMIE
Receiver timeout errorRTOFRTOIE
End of blockEOBFEOBIE
SPI slave underrun errorUDREIE

These events generate an interrupt if the corresponding enable control bit is set.

20.7 USART registers

Refer to Section 1.5: Acronyms for a list of abbreviations used in register descriptions.

20.7.1 Control register 1 (USARTx_CR1)

Address offset: 0x00

Reset value: 0x0000

31302928272625242322212019181716
RXFFIETXFEIEFIFOENM1EOBIERTOIEDEAT[4:0]DEDT[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
OVER8CMIEMMEM0WAKEPCEPSPEIETXEIE/
TXFNIE
TCIERXNEIE
/RXFNEIE
IDLEIETERERes.UE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bit 31

RXFFIE : RXFIFO full interrupt enable. This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated when RXFF=1 in the USART_ISR register

Note: When FIFO mode is disabled, this bit is reserved and must be kept at reset value.

Bit 30

TXFEIE : TXFIFO empty interrupt enable. This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated when TXFE=1 in the USART_ISR register

Note: When FIFO mode is disabled, this bit is reserved and must be kept at reset value.

Bit 29

FIFOEN : FIFO mode enable.

This bit is set and cleared by software.

0: FIFO mode is disabled

1: FIFO mode is enabled

This bit field can only be written when the USART is disabled (UE=0).

Note: FIFO mode can be used on standard UART communication, in SPI master/slave mode and in smartcard modes only. It must not be enabled in IrDA and LIN modes.

Bit 28

M1 : Word length.

This bit, with bit 12 (M0) determines the word length. It is set or cleared by software.

M[1:0] = 00: 1 Start bit, 8 data bits, n Stop bit

M[1:0] = 01: 1 Start bit, 9 data bits, n Stop bit

M[1:0] = 10: 1 Start bit, 7 Data bits, n Stop bit

This bit can only be written when the USART is disabled (UE=0).

Note: In 7-bits data length mode, the smartcard mode, LIN master mode and auto baud rate (0x7F and 0x55 frames detection) are not supported.

Bit 27

EOBIE : End of block interrupt enable. This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated when the EOBF flag is set in the USART_ISR register

Note: If the USART does not support Smartcard mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 26

RTOIE: Receiver timeout interrupt enable. This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated when the RTOF bit is set in the USART_ISR register

Note: If the USART does not support the Receiver timeout feature, this bit is reserved and forced by hardware to '0'.
Section 20.4: USART implementation.

Bits 25:21

DEAT[4:0]: Driver enable assertion time.

This 5-bit value defines the time between the activation of the DE (driver enable) signal and the beginning of the start bit. It is expressed in sample time units (1/8 or 1/16 bit time, depending on the oversampling rate).

This bit field can only be written when the USART is disabled (UE=0).

Note: If the driver enable feature is not supported, this bit is reserved and must be kept cleared.

Refer to Section 20.4: USART implementation.

Bits 20:16

DEDT[4:0]: Driver enable deassertion time.

This 5-bit value defines the time between the end of the last stop bit, in a transmitted message, and the deactivation of the DE (driver enable) signal. It is expressed in sample time units (1/8 or 1/16 bit time, depending on the oversampling rate).

If the USART_TDR register is written during the DEDT time, the new data is transmitted only when the DEDT and DEAT times have both elapsed.

This bit field can only be written when the USART is disabled (UE=0).

Note: If the driver enable feature is not supported, this bit is reserved and must be kept cleared. Refer to Section 20.4: USART implementation.

Bit 15

OVER8: Oversampling mode.

0: Oversampling by 16

1: Oversampling by 8

This bit can only be written when the USART is disabled (UE=0).

Note: In LIN, IrDA and Smartcard modes, this bit must be kept cleared.

Bit 14

CMIE: Character match interrupt enable. This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated when the CMF bit is set in the USART_ISR register

Bit 13

MME: Mute mode enable.

This bit activates the mute mode function of the USART. When set, the USART can switch between the active and mute modes, as defined by the WAKE bit. It is set and cleared by software.

0: Receiver in active mode permanently

1: Receiver can switch between mute mode and active mode

Bit 12

M0: Word length.

This bit, with bit 28 (M1) determines the word length. It is set or cleared by software.

See bit 28 (M1) description.

This bit can only be written when the USART is disabled (UE=0).

Bit 11

WAKE: Receiver wakeup method.

This bit determines the USART wakeup method from mute mode. It is set or cleared by software.

0: Idle line

1: Address mark

This bit field can only be written when the USART is disabled (UE=0).

Bit 10PCE: Parity control enable.
This bit selects the hardware parity control (generation and detection). When the parity control is enabled, the computed parity is inserted at the MSB position (9 th bit if M=1; 8 th bit if M=0) and parity is checked on the received data. This bit is set and cleared by software. Once it is set, PCE is active after the current byte (in reception and in transmission).
0: Parity control disabled
1: Parity control enabled
This bit field can only be written when the USART is disabled (UE=0).
Bit 9PS: Parity selection.
This bit selects the odd or even parity when the parity generation/detection is enabled (PCE bit set). It is set and cleared by software. The parity is selected after the current byte.
0: Even parity
1: Odd parity
This bit field can only be written when the USART is disabled (UE=0).
Bit 8PEIE: PE interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever PE=1 in the USART_ISR register
Bit 7TXEIE/TXFNFIE: Transmit data register empty/TXFIFO not full interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever TXE/TXFNF=1 in the USART_ISR register
Bit 6TCIE: Transmission complete interrupt enable. This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever TC=1 in the USART_ISR register
Bit 5RXNEIE/RXFNEIE: Receive data register not empty/RXFIFO not empty interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever ORE=1 or RXNE/RXFNE=1 in the USART_ISR register
Bit 4IDLEIE: IDLE interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever IDLE=1 in the USART_ISR register
Bit 3TE: Transmitter enable.
This bit enables the transmitter. It is set and cleared by software.
0: Transmitter is disabled
1: Transmitter is enabled
Note: During transmission, a "0" pulse on the TE bit ("0" followed by "1") sends a preamble (idleline) after the current word, except in Smartcard mode. In order to generate an idle character, the TE must not be immediately written to 1. In order to ensure the required duration, the software can poll the TEACK bit in the USART_ISR register.
In Smartcard mode, when TE is set there is a 1 bit-time delay before the transmission starts.
Bit 2RE: Receiver enable.
This bit enables the receiver. It is set and cleared by software.
0: Receiver is disabled
1: Receiver is enabled and begins searching for a start bit
Bit 1Reserved, must be kept at reset value.
Bit 0

UE: USART enable.

When this bit is cleared, the USART prescalers and outputs are stopped immediately, and current operations are discarded. The configuration of the USART is kept, but all the status flags in the USART_ISR are reset. This bit is set and cleared by software.

0: USART prescaler and outputs disabled, low-power mode
1: USART enabled

Note: In order to go into low-power mode without generating errors on the line, the TE bit must be reset before and the software must wait for the TC bit in the USART_ISR to be set before resetting the UE bit.

The DMA requests are also reset when UE = 0 so the DMA channel must be disabled before resetting the UE bit.

Note: In Smartcard mode, (SCEN = 1), the SCLK is always available when CLKEN = 1, regardless of the UE bit value.

20.7.2 Control register 2 (USARTx_CR2)

Address offset: 0x04

Reset value: 0x0000

31302928272625242322212019181716
ADD[7:4]ADD[3:0]RTOENABRMOD[1:0]ABRENMSBFI RSTDATAINVTXINVRXINV
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SWAPLINENSTOP[1:0]CLKENCPOLCPHALBCLRes.LBDIELBDLADD7DIS_N SS.Res.Res.SLVEN.
rwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:28

ADD[7:4]: Address of the USART node.

This bit-field gives the address of the USART node or a character code to be recognized.

This is used in multiprocessor communication during Mute mode for wakeup with 7-bit address mark detection. The MSB of the character sent by the transmitter should be equal to 1. It may also be used for character detection during normal reception, Mute mode inactive (for example, end of block detection in ModBus protocol). In this case, the whole received character (8-bit) is compared to the ADD[7:0] value and CMF flag is set on match.

This bit field can only be written when reception is disabled (RE=0) or the USART is disabled (UE=0).

Bits 27:24

ADD[3:0]: Address of the USART node.

This bit-field gives the address of the USART node or a character code to be recognized.

This is used in multiprocessor communication during Mute mode, for wakeup with address mark detection.

This bit field can only be written when reception is disabled (RE=0) or the USART is disabled (UE=0).

Bit 23

RTOEN: Receiver timeout enable.

This bit is set and cleared by software. 0: Receiver timeout feature disabled 1: Receiver timeout feature enabled

When this feature is enabled, the RTOF flag in the USART_ISR register is set if the RX line is idle (no reception) for the duration programmed in the RTOR (receiver timeout register).

Note: If the USART does not support the Receiver timeout feature, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 22:21

ABRMOD[1:0]: Auto baud rate mode.

These bits are set and cleared by software.

00: Measurement of the start bit is used to detect the baud rate

01: Falling edge to falling edge measurement (the received frame must start with a single bit = 1 -> Frame = Start10xxxxx)

10: 0x7F frame detection

11: 0x55 frame detection

This bit field can only be written when ABREN=0 or the USART is disabled (UE=0).

Note: If DATAINV=1 and/or MSBFIRST=1 the patterns must be the same on the line, for example 0xAA for MSBFIRST).

If the USART does not support the auto baud rate feature, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 20

ABREN: Auto baud rate enable.

This bit is set and cleared by software. 0: Auto baud rate detection is disabled 1: Auto baud rate detection is enabled

Note: If the USART does not support the auto baud rate feature, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 19

MSBFIRST: Most significant bit first.

This bit is set and cleared by software.

0: Data is transmitted/received with data bit 0 first, following the start bit

1: Data is transmitted/received with the MSB (bit 7/8) first, following the start bit. This bit field can only be written when the USART is disabled (UE=0).

Bit 18

DATAINV: Binary data inversion.

This bit is set and cleared by software.

0: Logical data from the data register are sent/received in positive/direct logic. (1=H, 0=L)

1: Logical data from the data register are sent/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted.

This bit field can only be written when the USART is disabled (UE=0).

Bit 17

TXINV: TX pin active level inversion. This bit is set and cleared by software.

0: TX pin signal works using the standard logic levels (VDD=1/idle, Gnd=0/mark)

1: TX pin signal values are inverted. (VDD=0/mark, Gnd=1/idle). This allows the use of an external inverter on the TX line.

This bit field can only be written when the USART is disabled (UE=0).

Bit 16

RXINV: RX pin active level inversion. This bit is set and cleared by software.

0: RX pin signal works using the standard logic levels (VDD=1/idle, Gnd=0/mark)

1: RX pin signal values are inverted. (VDD=0/mark, Gnd=1/idle). This allows the use of an external inverter on the RX line.

This bit field can only be written when the USART is disabled (UE=0).

Bit 15

SWAP: Swap TX/RX pins.

This bit is set and cleared by software.

0: TX/RX pins are used as defined in standard pinout

1: The TX and RX pins functions are swapped. This helps to work in the case of a cross-wired connection to another UART.

This bit field can only be written when the USART is disabled (UE=0).

Bit 14

LINEN: LIN mode enable.

This bit is set and cleared by software.

0: LIN mode disabled

1: LIN mode enabled

The LIN mode enables the capability to send LIN Synch Breaks (13 low bits) using the SBKRQ bit in the USART_CR1 register, and to detect LIN Sync breaks.

This bit field can only be written when the USART is disabled (UE=0).

Note: If the USART does not support LIN mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bits 13:12

STOP[1:0]: STOP bits.

These bits are used for programming the stop bits.

00: 1 stop bit

01: 0.5 stop bit

10: 2 stop bits

11: 1.5 stop bits

This bit field can only be written when the USART is disabled (UE=0).

Bit 11

CLKEN: Clock enable.

This bit allows the user to enable the SCLK pin.

0: SCLK pin disabled

1: SCLK pin enabled

This bit can only be written when the USART is disabled (UE=0).

Note: If neither synchronous mode nor Smartcard mode is supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Note: In Smartcard mode, in order to provide correctly the SCLK clock to the smartcard, the steps below must be respected:

  • • UE=0
  • • SCEN=1
  • • GTPR configuration
  • • CLKEN=1
  • • UE=1
Bit 10

CPOL: Clock polarity.

This bit allows the user to select the polarity of the clock output on the SCLK pin in synchronous mode. It works in conjunction with the CPHA bit to produce the desired clock/data relationship.

0: Steady low value on SCLK pin outside transmission window

1: Steady high value on SCLK pin outside transmission window

This bit can only be written when the USART is disabled (UE=0).

Note: If synchronous mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

Bit 9

CPHA: Clock phase.

This bit is used to select the phase of the clock output on the SCLK pin in synchronous mode. It works in conjunction with the CPOL bit to produce the desired clock/data relationship (see Figure 119. Data sampling when oversampling by 16 and Figure 120. Data sampling when oversampling by 8 ).

0: The first clock transition is the first data capture edge

1: The second clock transition is the first data capture edge

This bit can only be written when the USART is disabled (UE=0).

Note: If synchronous mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

Bit 8

LBCL: Last bit clock pulse.

This bit is used to select whether the clock pulse associated with the last data bit transmitted (MSB) has to be output on the SCLK pin in synchronous mode.

0: The clock pulse of the last data bit is not output to the SCLK pin

1: The clock pulse of the last data bit is output to the SCLK pin

Caution: The last bit is the 7 th or 8 th or 9 th data bit transmitted depending on the 7 or 8 or 9 bit format selected by the M bit in the USART_CR1 register.

This bit can only be written when the USART is disabled (UE=0).

Note: If synchronous mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

Bit 7

Reserved, must be kept at reset value.

Bit 6

LBDIE: LIN break detection interrupt enable.

Break interrupt mask (break detection using break delimiter).

0: Interrupt is inhibited

1: An interrupt is generated whenever LBDIF=1 in the USART_ISR register

Note: If LIN mode is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 5LBDL: LIN break detection length.
This bit is for selection between 11 bit or 10 bit break detection.
0: 10-bit break detection
1: 11-bit break detection
This bit can only be written when the USART is disabled (UE=0).
Note: If LIN mode is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 4ADD7: 7-bit address detection/4-bit address detection.
This bit is for selection between 4-bit address detection or 7-bit address detection. 0: 4-bit address detection.
1: 7-bit address detection (in 8-bit data mode)
This bit can only be written when the USART is disabled (UE=0).
Note: In 7-bit and 9-bit data modes, the address detection is done on 6-bit and 8-bit address (ADD[5:0] and ADD[7:0]) respectively.
Bit 3DIS_NSS
When the DIS_NSS bit is set, the NSS pin input is ignored.
0: SPI slave selection depends on NSS input pin
1: SPI slave is always selected and NSS input pin is ignored
Note: When SPI slave mode is not supported, this bit is reserved and must be kept at reset value.
Bit 2Reserved, must be kept at reset value.
Bit 1Reserved, must be kept at reset value.
Bit 0SLVEN: Synchronous slave mode enable.
When the SLVEN bit is set, the synchronous slave mode is enabled.
0: Slave mode disabled
1: Slave mode enabled
Note: When SPI slave mode is not supported, this bit is reserved and must be kept at reset value.

Note: The CPOL, CPHA and LBCL bits should not be written while the transmitter is enabled.

20.7.3 Control register 3 (USARTx_CR3)

Address offset: 0x08

Reset value: 0x0000

31302928272625242322212019181716
TXFTCFGRXFTI E.RXFTCFGTCBGT IETXFTIERes.Res.SCARCNT2:0]Res.
rwrwrwrwrwrwrwrw
1514131211109876543210
DEPDEMDDREOVR DISONE BITCTSIECTSERTSEDMATDMARSCENNACKHD SELIRLPIRENEIE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:29TXFTCFG: TXFIFO threshold configuration.
000: TXFIFO reaches 1/8 of its depth
001: TXFIFO reaches 1/4 of its depth
010: TXFIFO reaches 1/2 of its depth
011: TXFIFO reaches 3/4 of its depth. 100:TXFIFO reaches 7/8 of its depth.
101: TXFIFO becomes empty
Remaining combinations: Reserved.
Bit28RXFTIE: RXFIFO threshold interrupt enable. This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated when Receive FIFO reaches the threshold programmed in RXFTCFG
Bits 27:25RXFTCFG: Receive FIFO threshold configuration.
000: Receive FIFO reaches 1/8 of its depth
001: Receive FIFO reaches 1/4 of its depth
010: Receive FIFO reaches 1/2 of its depth
011: Receive FIFO reaches 3/4 of its depth
100: Receive FIFO reaches 7/8 of its depth
101: Receive FIFO becomes full
Remaining combinations: Reserved.
Bit 24TCBGTIE: Transmission complete before Guard Time, interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated whenever TCBGT=1 in the USARTx_ISR register
Note: If the USART does not support the Smartcard mode, this bit is reserved and forced by hardware to '0'.
Bit 23TXFTIE: TXFIFO threshold interrupt enable.
This bit is set and cleared by software.
0: Interrupt is inhibited
1: A USART interrupt is generated when TXFIFO reaches the threshold programmed in TXFTCFG
Bits 22:20Reserved, must be kept at reset value.
Bit 19:17

SCARCNT[2:0]: Smartcard auto-retry count.

This bit-field specifies the number of retries in transmit and receive, in Smartcard mode. In transmission mode, it specifies the number of automatic retransmission retries, before generating a transmission error (FE bit set).

In reception mode, it specifies the number of erroneous reception trials, before generating a reception error (RXNE/RXFNE and PE bits set).

This bit field must be programmed only when the USART is disabled (UE=0).

When the USART is enabled (UE=1), this bit field may only be written to 0x0, in order to stop retransmission.

0x0: Retransmission disabled - No automatic retransmission in transmit mode

0x1 to 0x7: Number of automatic retransmission attempts (before signaling error)

Note: If Smartcard mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

Bit 16

Reserved, must be kept at reset value.

Bit 15

DEP: Driver enable polarity selection.

0: DE signal is active high

1: DE signal is active low

This bit can only be written when the USART is disabled (UE=0).

Note: If the driver enable feature is not supported, this bit is reserved and must be kept cleared. Refer to Section 20.4: USART implementation .

Bit 14

DEM: Driver enable mode.

This bit allows the user to activate the external transceiver control, through the DE signal.

0: DE function is disabled

1: DE function is enabled. The DE signal is output on the RTS pin.

This bit can only be written when the USART is disabled (UE=0).

Note: If the driver enable feature is not supported, this bit is reserved and must be kept cleared. Section 20.4: USART implementation .

Bit 13

DDRE: DMA disable on reception error.

0: DMA is not disabled in case of reception error. The corresponding error flag is set but RXNE is kept 0 preventing from overrun. As a consequence, the DMA request is not asserted, so the erroneous data is not transferred (no DMA request), but next correct received data are transferred (used for Smartcard mode).

1: DMA is disabled following a reception error. The corresponding error flag is set, as well as RXNE. The DMA request is masked until the error flag is cleared. This means that the software must first disable the DMA request (DMAR=0) or clear RXNE (RXFNE in case FIFO mode is enabled) before clearing the error flag.

This bit can only be written when the USART is disabled (UE=0).

Note: The reception errors are: parity error, framing error or noise error.

Bit 12

OVRDIS: Overrun disable.

This bit is used to disable the receive overrun detection.

0: Overrun error flag, ORE, is set when received data is not read before receiving new data

1: Overrun functionality is disabled. If new data is received while the RXNE flag is still set the ORE flag is not set and the new received data overwrites the previous content of the USART_RDR register. When FIFO mode is enabled, the RXFIFO is bypassed and data are written directly in USARTx_RDR register. Even when FIFO management is enabled, the RXNE flag is to be used.

This bit can only be written when the USART is disabled (UE=0).

Note: This control bit allows checking the communication flow w/o reading the data.

Bit 11

ONEBIT: One sample bit method enable.

This bit allows the user to select the sample method. When the one sample bit method is selected the noise detection flag (NF) is disabled.

0: Three sample bit method

1: One sample bit method

This bit can only be written when the USART is disabled (UE=0).

Bit 10

CTSIE : CTS interrupt enable.

0: Interrupt is inhibited

1: An interrupt is generated whenever CTSIF=1 in the USART_ISR register

Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 9

CTSE : CTS enable.

0: CTS hardware flow control disabled

1: CTS mode enabled, data are only transmitted when the nCTS input is asserted (tied to 0). If the nCTS input is deasserted while data is being transmitted, then the transmission is completed before stopping. If data are written into the data register while nCTS is asserted, the transmission is postponed until nCTS is asserted.

This bit can only be written when the USART is disabled (UE=0).

Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 8

RTSE : RTS enable.

0: RTS hardware flow control disabled

1: RTS output enabled, data are only requested when there is space in the receive buffer. The transmission of data is expected to cease after the current character has been transmitted. The nRTS output is asserted (pulled to 0) when data can be received.

This bit can only be written when the USART is disabled (UE=0).

Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 7

DMAT : DMA enable transmitter. This bit is set/reset by software.

1: DMA mode is enabled for transmission

0: DMA mode is disabled for transmission

Bit 6

DMAR : DMA enable receiver. This bit is set/reset by software.

1: DMA mode is enabled for reception

0: DMA mode is disabled for reception

Bit 5

SCEN : Smartcard mode enable.

This bit is used for enabling Smartcard mode.

0: Smartcard mode disabled

1: Smartcard mode enabled

This bit field can only be written when the USART is disabled (UE=0).

Note: If the USART does not support Smartcard mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 4

NACK : Smartcard NACK enable.

0: NACK transmission in case of parity error is disabled

1: NACK transmission during parity error is enabled

This bit field can only be written when the USART is disabled (UE=0).

Note: If the USART does not support Smartcard mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 3

HDSEL : Half-duplex selection.

Selection of single-wire half-duplex mode.

0: Half-duplex mode is not selected

1: Half-duplex mode is selected

This bit can only be written when the USART is disabled (UE=0).

Bit 2IRLP: IrDA low-power.
This bit is used for selecting between normal and low-power IrDA modes.
0: Normal mode
1: Low-power mode
This bit can only be written when the USART is disabled (UE=0).
Note: If IrDA mode is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation
Bit 1IREN: IrDA mode enable.
This bit is set and cleared by software.
0: IrDA disabled
1: IrDA enabled
This bit can only be written when the USART is disabled (UE=0).
Note: If IrDA mode is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 0EIE: Error interrupt enable.
Error interrupt enable bit is required to enable interrupt generation in case of a framing error, overrun error noise flag or SPI slave underrun error (FE=1 or ORE=1 or NF=1 or UDR = 1 in the USART_ISR register).
0: Interrupt is inhibited
1: An interrupt is generated when FE=1 or ORE=1 or NF=1 or UDR = 1 (in SPI slave mode) in the USART_ISR register

20.7.4 Baud rate register (USARTx_BRR)

This register can only be written when the USART is disabled (UE=0). It may be automatically updated by hardware in auto baud rate detection mode.

Address offset: 0x0C

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
BRR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:16Reserved, must be kept at reset value.
Bits 15:4BRR[15:4]
BRR[15:4] = USARTDIV[15:4]
Bits 3:0BRR[3:0]
When OVER8 = 0, BRR[3:0] = USARTDIV[3:0].
When OVER8 = 1:
BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right.
BRR[3] must be kept cleared.

20.7.5 Guard Time and prescaler register (USARTx_GTPR)

Address offset: 0x10

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
GT[7:0]PSC[7:0]
rwrw
BitsDescription
31:16Reserved, must be kept at reset value.
15:8

GT[7:0]: Guard Time value.

This bit-field is used to program the Guard Time value in terms of number of baud clock periods.

This is used in smartcard mode. The transmission complete flag is set after this Guard Time value.

This bit field can only be written when the USART is disabled (UE=0).

Note: If smartcard mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

7:0

PSC[7:0]: Prescaler value.

In IrDA Low-power and normal IrDA mode:

PSC[7:0] = IrDA Normal and Low-Power Baud Rate

Used for programming the prescaler for dividing the USART source clock to achieve the low-power frequency:

The source clock is divided by the value given in the register (8 significant bits):

00000000: Reserved - do not program this value

00000001: Divides the source clock by 1

00000010: Divides the source clock by 2

...

In Smartcard mode:

PSC[4:0]: Prescaler value

Used for programming the prescaler for dividing the USART source clock to provide the Smartcard clock.

The value given in the register (5 significant bits) is multiplied by 2 to give the division factor of the source clock frequency:

00000: Reserved - do not program this value

00001: Divides the source clock by 2

00010: Divides the source clock by 4

00011: Divides the source clock by 6

...

This bit field can only be written when the USART is disabled (UE=0).

Note: Bits [7:5] must be kept cleared if Smartcard mode is used.

This bit field is reserved and forced by hardware to '0' when the Smartcard and IrDA modes are not supported.

Refer to Section 20.4: USART implementation .

20.7.6 Receiver timeout register (USARTx_RTOR)

Address offset: 0x14

Reset value: 0x0000

BLEN[7:0]RTO[23:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
31302928272625242322212019181716
RTO[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Bits
31:24

BLEN[7:0]: Block length.

This bit-field gives the block length in Smartcard T=1 Reception. Its value equals the number of information characters + the length of the epilogue field (1-LEC/2-CRC) - 1.

Examples:

  • BLEN = 0 -> 0 information characters + LEC
  • BLEN = 1 -> 0 information characters + CRC
  • BLEN = 255 -> 254 information characters + CRC (total 256 characters)

In Smartcard mode, the Block length counter is reset when TXE=0 (TXFE=0 in case FIFO mode is enabled).

This bit-field can be used also in other modes. In this case, the Block length counter is reset when RE=0 (receiver disabled) and/or when the EOBCF bit is written to 1.

Note: This value can be programmed after the start of the block reception (using the data from the LEN character in the prologue field). It must be programmed only once per received block.

Bits
23:0

RTO[23:0]: Receiver timeout value.

This bit-field gives the Receiver timeout value in terms of number of baud clocks.

In standard mode, the RTOF flag is set if, after the last received character, no new start bit is detected for more than the RTO value.

In Smartcard mode, this value is used to implement the CWT and BWT. See Smartcard section for more details. In the standard, the CWT/BWT measurement is done starting from the start bit of the last received character.

Note: This value must only be programmed once per received character.

Note: RTOR can be written on the fly. If the new value is lower than or equal to the counter, the RTOF flag is set. This register is reserved and forced by hardware to “0x00000000” when the receiver timeout feature is not supported. Refer to Section 20.4: USART implementation .

20.7.7 Request register (USARTx_RQR)

Address offset: 0x18

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TXFRQRXFRQMMRQSBKRQABRRQ
w_r0w_r0w_r0w_r0w_r0
Bits 31:5Reserved, must be kept at reset value.
Bit 4

TXFRQ: Transmit data flush request.

When FIFO mode is disabled, writing 1 to this bit sets the TXE flag.

This allows the transmit data to be discarded. This bit must be used only in Smartcard mode, when data has not been sent due to errors (NACK) and the FE flag is active in the USART_ISR register. If the USART does not support Smartcard mode, this bit is reserved and forced by hardware to ‘0’.

When FIFO is enabled, TXFRQ bit is set to flush the whole FIFO. This sets the flag TXFE (transmit FIFO empty, bit 23 in the USART_ISR register). Flushing the transmit FIFO is supported in both UART and Smartcard modes.

Note: In FIFO mode, the TXFNF flag is reset during the flush request until TxFIFO is empty in order to ensure that no data is written in the data register.

Bit 3

RXFRQ: Receive data flush request.

Writing 1 to this bit empties the entire receive FIFO, i.e. clears the bit RXFNE.

This allows the received data to be discarded without reading them, and avoid an overrun condition.

Bit 2

MMRQ: Mute mode request.

Writing 1 to this bit puts the USART in mute mode and resets the RWU flag.

Bit 1

SBKRQ: Send break request.

Writing 1 to this bit sets the SBKF flag and requests to send a BREAK on the line, as soon as the transmit machine is available.

Note: In the case the application needs to send the break character following all previously inserted data, including the ones not yet transmitted, the software should wait for the TXE flag assertion before setting the SBKRQ bit.

Bit 0

ABRRQ: Auto baud rate request.

Writing 1 to this bit resets the ABRF flag in the USART_ISR and requests an automatic baud rate measurement on the next received data frame.

Note: If the USART does not support the auto baud rate feature, this bit is reserved and forced by hardware to ‘0’. Refer to Section 20.4: USART implementation .

20.7.8 Interrupt and status register (USARTx_ISR)

Address offset: 0x1C

Reset value: 0x00C0 (in case FIFO disabled).

Reset value: 0x28000C0 (in case FIFO/Smartcard mode enabled).

Reset value: 0x08000C0 (in case FIFO enabled/Smartcard mode disabled).

31302928272625242322212019181716
Res.Res.Res.Res.TXFTRXFTTCBGTRXFFTXFERE ACKTE ACKRes.RWUSBKFCMFBUSY
rrrrrrrrrrr
1514131211109876543210
ABRFABREUDREOBFRTOFCTSCTSIFLBDFTXE/TX FNFTCRXNE/ RXFNEIDLEORENFFEPE
rrrrrrrrrrrrrrrr
Bits 31:28Reserved, must be kept at reset value.
Bit 27

TXFT: TXFIFO threshold flag.

This bit is set by hardware when the TXFIFO reaches the programmed threshold in TXFTCFG in USARTx_CR3 register i.e. the TXFIFO contains TXFTCFG empty locations. An interrupt is generated if the TXFTIE bit = 1 (bit 31) in the USART_CR3 register.

0: TXFIFO doesn't reach the programmed threshold
1: TXFIFO reached the programmed threshold

Bit 26

RXFT: RXFIFO threshold flag.

This bit is set by hardware when the programmed threshold in RXFTCFG in USARTx_CR3 register is reached. This means that there are (RXFTCFG - 1) data in the Receive FIFO and one data in the USART_RDR register. An interrupt is generated if the RXFTIE bit = 1 (bit 27) in the USART_CR3 register.

0: Receive FIFO does not reach the programmed threshold
1: Receive FIFO reached the programmed threshold

Note: When the RXFTCFG threshold is configured to «101», RXFT flag is set if 16 data are available, i.e. 15 data in the RXFIFO and 1 data in the USARTx_RDR. Consequently, the 17 th received data do not cause an overrun error. The overrun error occurs after receiving the 18 th data.

Bit 25

TCBGT: Transmission complete before Guard Time flag.

This bit indicates when the last data written in the USART_TDR has been transmitted correctly out of the shift register.

It is set by hardware in Smartcard mode, if the transmission of a frame containing data is complete and if there is no NACK from the smartcard. An interrupt is generated if TCBGTIE=1 in the USART_CR3 register. It is cleared by software, writing 1 to the TCBGTIF in the USART_ICR register or by a write to the USART_TDR register.

0: Transmission is not complete or transmission is complete unsuccessfully (i.e. a NACK is received from the card)
1: Transmission is complete successfully (before Guard Time completion and there is no NACK from the smart card).

Note: If the USART does not support the Smartcard mode, this bit is reserved and forced by hardware to '0'. If the USART supports the Smartcard mode and the Smartcard mode is enabled, the TCBGT reset value is "1".

Bit 24

RXFF: RXFIFO full.

This bit is set by hardware when RXFIFO is full.

An interrupt is generated if the RXFFIE bit = 1 in the USART_CR1 register.

0: RXFIFO is not full
1: RXFIFO is full

Bit 23TXFE: TXFIFO empty.
This bit is set by hardware when TXFIFO is Empty. When the TXFIFO contains at least one data, this flag is cleared. The TXFE flag can also be set by writing 1 to the bit TXFRQ (bit 4) in the USART_RQR register.
An interrupt is generated if the TXFEIE bit = 1 (bit 30) in the USART_CR1 register.
0: TXFIFO is not empty
1: TXFIFO is empty
Bit 22REACK: Receive enable acknowledge flag.
This bit is set/reset by hardware, when the receive enable value is taken into account by the USART.
It can be used to verify that the USART is ready for reception before entering Deepstop mode.
Note: If the USART does not support the wakeup from Deepstop feature, this bit is reserved and forced by hardware to '0'.
Bit 21TEACK: transmit enable acknowledge flag.
This bit is set/reset by hardware, when the transmit enable value is taken into account by the USART.
It can be used when an idle frame request is generated by writing TE=0, followed by TE=1 in the USART_CR1 register, in order to respect the TE=0 minimum period.
Bit 20Reserved, must be kept at reset value.
Bit 19RWU: Receiver wakeup from Mute mode.
This bit indicates if the USART is in mute mode. It is cleared/set by hardware when a wakeup/mute sequence is recognized. The mute mode control sequence (address or IDLE) is selected by the WAKE bit in the USART_CR1 register.
When wakeup on IDLE mode is selected, this bit can only be set by software, writing 1 to the MMRQ bit in the USART_RQR register.
0: Receiver in active mode
1: Receiver in mute mode
Note: If the USART does not support the wakeup from Deepstop feature, this bit is reserved and forced by hardware to '0'.
Bit 18SBKF: Send break flag.
This bit indicates that a send break character was requested. It is set by software, by writing 1 to the SBKRQ bit in the USART_CR3 register. It is automatically reset by hardware during the stop bit of break transmission.
0: No break character is transmitted
1: Break character is transmitted
Bit 17CMF: Character match flag.
This bit is set by hardware, when the character defined by ADD[7:0] is received. It is cleared by software, writing 1 to the CMCF in the USART_ICR register.
An interrupt is generated if CMIE=1 in the USART_CR1 register.
0: No character match detected
1: Character match detected
Bit 16BUSY: Busy flag.
This bit is set and reset by hardware. It is active when a communication is on-going on the RX line (successful start bit detected). It is reset at the end of the reception (successful or not).
0: USART is idle (no reception)
1: Reception on-going
Bit 15ABRF: Auto baud rate flag.
This bit is set by hardware when the automatic baud rate has been set (RXNE is also set, generating an interrupt if RXNEIE=1) or when the auto baud rate operation was completed without success (ABRE=1) (ABRE, RXNE and FE are also set in this case).
It is cleared by software, in order to request a new auto baud rate detection, by writing 1 to the ABRHQ in the USART_RQR register.
Note: If the USART does not support the auto baud rate feature, this bit is reserved and forced by hardware to '0'.
Bit 14

ABRE: Auto baud rate error.

This bit is set by hardware if the baud rate measurement failed (baud rate out of range or character comparison failed).

It is cleared by software, by writing 1 to the ABRREQ bit in the USART_CR3 register.

Note: If the USART does not support the auto baud rate feature, this bit is reserved and forced by hardware to '0'.

Bit 13

UDR: SPI slave underrun error flag.

In slave transmission mode, this flag is set when the first clock for data transmission appears while the software has not yet loaded any value into USARTx_DR.

0: No underrun error 1: underrun error

Note: If the USART does not support the SPI slave mode, this bit is reserved and forced by hardware to '0'.

Bit 12

EOBF: End of block flag.

This bit is set by hardware when a complete block has been received (for example T=1 Smartcard mode). The detection is done when the number of received bytes (from the start of the block, including the prologue) is equal or greater than BLEN + 4.

An interrupt is generated if the EOBIE=1 in the USART_CR2 register.

It is cleared by software, writing 1 to the EOBCF in the USART_ICR register.

0: End of block not reached

1: End of block (number of characters) reached

Note: If Smartcard mode is not supported, this bit is reserved and forced by hardware to '0'.

Refer to Section 20.4: USART implementation .

Bit 11

RTOF: Receiver timeout.

This bit is set by hardware when the timeout value programmed in the RTOR register has lapsed, without any communication. It is cleared by software, writing 1 to the RTOCF bit in the USART_ICR register.

An interrupt is generated if RTOIE=1 in the USART_CR2 register.

In Smartcard mode, the timeout corresponds to the CWT or BWT timings.

0: Timeout value not reached

1: Timeout value reached without any data reception

Note: If a time equal to the value programmed in RTOR register separates 2 characters, RTOF is not set. If this time exceeds this value + 2 sample times (2/16 or 2/8, depending on the oversampling method), the RTOF flag is set.

The counter counts even if RE=0 but RTOF is set only when RE=1. If the timeout has already elapsed when RE is set, then RTOF is set.

If the USART does not support the receiver timeout feature, this bit is reserved and forced by hardware to '0'.

Bit 10

CTS: CTS flag.

This bit is set/reset by hardware. It is an inverted copy of the status of the nCTS input pin.

0: nCTS line set

1: nCTS line reset

Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'.

Bit 9

CTSIF: CTS interrupt flag.

This bit is set by hardware when the nCTS input toggles, if the CTSE bit is set. It is cleared by software, by writing 1 to the CTSCF bit in the USART_ICR register.

An interrupt is generated if CTSIE=1 in the USART_CR3 register.

0: No change occurred on the nCTS status line

1: A change occurred on the nCTS status line

Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'.

Bit 8

LBDIF: LIN break detection flag.

This bit is set by hardware when the LIN break is detected. It is cleared by software, by writing 1 to the LBDIF in the USART_ICR.

An interrupt is generated if LBDIE=1 in the USART_CR2 register.

0: LIN Break not detected

1: LIN break detected

Note: If the USART does not support LIN mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .

Bit 7

TXE/TXFNF: Transmit data register empty/TXFIFO not full.

When FIFO mode is disabled, TXE is set by hardware when the content of the USARTx_TDR register has been transferred into the shift register. It is cleared by a write to the USARTx_TDR register. The TXE flag can also be set by writing 1 to the TXFRQ in the USART_RQR register, in order to discard the data (only in Smartcard T=0 mode, in case of transmission failure).

When FIFO mode is enabled, TXFNF is set by hardware when TXFIFO is not full, and so data can be written in the USART_TDR. Every write in the USART_TDR places the data in the TXFIFO. This flag remains set until the TXFIFO is full. When the TXFIFO is full, this flag is cleared indicating that data cannot be written into the USART_TDR.

Note: The TXFNF is kept reset during the flush request until TXFIFO is empty . After sending the flush request (by setting TXFRQ bit), the flag TXFNF should be checked prior to writing in TXFIFO. (TXFNF and TXFE are set at the same time).

An interrupt is generated if the TXEIE/TXFNFIE bit = 1 in the USART_CR1 register.

0: Data register is full/transmit FIFO is full

1: Data register/transmit FIFO is not full

Note: This bit is used during single buffer transmission.

Bit 6

TC: Transmission complete

This bit indicates when the last data written in the USART_TDR has been transmitted out of the shift register.

It is set by hardware if the transmission of a frame containing data is complete and if TXE/TXFE is set. An interrupt is generated if TCIE=1 in the USART_CR1 register. It is cleared by software, writing 1 to the TCCF in the USART_ICR register or by a write to the USART_TDR register.

An interrupt is generated if TCIE=1 in the USART_CR1 register.

0: Transmission is not complete

1: Transmission is complete

Note: If TE bit is reset and no transmission is on-going, the TC bit is set immediately.

Bit 5

RXNE/RXFNE: Read data register not empty/RXFIFO not empty.

RXNE bit is set by hardware when the content of the USARTx_RDR shift register has been transferred to the USARTx_RDR register. It is cleared by a read to the USARTx_RDR register. The RXNE flag can also be cleared by writing 1 to the RXFRQ in the USARTx_RQR register. RXFNE bit is set by hardware when the RXFIFO is not empty, and so data can be read from the USART_RDR register. Every read of the USART_RDR frees a location in the RXFIFO. It is cleared when the RXFIFO is empty.

The RXNE/RXFNE flag can also be cleared by writing 1 to the RXFRQ in the USART_RQR register.

An interrupt is generated if RXNEIE/RXFNEIE=1 in the USART_CR1 register.

0: Data is not received

1: Received data is ready to be read

Bit 4

IDLE: Idle line detected.

This bit is set by hardware when an idle line is detected. An interrupt is generated if IDLEIE=1 in the USART_CR1 register. It is cleared by software, writing 1 to the IDLECF in the USART_ICR register.

0: No idle line is detected

1: Idle line is detected

Note: The IDLE bit is not set again until the RXNE bit has been set (i.e. a new idle line occurs).

If mute mode is enabled (MME=1), IDLE is set if the USART is not mute (RWU=0), whatever the mute mode selected by the WAKE bit. If RWU=1, IDLE is not set.

Bit 3

ORE: Overrun error.

This bit is set by hardware when the data currently being received in the shift register is ready to be transferred into the USARTx_RDR register while RXNE=1 (RXFF=1 in case FIFO mode is enabled). It is cleared by a software, writing 1 to the ORECF, in the USARTx_ICR register.

An interrupt is generated if RXNEIE/ RXFNEIE=1 or EIE=1 in the USARTx_CR1 register.

0: No overrun error

1: Overrun error is detected

Note: When this bit is set, the USART_RDR register content is not lost but the shift register is overwritten. An interrupt is generated if the ORE flag is set during multi-buffer communication if the EIE bit is set.

This bit is permanently forced to 0 (no overrun detection) when the bit OVRDIS is set in the USART_CR3 register.

Bit 2

NF: START bit noise detection flag.

This bit is set by hardware when noise is detected on a received frame. It is cleared by software, writing 1 to the NFCF bit in the USART_ICR register.

0: No noise is detected

1: Noise is detected

Note: This bit does not generate an interrupt as it appears at the same time as the RXNE/RXFNE bit which itself generates an interrupt. An interrupt is generated when the NF flag is set during multi-buffer communication if the EIE bit is set.

Note: When the line is noise-free, the NF flag can be disabled by programming the ONEBIT bit to 1 to increase the USART tolerance to deviations (refer to Section 20.5.6: Tolerance of the USART receiver to clock deviation ).

Note: In FIFO mode, this error is associated with the character in the USARTx_RDR.

Bit 1

FE: Framing error.

This bit is set by hardware when a de-synchronization, excessive noise or a break character is detected. It is cleared by software, writing 1 to the FECF bit in the USART_ICR register. In Smartcard mode, in transmission, this bit is set when the maximum number of transmit attempts is reached without success (the card NACKs the data frame).

An interrupt is generated if EIE=1 in the USART_CR1 register.

0: No framing error is detected

1: Framing error or break character is detected

Note: In FIFO mode, this error is associated with the character in the USARTx_RDR.

Bit 0

PE: Parity error.

This bit is set by hardware when a parity error occurs in receiver mode. It is cleared by software, writing 1 to the PECF in the USART_ICR register.

An interrupt is generated if PEIE=1 in the USART_CR1 register.

0: No parity error

1: Parity error

Note: In FIFO mode, this error is associated with the character in the USARTx_RDR.

20.7.9 Interrupt flag clear register (USART_ICR)

Address offset: 0x20

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CMCFRes.
w
1514131211109876543210
Res.Res.UDRCFEOBCFRTOCFRes.CTSCFLBDCFTCBGT CFTCCFTXFEC FIDLECFORECFNECFFECFPECF
wwwwwwwwwwwww
Bits 31:20Reserved, must be kept at reset value.
Bit 19:18Reserved, must be kept at reset value.
Bit 17CMCF : Character match clear flag.
Writing 1 to this bit clears the CMF flag in the USART_ISR register.
Bit 16:14Reserved, must be kept at reset value.
Bit 13UDRCF : SPI slave underrun clear flag.
Writing 1 to this bit clears the UDRF flag in the USART_ISR register.
Note: If the USART does not support SPI slave mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 12EOBCF : End of block clear flag.
Writing 1 to this bit clears the EOBF flag in the USART_ISR register.
Note: If the USART does not support Smartcard mode, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 11RTOCF : Receiver timeout clear flag.
Writing 1 to this bit clears the RTOF flag in the USART_ISR register.
Note: If the USART does not support the receiver timeout feature, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 10Reserved, must be kept at reset value.
Bit 9CTSCF : CTS clear flag.
Writing 1 to this bit clears the CTSIF flag in the USART_ISR register.
Note: If the hardware flow control feature is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 8LBDCF : LIN break detection clear flag.
Writing 1 to this bit clears the LBDF flag in the USART_ISR register.
Note: If LIN mode is not supported, this bit is reserved and forced by hardware to '0'. Refer to Section 20.4: USART implementation .
Bit 7TCBGT CF : Transmission complete before Guard Time clear flag writing 1 to this bit clears the TCBGT flag in the USART_ISR register.
Bit 6TCCF : Transmission complete clear flag writing 1 to this bit clears the TC flag in the USART_ISR register.
Bit 5TXFECF : TXFIFO empty clear flag.
Writing 1 to this bit clears the TXFE flag in the USART_ISR register.
Bit 4IDLECF : Idle line detected clear flag.
Writing 1 to this bit clears the IDLE flag in the USART_ISR register.
Bit 3ORECF : Overrun error clear flag.
Writing 1 to this bit clears the ORE flag in the USART_ISR register.
Bit 2NECF : Noise detected clear flag.
Writing 1 to this bit clears the NF flag in the USART_ISR register.
Bit 1FECF : Framing error clear flag.
Writing 1 to this bit clears the FE flag in the USART_ISR register.
Bit 0PECF : Parity error clear flag.
Writing 1 to this bit clears the PE flag in the USART_ISR register.

20.7.10 Receive data register (USART_RDR)

Address offset: 0x24

Reset value: undefined

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.RDR[8:0]
rrrrrrrrr
Bits 31:9Reserved, must be kept at reset value.
Bits 8:0

RDR[8:0] : Receive data value. Contains the received data character.

The RDR register provides the parallel interface between the input shift register and the internal bus (see Figure 113. USART block diagram).

When receiving with the parity enabled, the value read in the MSB bit is the received parity bit.

20.7.11 Transmit data register (USART_TDR)

Address offset: 0x28

Reset value: undefined

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.TDR[8:0]
rwrwrwrwrwrwrwrwrw
Bits 31:9Reserved, must be kept at reset value.
Bits 8:0

TDR[8:0]: Transmit data value.

Contains the data character to be transmitted.

The USART x _TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 113. USART block diagram ).

When transmitting with the parity enabled (PCE bit set to 1 in the USART_CR1 register), the value written in the MSB (bit 7 or bit 8 depending on the data length) has no effect because it is replaced by the parity.

Note: This register must be written only when TXE/TXFNF=1.

20.7.12 Prescaler register (USARTx_PRESC)

This register can only be written when the USART is disabled (UE=0).

Address offset: 0x2C

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PRESCALER[3:0]
rwrwrwrw
BitsDescription
Bits
31:4
Reserved, must be kept at reset value.
Bits
3:0

PRESCALER[3:0]: Clock prescaler.
The USART input clock can be divided by a prescaler:
0000: Input clock not divided
0001: Input clock divided by 2
0010: Input clock divided by 4
0011: Input clock divided by 6
0100: Input clock divided by 8
0101: Input clock divided by 10
0110: Input clock divided by 12
0111: Input clock divided by 16
1000: Input clock divided by 32
1001: Input clock divided by 64
1010: Input clock divided by 128
1011: Input clock divided by 256
Remaining combinations: Reserved.
Note: When PRESCALER is programmed with a value different to the allowed ones, programmed prescaler value is «1011», i.e. input clock divided by 256.

20.7.13 USART register map

Table 66. USART register map

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00USART_CR1RXFFIERXFEIEFIFOENM1EOBIERTOIERes.DEAT[4:0]DEDT[4:0]OVER8CMIEMMEM0WAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETERERes.UE
Reset value00000000000000000000000000000000
0x04USART_CR2ADD[7:4]ADD[3:0]RTOENABRMOD[1:0]Res.ABRENMSBFIRSTDATAINVTXINVRXINVSWAPLINENSTOP [1:0]CLKENCPOLCPHALBCLRes.LBDIELBDLADD7DIS_NSSRes.Res.SLVEN
Reset value00000000000000000000000000000000
0x08USART_CR3TXFTCFG[2:0]Res.RXFTIERes.RXFTCFG[2:0]TCBGTIETXFTIERes.Res.Res.SCAR CNT[2:0]Res.DEPDEMDDREOVRDISONEBITCTSIECTSERTSEDMATDMARSCENNACKHDSELIRLPIRENEIE
Reset value00000000000000000000000000000000
0x0CUSART_BRRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BRR[15:0]
Reset value0000000000000000
0x10USART_GTPRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.GT[7:0]PSC[7:0]
Reset value0000000000000000
OffsetRegister313029282726252423222120191817161514131211109876543210
0x14USART_RTORBLEN[7:0]RTO[23:0]
Reset value00000000000000000000000000000000
0x18USART_RQRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TXFRQRXFRQMMRQSBKRQABRRQ
Reset value00000
0x1CUSART_ISRRes.Res.Res.Res.Res.Res.Res.Res.Res.REACKTEACKRes.RWUSBKFCMFBUSYABRFABRERes.EOBFRTOFCTSCTSIFLBDFTXETCRXNEIDLEORENFFEPE
Reset value000000000000010000000
0x20USART_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CMCFRes.Res.Res.Res.EOBCFRTOCFRes.CTSCFLBDCFRes.TCCFRes.IDLECFORECFNECFFECFPECF
Reset value00000000000
0x24USART_RDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.RDR[8:0]
Reset value000000000
0x28USART_TDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TDR[8:0]
Reset value000000000
OffsetRegister313029282726252423222120191817161514131211109876543210
0x2CUSART_PRES CRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PRESCALER[3:0]
Reset value0000

Refer to Table 3. STM32WB07xC and STM32WB06xC memory map and peripheral register boundary addresses for the register boundary addresses.

STMicroelectronics logo
STMicroelectronics logo