27. Universal synchronous asynchronous receiver transmitter (USART)

Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.

Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.

High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes.

XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 768 Kbytes and 1 Mbyte.

Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.

This section applies to the whole STM32F10xxx family, unless otherwise specified.

27.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 allows multiprocessor communication.

High speed data communication is possible by using the DMA for multibuffer configuration.

27.2 USART main features

27.3 USART functional description

The interface is externally connected to another device by three pins (see Figure 279 ). Any USART bidirectional communication requires a minimum of two pins: Receive Data In (RX) and Transmit Data Out (TX):

RX: Receive Data Input is the serial data input. Oversampling techniques are used for data recovery by discriminating between valid incoming data and noise.

TX: Transmit Data Output. When the transmitter is disabled, the output pin returns to its IO port configuration. When the transmitter is enabled and nothing is to be transmitted, the TX pin is at high level. In single-wire and smartcard modes, this IO is used to transmit and receive the data (at USART level, data are then received on SW_RX).

Through these pins, serial data is transmitted and received in normal USART mode as frames comprising:

Refer to Section 27.6: USART registers for the definition of each bit.

The following pin is required to interface in synchronous mode:

The following pins are required in Hardware flow control mode:

Figure 279. USART block diagram

Detailed block diagram of the USART showing internal components like registers (TDR, RDR), shift registers, control units, and the baud rate generator. It includes external pins for TX, RX, and flow control, and internal signal paths for data and control.

The diagram illustrates the internal architecture of the USART. At the top, the DATA REGISTER (DR) is shown, consisting of the Transmit Data register (TDR) and the Receive Data register (RDR) . Data is written to the TDR by a (CPU or DMA) and read from the RDR by a (CPU or DMA) . The TDR feeds into the Transmit Shift register , which in turn connects to the IrDA SIR ENDEC BLOCK . The RDR receives data from the Receive Shift register . The IrDA SIR ENDEC BLOCK has pins for TX , RX , and SW_RX . The IrDA SIR ENDEC BLOCK also connects to the TRANSMIT CONTROL and RECEIVER CONTROL blocks. The TRANSMIT CONTROL block has pins for RTS and CTS and connects to the Hardware flow controller . The Hardware flow controller has pins for RTS and CTS . The TRANSMIT CONTROL block also connects to the USART INTERRUPT CONTROL block. The RECEIVER CONTROL block connects to the RECEIVER CLOCK and the USART INTERRUPT CONTROL block. The USART INTERRUPT CONTROL block connects to the TRANSMITTER CLOCK and the CONVENTIONAL BAUD RATE GENERATOR block. The CONVENTIONAL BAUD RATE GENERATOR block contains the TRANSMITTER RATE CONTROL and RECEIVER RATE CONTROL blocks. The TRANSMITTER RATE CONTROL block has pins for TE and DIV_Mantissa (bits 15-4) and DIV_Fraction (bits 3-0). The RECEIVER RATE CONTROL block has pins for RE and DIV_Mantissa (bits 15-4) and DIV_Fraction (bits 3-0). The TRANSMITTER CLOCK is derived from \( f_{PCLKx}(x=1,2) \) and is divided by 16 and then by /USARTDIV . The /USARTDIV is calculated as \( USARTDIV = DIV\_Mantissa + (DIV\_Fraction / 16) \) . The USARTDIV is also used by the TRANSMITTER RATE CONTROL and RECEIVER RATE CONTROL blocks. The CONTROL REGISTERS are shown: CR1 (TXEIE, TCIE, RXNEIE, IDLEIE, TE, RE, RWU, SBK), CR2 (USART Address), CR3 (DMAT, DMAR, SCEN, NACK, HD, IRLP, IREN), and GTPR (GT, PSC). The CR1 register is also shown in the RECEIVER CONTROL block with bits: CTS, LBD, TXE, TC, RXNE, IDLE, ORE, NE, FE, PE. The CK CONTROL block has pins for CK and is controlled by GTPR and CR2 (LINE, STOP[1:0], CKEN, CPOL, CPHA, LBCL).

Detailed block diagram of the USART showing internal components like registers (TDR, RDR), shift registers, control units, and the baud rate generator. It includes external pins for TX, RX, and flow control, and internal signal paths for data and control.

\[ USARTDIV = DIV\_Mantissa + (DIV\_Fraction / 16) \]

27.3.1 USART character description

Word length may be selected as being either 8 or 9 bits by programming the M bit in the USART_CR1 register (see Figure 280).

The TX pin is in low state during the start bit. It is in high state during the stop bit.

An Idle character is interpreted as an entire frame of “1”s followed by the start bit of the next frame which contains data (The number of “1” s will include 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 either 1 or 2 stop bits (logic “1” bit) to acknowledge the start bit.

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 280. Word length programming

Timing diagrams for 9-bit and 8-bit word length USART communication showing data frames, idle frames, and break frames with start, data, parity, and stop bits.

The diagram illustrates the timing for two word lengths: 9-bit and 8-bit, both with 1 stop bit.

9-bit word length (M bit is set), 1 stop bit

8-bit word length (M bit is reset), 1 stop bit

Timing diagrams for 9-bit and 8-bit word length USART communication showing data frames, idle frames, and break frames with start, data, parity, and stop bits.

27.3.2 Transmitter

The transmitter can send data words of either 8 or 9 bits depending on the M bit status. When the transmit enable bit (TE) is set, the data in the transmit shift register is output on the TX pin and the corresponding clock pulses are output on the CK pin.

Character transmission

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

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 should not be reset during transmission of data. Resetting the TE bit during the transmission will corrupt the data on the TX pin as the baud rate counters will get frozen. The current data being transmitted will be lost. An idle frame will be 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.

  1. 1. 1 stop bit: This is the default value.
  2. 2. 2 stop bits: This is supported by normal USART, single-wire and modem modes.
  3. 3. 0.5 stop bit: To be used when receiving data in Smartcard mode.
  4. 4. 1.5 stop bits: To be used when transmitting and receiving data in Smartcard mode.

An idle frame transmission will include the stop bits.

A break transmission will be 10 low bits followed by the configured number of stop bits (when m = 0) and 11 low bits followed by the configured number of stop bits (when m = 1). It is not possible to transmit long breaks (break of length greater than 10/11 low bits).

Figure 281. Configurable stop bits

Timing diagrams for 8-bit word length showing different stop bit configurations: a) 1 Stop Bit, b) 1 1/2 stop Bits, c) 2 Stop Bits, and d) 1/2 Stop Bit. Each diagram shows the Data Frame (Start Bit, Bit0-Bit7, Possible Parity Bit, Stop Bit(s)) and the transition to the Next Data Frame. A CLOCK signal is shown. A note indicates that the ** LBCL bit controls the last data clock pulse.

8-bit Word length (M bit is reset)

The diagram illustrates four timing scenarios for an 8-bit word length (M bit reset) on a USART. Each scenario shows the sequence of bits in a Data Frame and the transition to the Next Data Frame, synchronized with a CLOCK signal.

A CLOCK signal is shown, with a note indicating that the ** LBCL bit controls the last data clock pulse.

Timing diagrams for 8-bit word length showing different stop bit configurations: a) 1 Stop Bit, b) 1 1/2 stop Bits, c) 2 Stop Bits, and d) 1/2 Stop Bit. Each diagram shows the Data Frame (Start Bit, Bit0-Bit7, Possible Parity Bit, Stop Bit(s)) and the transition to the Next Data Frame. A CLOCK signal is shown. A note indicates that the ** LBCL bit controls the last data clock pulse.

Procedure:

  1. 1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
  2. 2. Program the M bit in USART_CR1 to define the word length.
  3. 3. Program the number of stop bits in USART_CR2.
  4. 4. Select DMA enable (DMAT) in USART_CR3 if Multi buffer Communication is to take place. Configure the DMA register as explained in multibuffer communication.
  5. 5. Select the desired baud rate using the USART_BRR register.
  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_DR register (this clears the TXE bit). Repeat this for each data to be transmitted in case of single buffer.
  8. 8. After writing the last data into the USART_DR register, wait until TC=1. This indicates that the transmission of the last frame is complete. This is required for instance when the USART is disabled or enters the Halt mode to avoid corrupting the last transmission.

Single byte communication

The TXE bit is always cleared by a write to the data register.

The TXE bit 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 USART_DR 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 USART_DR register places the data directly in the shift register, the data transmission starts, and the TXE bit is immediately set.

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

After writing the last data into the USART_DR 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 282 ).

The TC bit is cleared by the following software sequence:

  1. 1. A read from the USART_SR register
  2. 2. A write to the USART_DR register

Note: The TC bit can also be cleared by writing a '0' to it. This clearing sequence is recommended only for Multibuffer communication.

Figure 282. TC/TXE behavior when transmitting

Timing diagram showing TX line, TXE flag, USART_DR, and TC flag behavior during frame transmission (Frame 1, Frame 2, Frame 3).

The diagram illustrates the timing of the TX line, TXE flag, USART_DR register, and TC flag during the transmission of three frames (Frame 1, Frame 2, and Frame 3) following an idle preamble.

Software sequence:The diagram is labeled ai17121b.

Timing diagram showing TX line, TXE flag, USART_DR, and TC flag behavior during frame transmission (Frame 1, Frame 2, Frame 3).

Break characters

Setting the SBK bit transmits a break character. The break frame length depends on the M bit (see Figure 280 ).

If the SBK bit is set to '1' a break character is sent on the TX line after completing the current character transmission. This bit is reset by hardware when the break character is completed (during the stop bit of the break character). The USART inserts a logic 1 bit at the end of the last break frame to guarantee the recognition of the start bit of the next frame.

Note: If the software resets the SBK bit before the commencement of break transmission, the break character will not be transmitted. For two consecutive breaks, the SBK bit should be set after the stop bit of the previous break.

Idle characters

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

27.3.3 Receiver

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

Start bit detection

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 0 X 0 0 0 0.

Figure 283. Start bit detection

Timing diagram for start bit detection showing RX state, RX line, Ideal sample clock, Real sample clock, and Conditions to validate the start bit.

The diagram illustrates the start bit detection process. The RX state transitions from Idle to Start bit. The RX line shows a falling edge followed by a low level. Ideal sample clock and Real sample clock are shown as vertical lines. Sampled values are indicated by 'X' marks. The sequence of sampled values is: 1 1 1 0 X 0 X 0 X 0 0 0 0. The first three samples (1 1 1) are used for falling edge detection. The next three samples (0 X 0) are used to validate the start bit (At least 2 bits out of 3 at 0). The final three samples (X 0 X) are also used to validate the start bit (At least 2 bits out of 3 at 0). The sequence continues with 0 0 0 X X X X X X. Timing parameters shown include 7/16, 6/16, and One-bit time.

Timing diagram for start bit detection showing RX state, RX line, Ideal sample clock, Real sample clock, and Conditions to validate the start bit.

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) 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 (RXNE flag set, interrupt generated if RXNEIE=1) but the NE noise flag is set if, for both samplings, at least 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). If this condition is not met, the start detection aborts and the receiver returns to the idle state (no flag is set).

If, 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, the start bit is validated but the NE noise flag bit is set.

Character reception

During a USART reception, data shifts in least significant bit first through the RX pin. In this mode, the USART_DR register consists of a buffer (RDR) between the internal bus and the received shift register.

Procedure:

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

When a character is received

Note: The RE bit should not be reset while receiving data. If the RE bit is disabled during reception, the reception of the current byte will be aborted.

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 a data received 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 can not 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:

Note:

The ORE bit, when set, indicates that at least 1 data has been lost. There are two possibilities:

Noise error

Over-sampling techniques are used (except in synchronous mode) for data recovery by discriminating between valid incoming data and noise.

Figure 284. Data sampling for noise detection

Timing diagram for data sampling for noise detection. It shows the RX LINE and Sample clock signals over time. The RX LINE is a horizontal line with a shaded start and end. The Sample clock is a series of 16 pulses, numbered 1 to 16. The first pulse is at the start of the RX LINE, and the last pulse is at the end. The diagram indicates that the first 7 pulses (1-7) are used for sampling, and the last 6 pulses (11-16) are used for sampling. The time between the start of the RX LINE and the 7th pulse is labeled 7/16. The time between the 7th pulse and the 11th pulse is labeled 6/16. The total time for one bit is labeled One bit time, and the time between the 11th pulse and the end of the RX LINE is labeled 7/16.

The diagram illustrates the timing for data sampling. The RX LINE signal is shown at the top, with a shaded area at the beginning and end. Below it, the Sample clock is shown as a series of 16 pulses, numbered 1 through 16. The first pulse (1) is aligned with the start of the RX LINE, and the last pulse (16) is aligned with the end. A bracket labeled 'sampled values' spans from pulse 8 to 10. Horizontal double-headed arrows indicate time intervals: '7/16' from the start of the RX LINE to the 7th pulse, '6/16' from the 7th pulse to the 11th pulse, and '7/16' from the 11th pulse to the end of the RX LINE. A longer double-headed arrow at the bottom is labeled 'One bit time', spanning from the start of the RX LINE to the end.

Timing diagram for data sampling for noise detection. It shows the RX LINE and Sample clock signals over time. The RX LINE is a horizontal line with a shaded start and end. The Sample clock is a series of 16 pulses, numbered 1 to 16. The first pulse is at the start of the RX LINE, and the last pulse is at the end. The diagram indicates that the first 7 pulses (1-7) are used for sampling, and the last 6 pulses (11-16) are used for sampling. The time between the start of the RX LINE and the 7th pulse is labeled 7/16. The time between the 7th pulse and the 11th pulse is labeled 6/16. The total time for one bit is labeled One bit time, and the time between the 11th pulse and the end of the RX LINE is labeled 7/16.
Table 191. Noise detection from sampled data
Sampled valueNE statusReceived bit valueData validity
00000Valid
00110Not Valid
01010Not Valid
01111Not Valid
10010Not Valid
10111Not Valid
11011Not Valid
11101Valid

When noise is detected in a frame:

The NE bit is reset by a USART_SR register read operation followed by a USART_DR register read operation.

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 a USART_SR register read operation followed by a USART_DR register read operation.

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.

  1. 1. 0.5 stop bit (reception in Smartcard mode): No sampling is done for 0.5 stop bit. As a consequence, no framing error and no break frame can be detected when 0.5 stop bit is selected.
  2. 2. 1 stop bit: Sampling for 1 stop Bit is done on the 8th, 9th and 10th samples.
  3. 3. 1.5 stop bits (Smartcard mode): When transmitting in Smartcard mode, the device must check that the data is correctly sent. Thus the receiver block must be enabled (RE = 1 in the USART_CR1 register) and the stop bit is checked to test if the smartcard has detected a parity error. In the event of a parity error, the smartcard forces the data signal low during the sampling - NACK signal-, which is flagged as a framing error. Then, the FE flag is set with the RXNE at the end of the 1.5 stop bit. Sampling for 1.5 stop bits is done on the 16th, 17th and 18th samples (1 baud clock period after the beginning of the stop bit). The 1.5 stop bit can be decomposed into 2 parts: one 0.5 baud clock period during which nothing happens, followed by 1 normal stop bit period during which sampling occurs halfway through. Refer to Section 27.3.11 for more details.
  4. 4. 2 stop bits: Sampling for 2 stop bits is done on the 8th, 9th and 10th samples of the first stop bit. If a framing error is detected during the first stop bit the framing error flag will be set. The second stop bit is not checked for framing error. The RXNE flag will be set at the end of the first stop bit.

27.3.4 Fractional 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 Mantissa and Fraction values of USARTDIV.

\[ \text{Tx/ Rx baud} = \frac{f_{CK}}{(16 * \text{USARTDIV})} \]

legend: \( f_{CK} \) - Input clock to the peripheral (PCLK1 for USART2, 3, 4, 5 or PCLK2 for USART1)

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

Note: The baud counters are updated with the new value of the Baud registers after a write to USART_BRR. Hence the Baud rate register value should not be changed during communication.

How to derive USARTDIV from USART_BRR register values

Example 1:

If DIV_Mantissa = 0d27 and DIV_Fraction = 0d12 (USART_BRR = 0x1BC), then

Mantissa (USARTDIV) = 0d27

Fraction (USARTDIV) = 12/16 = 0d0.75

Therefore USARTDIV = 0d27.75

Example 2:

To program USARTDIV = 0d25.62

This leads to:

\[ \text{DIV\_Fraction} = 16 * 0d0.62 = 0d9.92 \]

The nearest real number is 0d10 = 0xA

\[ \text{DIV\_Mantissa} = \text{mantissa}(0d25.620) = 0d25 = 0x19 \]

Then, USART_BRR = 0x19A hence USARTDIV = 0d25.625

Example 3:

To program USARTDIV = 0d50.99

This leads to:

\[ \text{DIV\_Fraction} = 16 * 0d0.99 = 0d15.84 \]

The nearest real number is 0d16 = 0x10 => overflow of DIV_frac[3:0] => carry must be added up to the mantissa

\[ \text{DIV\_Mantissa} = \text{mantissa}(0d50.990 + \text{carry}) = 0d51 = 0x33 \]

Then, USART_BRR = 0x330 hence USARTDIV = 0d51.000

Table 192. Error calculation for programmed baud rates

Baud rate\( f_{PCLK} = 36 \text{ MHz} \)\( f_{PCLK} = 72 \text{ MHz} \)
S.Noin KbpsActualValue programmed in the Baud Rate register% Error (1)ActualValue programmed in the Baud Rate register% Error (1)
1.2.42.400937.50%2.418750%
2.9.69.600234.3750%9.6468.750%
3.19.219.2117.18750%19.2234.3750%
4.57.657.639.06250%57.678.1250.0%
5.115.2115.38419.50.15%115.239.06250%
6.230.4230.7699.750.16%230.76919.50.16%
7.460.8461.5384.8750.16%461.5389.750.16%
8.921.6923.0762.43750.16%923.0764.8750.16%
9.2250225010%225020%
10.4500NANANA450010%

1. Defined as (Calculated Baud Rate - Desired Baud Rate) / Desired Baud Rate.

Note: The lower the CPU clock the lower will be the accuracy for a particular Baud rate. The upper limit of the achievable baud rate can be fixed with this data.

Only USART1 is clocked with PCLK2 (72 MHz max). Other USARTs are clocked with PCLK1 (36 MHz max).

27.3.5 USART receiver's tolerance to clock deviation

The USART's asynchronous receiver works correctly only if the total clock system deviation is smaller than the USART receiver tolerance. The causes that contribute to the total deviation are:

\[ DTRA + DQUANT + DREC + DTCL < \text{USART receiver tolerance} \]

The USART receiver tolerance to properly receive data is equal to the maximum tolerated deviation and depends on the following choices:

Table 193. USART receiver tolerance when DIV_Fraction is 0

M bitNF is an errorNF is don't care
03.75%4.375%
13.41%3.97%

Table 194. USART receiver tolerance when DIV_Fraction is different from 0

M bitNF is an errorNF is don't care
03.33%3.88%
13.03%3.53%

Note: The figures specified in Table 193 and Table 194 may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit times when M=0 (11-bit times when M=1).

27.3.6 Multiprocessor communication

There is a possibility of performing multiprocessor communication with the USART (several USARTs connected in a network). For instance, one of the USARTs can be the master, its TX output is connected to the RX input of the other USART. 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 recipient 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 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 RWU bit is written to 1.

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_SR register. RWU can also be written to 0 by software.

An example of mute mode behavior using idle line detection is given in Figure 285 .

Figure 285. Mute mode using Idle line detection

Timing diagram for Idle line detection mute mode. The top part shows the RX line with Data 1, Data 2, Data 3, Data 4, an IDLE period, Data 5, and Data 6. The bottom part shows the RWU bit state: it is written to 1 to enter 'Mute Mode', and it is cleared by hardware when an 'Idle frame detected' occurs, returning to 'Normal Mode'. RXNE flags are shown rising at the start of Data 5 and Data 6.
Timing diagram for Idle line detection mute mode. The top part shows the RX line with Data 1, Data 2, Data 3, Data 4, an IDLE period, Data 5, and Data 6. The bottom part shows the RWU bit state: it is written to 1 to enter 'Mute Mode', and it is cleared by hardware when an 'Idle frame detected' occurs, returning to 'Normal Mode'. RXNE flags are shown rising at the start of Data 5 and Data 6.

Address mark detection (WAKE=1)

In this mode, bytes are recognized as addresses if their MSB is a '1' else they are considered as data. In an address byte, the address of the targeted receiver is put on the 4 LSB. This 4-bit word is compared by the receiver with its own address which is programmed in the ADD bits in the USART_CR2 register.

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 nor DMA request is issued as the USART would have entered mute mode.

It 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 bit is set for the address character since the RWU bit has been cleared.

The RWU bit can be written to as 0 or 1 when the receiver buffer contains no data (RXNE=0 in the USART_SR register). Otherwise the write attempt is ignored.

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

Figure 286. Mute mode using address mark detection

Timing diagram for Figure 286 showing RX and RWU signals. The RX signal shows a sequence of frames: IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. The RWU signal is initially high. When Addr=0 (non-matching) is received, RWU goes low, entering 'Mute Mode'. When Addr=1 (matching) is received, RWU goes high, entering 'Normal Mode'. When Addr=2 (non-matching) is received, RWU goes low again, entering 'Mute Mode'. RXNE flags are shown as pulses above the RX signal at the start of each data frame (Data 1, Data 3, Data 5). A note indicates RWU was written to 1 and RXNE was cleared.

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

Timing diagram for Figure 286 showing RX and RWU signals. The RX signal shows a sequence of frames: IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. The RWU signal is initially high. When Addr=0 (non-matching) is received, RWU goes low, entering 'Mute Mode'. When Addr=1 (matching) is received, RWU goes high, entering 'Normal Mode'. When Addr=2 (non-matching) is received, RWU goes low again, entering 'Mute Mode'. RXNE flags are shown as pulses above the RX signal at the start of each data frame (Data 1, Data 3, Data 5). A note indicates RWU was written to 1 and RXNE was cleared.

27.3.7 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 bit, the possible USART frame formats are as listed in Table 195 .

Table 195. Frame formats (1)
M bitPCE bitUSART frame
00| SB | 8 bit data | STB |
01| SB | 7-bit data | PB | STB |
10| SB | 9-bit data | STB |
11| SB | 8-bit data PB | STB |

1. Legends: SB: Start Bit, STB: Stop Bit, PB: Parity Bit

Note: In case of wake up by an address mark, the MSB bit of the data is taken into account and not the parity bit

Even parity: the parity bit is calculated to obtain an even number of “1s” inside the frame made of the 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.

Ex: data=00110101; 4 bits set => parity bit will be 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 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.

Ex: data=00110101; 4 bits set => parity bit will be 1 if odd parity is selected (PS bit in USART_CR1 = 1).

Transmission mode: 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)). If the parity check fails, the PE flag is set in the USART_SR register and an interrupt is generated if PEIE is set in the USART_CR1 register.

27.3.8 LIN (local interconnection network) mode

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 same procedure explained in Section 27.3.2 has to be applied for LIN Master transmission than for normal USART transmission with the following differences:

LIN reception

A break detection circuit is implemented in the USART. 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 for detecting 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 8th, 9th and 10th 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 LBD flag is set in USART_SR. 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 will be 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 on the Figure 287 . Examples of break frames are given on Figure 288 .

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

Timing diagrams for three cases of break detection in LIN mode. Case 1: break signal not long enough -> break discarded, LBD is not set. Case 2: break signal just long enough -> break detected, LBD is set. Case 3: break signal long enough -> break detected, LBD is set. Each case shows RX line, Capture Strobe, Break State machine, Read Samples, and LBD signal over time.

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

RX lineBreak frame
Capture Strobe|||||||||||
Break State machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read Samples00000000001

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

RX lineBreak frame
Capture Strobe|||||||||||
Break State machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10Idle
Read Samples00000000000
LBDdelimiter is immediate

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

RX lineBreak frame
Capture Strobe|||||||||||
Break State machineIdleBit0Bit1Bit2Bit3Bit4Bit5Bit6Bit7Bit8Bit9Bit10wait delimiterIdle
Read Samples00000000000
LBD
Timing diagrams for three cases of break detection in LIN mode. Case 1: break signal not long enough -> break discarded, LBD is not set. Case 2: break signal just long enough -> break detected, LBD is set. Case 3: break signal long enough -> break detected, LBD is set. Each case shows RX line, Capture Strobe, Break State machine, Read Samples, and LBD signal over time.

Figure 288. Break detection in LIN mode vs. Framing error detection

Timing diagram for Case 1: break occurring after an Idle. The RX line shows a sequence: data 1, IDLE, BREAK (low for 11 bits), data2 (0x55), and data 3 (header). The RXNE / FE signal goes high after data 1, stays high during IDLE, and goes low at the end of the BREAK. The LBD (LIN Break Detection) signal goes high after the BREAK is detected. There is a '1 data time' arrow indicating the duration of the BREAK and the gap between data2 and data3. Timing diagram for Case 1: break occurring while a data is being received. The RX line shows: data 1, data 2, BREAK, data2 (0x55), and data 3 (header). The RXNE / FE signal goes high after data 1 and data 2, then goes low at the end of the BREAK. The LBD signal goes high after the BREAK is detected. '1 data time' arrows indicate the BREAK duration and the gap between data2 and data3.

In these examples, we suppose that LBDL=1 (11-bit break length), M=0 (8-bit data)

Case 1: break occurring after an Idle

Case 1: break occurring while a data is being received

Timing diagram for Case 1: break occurring after an Idle. The RX line shows a sequence: data 1, IDLE, BREAK (low for 11 bits), data2 (0x55), and data 3 (header). The RXNE / FE signal goes high after data 1, stays high during IDLE, and goes low at the end of the BREAK. The LBD (LIN Break Detection) signal goes high after the BREAK is detected. There is a '1 data time' arrow indicating the duration of the BREAK and the gap between data2 and data3. Timing diagram for Case 1: break occurring while a data is being received. The RX line shows: data 1, data 2, BREAK, data2 (0x55), and data 3 (header). The RXNE / FE signal goes high after data 1 and data 2, then goes low at the end of the BREAK. The LBD signal goes high after the BREAK is detected. '1 data time' arrows indicate the BREAK duration and the gap between data2 and data3.

27.3.9 USART synchronous mode

The synchronous 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:

The USART allows the user to control a bidirectional synchronous serial communications in master mode. The CK pin is the output of the USART transmitter clock. No clock pulses are sent to the CK pin during start bit and stop bit. Depending on the state of the LBCL bit in the USART_CR2 register clock pulses will or will not be generated during the last valid data bit (address mark). The CPOL bit in the USART_CR2 register allows the user to select the clock polarity, and the CPHA bit in the USART_CR2 register allows the user to select the phase of the external clock (see Figure 289 , Figure 290 and Figure 291 ).

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

In synchronous mode the USART transmitter works exactly like in asynchronous mode. But as CK 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 CK (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: The CK pin works in conjunction with the TX pin. Thus, the clock is provided only if the transmitter is enabled (TE=1) and a data is being transmitted (the data register USART_DR).

has been written). This means that it is not possible to receive a synchronous data without transmitting data.

The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. These bits should not be changed while the transmitter or the receiver is enabled.

It is advised that TE and RE are set in the same instruction to minimize the setup and the hold time of the receiver.

The USART supports master mode only: it cannot receive or send data related to an input clock (CK is always an output).

Figure 289. USART example of synchronous transmission

Block diagram showing USART connected to a synchronous device (e.g. slave SPI). The USART has RX, TX, and CK pins. The synchronous device has Data out, Data in, and Clock pins. Arrows show data flow from TX to Data in and from Data out to RX. The CK pin is connected to the Clock pin.
Block diagram showing USART connected to a synchronous device (e.g. slave SPI). The USART has RX, TX, and CK pins. The synchronous device has Data out, Data in, and Clock pins. Arrows show data flow from TX to Data in and from Data out to RX. The CK pin is connected to the Clock pin.

Figure 290. USART data clock timing diagram (M=0)

Timing diagram for USART data clock (M=0) showing four clock phases (CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; CPOL=1, CPHA=1). It illustrates the relationship between the clock signal, data on TX (from master), data on RX (from slave), and the capture strobe. The diagram shows 8 data bits (0-7) being transmitted, with the LSB and MSB identified. The last data clock pulse is controlled by the LBCL bit.

The timing diagram illustrates the relationship between the clock signal and data transfer for a master mode (M=0) 8-bit data transfer. It shows four possible clock phases based on CPOL and CPHA settings. The 'Data on TX (from master)' line shows bits 0 through 7 being transmitted, with bit 0 being the LSB and bit 7 being the MSB. The 'Data on RX (from slave)' line shows the same bits being received. The 'Capture Strobe' line is shown for the CPOL=1, CPHA=1 configuration. The last data clock pulse is controlled by the LBCL bit, as indicated by the asterisk (*).

Timing diagram for USART data clock (M=0) showing four clock phases (CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; CPOL=1, CPHA=1). It illustrates the relationship between the clock signal, data on TX (from master), data on RX (from slave), and the capture strobe. The diagram shows 8 data bits (0-7) being transmitted, with the LSB and MSB identified. The last data clock pulse is controlled by the LBCL bit.

Figure 291. USART data clock timing diagram (M=1)

Figure 291. USART data clock timing diagram (M=1). This timing diagram shows the relationship between the Clock signal and the Data signals (TX and RX) for a 9-bit data transmission (M=1). The diagram illustrates four clock phases: CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; and CPOL=1, CPHA=1. The Data on TX (from master) and Data on RX (from slave) are shown as a sequence of 9 bits (0-8). The Capture Strobe is shown as a pulse that occurs at the rising edge of the clock. The diagram also indicates the Start, Stop, and Idle or next transmission states. A note indicates that the LBCL bit controls the last data clock pulse.
Figure 291. USART data clock timing diagram (M=1). This timing diagram shows the relationship between the Clock signal and the Data signals (TX and RX) for a 9-bit data transmission (M=1). The diagram illustrates four clock phases: CPOL=0, CPHA=0; CPOL=0, CPHA=1; CPOL=1, CPHA=0; and CPOL=1, CPHA=1. The Data on TX (from master) and Data on RX (from slave) are shown as a sequence of 9 bits (0-8). The Capture Strobe is shown as a pulse that occurs at the rising edge of the clock. The diagram also indicates the Start, Stop, and Idle or next transmission states. A note indicates that the LBCL bit controls the last data clock pulse.

Figure 292. RX data setup/hold time

Figure 292. RX data setup/hold time. This diagram shows the timing requirements for the RX data signal. The CK (capture strobe on CK rising edge in this example) and Data on RX (from slave) signals are shown. The valid DATA bit is indicated. The setup time (t_SETUP) and hold time (t_HOLD) are defined as 1/16 bit time.
Figure 292. RX data setup/hold time. This diagram shows the timing requirements for the RX data signal. The CK (capture strobe on CK rising edge in this example) and Data on RX (from slave) signals are shown. The valid DATA bit is indicated. The setup time (t_SETUP) and hold time (t_HOLD) are defined as 1/16 bit time.

Note: The function of CK is different in Smartcard mode. Refer to the Smartcard mode section for more details.

27.3.10 Single-wire half-duplex communication

The 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. In single-wire half-duplex mode, the TX and RX pins are connected internally. The selection between half- and full-duplex communication is made with a control bit 'HALF DUPLEX SEL' (HDSEL in USART_CR3).

As soon as HDSEL is written to 1:

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

27.3.11 Smartcard

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

Moreover, 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. The USART should be configured as:

Note: It is also possible to choose 0.5 stop bit for receiving but it is recommended to use 1.5 stop bits for both transmitting and receiving to avoid switching between the two configurations.

Figure 293 shows examples of what can be seen on the data line with and without parity error.

Figure 293. ISO 7816-3 asynchronous protocol

Timing diagram for ISO 7816-3 asynchronous protocol showing 'Without Parity error' and 'With Parity error' scenarios.

The diagram illustrates two timing scenarios for the ISO 7816-3 asynchronous protocol. Both show a sequence of bits: S (Start bit), 0, 1, 2, 3, 4, 5, 6, 7, and P (Parity bit). A vertical dashed line marks the 'Guard time' after the parity bit.

Without Parity error: The signal line is high after the parity bit, indicating a successful transmission.

With Parity error: The signal line is pulled low by the receiver during the stop bit period (after the parity bit), indicating a parity error. The text 'Line pulled low by receiver during stop in case of parity error' is present.

Timing diagram for ISO 7816-3 asynchronous protocol showing 'Without Parity error' and 'With Parity error' scenarios.

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

Smartcard is a single wire half duplex communication protocol.

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

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 294 details how the NACK signal is sampled by the USART. In this example, the USART transmits a 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 294. Parity error detection using the 1.5 stop bits

Timing diagram for parity error detection using 1.5 stop bits. The diagram shows two rows of bit transmission. The top row shows Bit 7, Parity Bit, and 1.5 Stop Bit. The bottom row shows Bit 7, Parity Bit, and 1.5 Stop Bit. Sampling points are indicated by vertical lines and arrows. For the first bit (Bit 7), sampling occurs at the 8th, 9th, and 10th clock cycles. For the Parity Bit, sampling occurs at the 16th, 17th, and 18th clock cycles. For the 1.5 Stop Bit, sampling occurs at the 24th, 25th, and 26th clock cycles. The diagram also shows the bit time (1 bit time) and the stop bit time (1.5 bit time).

The diagram illustrates two scenarios for sampling during the Parity Bit and 1.5 Stop Bit periods.
In the first scenario (top half):
- The Parity Bit is sampled at the 8th, 9th, and 10th clock cycles within its 1 bit time.
- The 1.5 Stop Bit is sampled at the 16th, 17th, and 18th clock cycles within its 1.5 bit time.
In the second scenario (bottom half):
- The Parity Bit is sampled at the 8th, 9th, and 10th clock cycles.
- A 0.5 bit time gap is shown before the next 1 bit time segment.
- The 1.5 Stop Bit is sampled at the 8th, 9th, and 10th clock cycles of the final 1 bit time segment.

Timing diagram for parity error detection using 1.5 stop bits. The diagram shows two rows of bit transmission. The top row shows Bit 7, Parity Bit, and 1.5 Stop Bit. The bottom row shows Bit 7, Parity Bit, and 1.5 Stop Bit. Sampling points are indicated by vertical lines and arrows. For the first bit (Bit 7), sampling occurs at the 8th, 9th, and 10th clock cycles. For the Parity Bit, sampling occurs at the 16th, 17th, and 18th clock cycles. For the 1.5 Stop Bit, sampling occurs at the 24th, 25th, and 26th clock cycles. The diagram also shows the bit time (1 bit time) and the stop bit time (1.5 bit time).

The USART can provide a clock to the smartcard through the CK output. In Smartcard mode, CK 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. CK frequency can be programmed from \( f_{CK}/2 \) to \( f_{CK}/62 \) , where \( f_{CK} \) is the peripheral input clock.

27.3.12 IrDA SIR ENDEC block

The 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 295).

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 bit rates up to 115.2Kbps 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 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\text{ MHz} < \text{PSC} < 2.12\text{ 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/\text{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 USART_GTPR).

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

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 295. IrDA SIR ENDEC- block diagram

Figure 295. IrDA SIR ENDEC- block diagram

The diagram shows the internal architecture of the IrDA SIR ENDEC. A central block labeled 'USART' has three main pins: 'TX' (transmit), 'SIREN' (enable), and 'RX' (receive). The 'TX' pin connects to an 'OR' gate. The 'SIREN' pin connects to a 'SIR Transmit Encoder' block. The 'RX' pin is connected to a multiplexer. The 'OR' gate has two inputs: one from the 'TX' pin and another from the 'SIR Transmit Encoder'. The output of the 'OR' gate is labeled 'USART_TX'. The 'SIR Transmit Encoder' has an output labeled 'IrDA_OUT'. The 'SIR Receive Decoder' block has an input labeled 'IrDA_IN' and an output that connects to the multiplexer. The multiplexer also has an input from the 'USART_RX' pin. The output of the multiplexer is labeled 'RX' and connects back to the 'USART' block.

Figure 295. IrDA SIR ENDEC- block diagram

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

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

The diagram illustrates the IrDA data modulation process for a byte sequence of 0x10011101 (binary: 0 1 0 1 0 0 1 1 0 1). The top waveform, labeled 'TX', shows the digital representation of this byte, starting with a 'Start bit' (0) and ending with a 'stop bit' (1). The middle waveform, labeled 'IrDA_OUT', shows the modulated signal. It is a pulse-width modulated signal where the duration of the high and low pulses corresponds to the bits of the byte. The bottom waveform, labeled 'RX', shows the received digital representation of the byte, which is identical to the transmitted byte (0 1 0 1 0 0 1 1 0 1). A 'bit period' is indicated between the start and stop bits. A '3/16' ratio is indicated between two consecutive rising edges of the IrDA_OUT signal, representing the modulation ratio.

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

27.3.13 Continuous communication using DMA

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

Note: User should refer to product specs for availability of the DMA controller. If DMA is not available in the product, you should use the USART as explained in Section 27.3.2 or 27.3.3 . In the USART_SR register, user can clear the TXE/ RXNE flags to achieve continuous communication.

Transmission using DMA

DMA mode can be enabled for transmission by setting DMAT bit in the USART_CR3 register. Data is loaded from a SRAM area configured using the DMA peripheral (refer to the DMA specification) to the USART_DR register whenever the TXE bit is set. To map a DMA channel for USART transmission, use the following procedure (x denotes the channel number):

  1. 1. Write the USART_DR register address in the DMA control register to configure it as the destination of the transfer. The data will be moved to this address from memory after each TXE event.
  2. 2. Write the memory address in the DMA control register to configure it as the source of the transfer. The data will be loaded into the USART_DR register from this memory area after each TXE 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 register
  5. 5. Configure DMA interrupt generation after half/ full transfer as required by the application.
  6. 6. Clear the TC bit in the SR register by writing 0 to it.
  7. 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 the Stop mode. The software must wait until TC=1. The TC flag remains cleared during all data transfers and it is set by hardware at the last frame's end of transmission.

Figure 297. Transmission using DMA

Timing diagram for Figure 297. Transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, USART_DR register, TC flag, and DMA writes over three frames (Frame 1, Frame 2, Frame 3).

The diagram illustrates the timing for DMA transmission of three frames (F1, F2, F3) over a TX line. It includes the following signals and events:

Sequence of events:

  1. software configures the DMA to send 3 data and enables the USART
  2. DMA writes F1 into USART_DR
  3. DMA writes F2 into USART_DR
  4. DMA writes F3 into USART_DR
  5. The DMA transfer is complete (TCIF=1 in DMA_ISR)
  6. software waits until TC=1

ai17192

Timing diagram for Figure 297. Transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, USART_DR register, TC flag, and DMA writes over three frames (Frame 1, Frame 2, Frame 3).

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_DR register to a SRAM area configured using the DMA peripheral (refer to the DMA specification) whenever a data byte is received. To map a DMA channel for USART reception, use the following procedure:

  1. 1. Write the USART_DR register address in the DMA control register to configure it as the source of the transfer. The data will be moved from this address to the memory after each RXNE event.
  2. 2. Write the memory address in the DMA control register to configure it as the destination of the transfer. The data will be loaded from USART_DR to this memory area after each RXNE event.
  3. 3. Configure the total number of bytes to be transferred in 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 298. Reception using DMA

Timing diagram for Figure 298. Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via USART using DMA. The signals shown are TX line, RXNE flag, DMA request, USART_DR, DMA reads SPI_DR, and DMA TCIF flag. The RXNE flag is set by hardware and cleared by DMA read. The DMA request is generated when the RXNE flag is set. The USART_DR register contains the received data (F1, F2, F3). The DMA reads the data from the USART_DR register. The DMA TCIF flag is set by hardware when the DMA transfer is complete and cleared by software.

The diagram illustrates the timing and sequence of events for DMA reception of three frames (Frame 1, Frame 2, Frame 3) over a TX line. The RXNE flag is set by hardware when a byte is received and cleared by the DMA read. The DMA request is generated when the RXNE flag is set. The USART_DR register contains the received data (F1, F2, F3). The DMA reads the data from the USART_DR register. The DMA TCIF flag is set by hardware when the DMA transfer is complete and cleared by software.

Key events shown in the diagram:

Timing diagram for Figure 298. Reception using DMA. The diagram shows the sequence of events for receiving three frames (Frame 1, Frame 2, Frame 3) via USART using DMA. The signals shown are TX line, RXNE flag, DMA request, USART_DR, DMA reads SPI_DR, and DMA TCIF flag. The RXNE flag is set by hardware and cleared by DMA read. The DMA request is generated when the RXNE flag is set. The USART_DR register contains the received data (F1, F2, F3). The DMA reads the data from the USART_DR register. The DMA TCIF flag is set by hardware when the DMA transfer is complete and cleared by software.

ai17193

Error flagging and interrupt generation in multibuffer communication

In case of multibuffer communication if any error occurs during the transaction the error flag will be asserted after the current byte. An interrupt will be generated if the interrupt enable flag is set. For framing error, overrun error and noise flag which are asserted with RXNE in case of single byte reception, there will be separate error flag interrupt enable bit (EIE bit in the USART_CR3 register), which if set will issue an interrupt after the current byte with either of these errors.

27.3.14 Hardware flow control

It is possible to control the serial data flow between two devices by using the CTS input and the RTS output. Figure 299 shows how to connect two devices in this mode:

Figure 299. Hardware flow control between two USARTs

Diagram showing hardware flow control connection between two USARTs. USART 1's TX circuit is connected to USART 2's RX circuit. USART 1's RX circuit is connected to USART 2's TX circuit. Flow control lines are connected: USART 1's CTS input to USART 2's RTS output, and USART 1's RTS output to USART 2's CTS input.
Diagram showing hardware flow control connection between two USARTs. USART 1's TX circuit is connected to USART 2's RX circuit. USART 1's RX circuit is connected to USART 2's TX circuit. Flow control lines are connected: USART 1's CTS input to USART 2's RTS output, and USART 1's RTS output to USART 2's CTS input.

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

RTS flow control

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

Figure 300. RTS flow control

Timing diagram for RTS flow control. The RX line shows two frames: Start Bit, Data 1, Stop Bit, Idle, Start Bit, Data 2, Stop Bit. The RTS 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 indicate RXNE flags at the start and end of frames, and a note 'Data 1 read Data 2 can now be transmitted' when RTS goes low.
Timing diagram for RTS flow control. The RX line shows two frames: Start Bit, Data 1, Stop Bit, Idle, Start Bit, Data 2, Stop Bit. The RTS 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 indicate RXNE flags at the start and end of frames, and a note 'Data 1 read Data 2 can now be transmitted' when RTS goes low.

CTS flow control

If the CTS flow control is enabled (CTSE=1), then the transmitter checks the CTS input before transmitting the next frame. If CTS is asserted (tied low), then the next data is transmitted (assuming that a data is to be transmitted, in other words, if TXE=0), else the transmission does not occur. When CTS 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. The figure below shows an example of communication with CTS flow control enabled.

Figure 301. CTS flow control

Timing diagram for CTS flow control showing CTS signal, Transmit data register (TDR), and TX line states over time. It illustrates that transmission of Data 3 is delayed until the CTS signal goes low.

The diagram shows three horizontal timelines. The top timeline is the CTS signal, which is initially high, then goes low when Data 2 is being transmitted, and returns high when the TDR becomes empty. The middle timeline is the Transmit data register (TDR), showing Data 2 being transmitted, then the register becoming empty, then Data 3 being written into it, and finally becoming empty again. The bottom timeline is the TX line, showing the transmission of Data 1, then Data 2, then an idle state, and then Data 3. Arrows indicate that the transmission of Data 3 is delayed until the CTS signal goes low again after Data 2 is fully transmitted.

Timing diagram for CTS flow control showing CTS signal, Transmit data register (TDR), and TX line states over time. It illustrates that transmission of Data 3 is delayed until the CTS signal goes low.

27.4 USART interrupts

Table 196. USART interrupt requests

Interrupt eventEvent flagEnable Control bit
Transmit data register emptyTXETXEIE
CTS flagCTSCTSIE
Transmission completeTCTCIE
Received data ready to be readRXNERXNEIE
Overrun error detectedORE
Idle line detectedIDLEIDLEIE
Parity errorPEPEIE
Break flagLBDLBDIE
Noise flag, Overrun error and Framing error in multibuffer communicationNE or ORE or FEEIE (1)

1. This bit is used only when data reception is performed by DMA.

The USART interrupt events are connected to the same interrupt vector (see Figure 302).

These events generate an interrupt if the corresponding Enable Control Bit is set.

Figure 302. USART interrupt mapping diagram

Figure 302. USART interrupt mapping diagram. This logic diagram shows how various USART flags and enable bits are combined to generate a single USART interrupt. The inputs are: TC/TCIE, TXE/TXEIE, CTS/CTSIE, IDLE/IDLEIE, RXNEIE/ORE, RXNEIE/RXNE, PE/PEIE, LBD/LBDIE, and FE/NE/ORE. The first seven pairs are each connected to an AND gate. The outputs of these AND gates are then combined through a series of OR gates. The FE/NE/ORE inputs are first combined via an OR gate, and its output is then ANDed with EIE and DMAR. This result is also combined via an OR gate with the other OR gate outputs to produce the final 'USART interrupt' signal.
Figure 302. USART interrupt mapping diagram. This logic diagram shows how various USART flags and enable bits are combined to generate a single USART interrupt. The inputs are: TC/TCIE, TXE/TXEIE, CTS/CTSIE, IDLE/IDLEIE, RXNEIE/ORE, RXNEIE/RXNE, PE/PEIE, LBD/LBDIE, and FE/NE/ORE. The first seven pairs are each connected to an AND gate. The outputs of these AND gates are then combined through a series of OR gates. The FE/NE/ORE inputs are first combined via an OR gate, and its output is then ANDed with EIE and DMAR. This result is also combined via an OR gate with the other OR gate outputs to produce the final 'USART interrupt' signal.

27.5 USART mode configuration

Table 197. USART mode configuration (1)
USART modesUSART1USART2USART3UART4UART5
Asynchronous modeXXXXX
Hardware Flow ControlXXXNANA
Multibuffer Communication (DMA)XXXXNA
Multiprocessor CommunicationXXXXX
SynchronousXXXNANA
SmartcardXXXNANA
Half-Duplex (Single-Wire mode)XXXXX
IrDAXXXXX
LINXXXXX

1. X = supported; NA = not applicable.

27.6 USART registers

Refer to Section 2.2 on page 45 for a list of abbreviations used in register descriptions.

The peripheral registers can be accessed by half-words (16-bit) or words (32-bit).

27.6.1 Status register (USART_SR)

Address offset: 0x00

Reset value: 0x00C0

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedCTSLBDTXETCRXNEIDLEORENEFE
rc_w0rc_w0rrc_w0rc_w0rrrr

Bits 31:10 Reserved, forced by hardware to 0.

Bit 9 CTS: CTS flag

This bit is set by hardware when the CTS input toggles, if the CTSE bit is set. It is cleared by software (by writing it to 0). An interrupt is generated if CTSIE=1 in the USART_CR3 register.

0: No change occurred on the CTS status line

1: A change occurred on the CTS status line

This bit is not available for UART4 & UART5.

Bit 8 LBD: LIN break detection flag

This bit is set by hardware when the LIN break is detected. It is cleared by software (by writing it to 0). An interrupt is generated if LBDIE = 1 in the USART_CR2 register.

0: LIN Break not detected

1: LIN break detected

Note: An interrupt is generated when LBD=1 if LBDIE=1

Bit 7 TXE: Transmit data register empty

This bit is set by hardware when the content of the TDR register has been transferred into the shift register. An interrupt is generated if the TXEIE bit =1 in the USART_CR1 register. It is cleared by a write to the USART_DR register.

0: Data is not transferred to the shift register

1: Data is transferred to the shift register)

Note: This bit is used during single buffer transmission.

Bit 6 TC: Transmission complete

This bit is set by hardware if the transmission of a frame containing data is complete and if TXE is set. An interrupt is generated if TCIE=1 in the USART_CR1 register. It is cleared by a software sequence (a read from the USART_SR register followed by a write to the USART_DR register). The TC bit can also be cleared by writing a '0' to it. This clearing sequence is recommended only for multibuffer communication.

0: Transmission is not complete

1: Transmission is complete

Bit 5 RXNE: Read data register not empty

This bit is set by hardware when the content of the RDR shift register has been transferred to the USART_DR register. An interrupt is generated if RXNEIE=1 in the USART_CR1 register. It is cleared by a read to the USART_DR register. The RXNE flag can also be cleared by writing a zero to it. This clearing sequence is recommended only for multibuffer communication.

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 the IDLEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Idle Line is detected

1: Idle Line is detected

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

Bit 3 ORE: Overrun error

This bit is set by hardware when the word currently being received in the shift register is ready to be transferred into the RDR register while RXNE=1. An interrupt is generated if RXNEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Overrun error

1: Overrun error is detected

Note: When this bit is set, the RDR register content will not be lost but the shift register will be overwritten. An interrupt is generated on ORE flag in case of Multi Buffer communication if the EIE bit is set.

Bit 2 NE: Noise error flag

This bit is set by hardware when noise is detected on a received frame. It is cleared by a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No noise is detected

1: Noise is detected

Note: This bit does not generate interrupt as it appears at the same time as the RXNE bit which itself generates an interrupting interrupt is generated on NE flag in case of Multi Buffer communication if the EIE bit is set.

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 a software sequence (an read to the USART_SR register followed by a read to the USART_DR register).

0: No Framing error is detected

1: Framing error or break character is detected

Note: This bit does not generate interrupt as it appears at the same time as the RXNE bit which itself generates an interrupt. If the word currently being transferred causes both frame error and overrun error, it will be transferred and only the ORE bit will be set.

An interrupt is generated on FE flag in case of Multi Buffer communication if the EIE bit is set.

Bit 0 PE: Parity error

This bit is set by hardware when a parity error occurs in receiver mode. It is cleared by a software sequence (a read to the status register followed by a read to the USART_DR data register). The software must wait for the RXNE flag to be set before clearing the PE bit.

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

0: No parity error

1: Parity error

27.6.2 Data register (USART_DR)

Address offset: 0x04

Reset value: Undefined

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedDR[8:0]
rwrw

Bits 31:9 Reserved, forced by hardware to 0.

Bits 8:0 DR[8:0] : Data value

Contains the Received or Transmitted data character, depending on whether it is read from or written to.

The Data register performs a double function (read and write) since it is composed of two registers, one for transmission (TDR) and one for reception (RDR)

The TDR register provides the parallel interface between the internal bus and the output shift register (see Figure 1).

The RDR register provides the parallel interface between the input shift register and the internal bus.

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.

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

27.6.3 Baud rate register (USART_BRR)

Note: The baud counters stop counting if the TE or RE bits are disabled respectively.

Address offset: 0x08

Reset value: 0x0000

31302928272625242322212019181716
Reserved
1514131211109876543210
DIV_Mantissa[11:0]DIV_Fraction[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, forced by hardware to 0.

Bits 15:4 DIV_Mantissa[11:0] : mantissa of USARTDIV

These 12 bits define the mantissa of the USART Divider (USARTDIV)

Bits 3:0 DIV_Fraction[3:0] : fraction of USARTDIV

These 4 bits define the fraction of the USART Divider (USARTDIV)

27.6.4 Control register 1 (USART_CR1)

Address offset: 0x0C

Reset value: 0x0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedUEMWAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETERERWUSBK
r/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/w

Bits 31:14 Reserved, forced by hardware to 0.

Bit 13 UE: USART enable

When this bit is cleared the USART prescalers and outputs are stopped and the end of the current

byte transfer in order to reduce power consumption. This bit is set and cleared by software.

0: USART prescaler and outputs disabled

1: USART enabled

Bit 12 M: Word length

This bit determines the word length. It is set or cleared by software.

0: 1 Start bit, 8 Data bits, n Stop bit

1: 1 Start bit, 9 Data bits, n Stop bit

Note: The M bit must not be modified during a data transfer (both transmission and reception)

Bit 11 WAKE: Wakeup method

This bit determines the USART wakeup method, it is set or cleared by software.

0: Idle Line

1: Address Mark

Bit 10 PCE: 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 (9th bit if M=1; 8th 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

Bit 9 PS: 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 will be selected after the current byte.

0: Even parity

1: Odd parity

Bit 8 PEIE: 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_SR register

Bit 7 TXEIE: TXE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: A USART interrupt is generated whenever TXE=1 in the USART_SR register

Bit 6 TCIE: 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_SR register

Bit 5 RXNEIE: RXNE 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=1 in the USART_SR register

Bit 4 IDLEIE: 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_SR register

Bit 3 TE: Transmitter enable

This bit enables the transmitter. It is set and cleared by software.

0: Transmitter is disabled

1: Transmitter is enabled

Note: 1: During transmission, a “0” pulse on the TE bit (“0” followed by “1”) sends a preamble (idle line) after the current word, except in Smartcard mode.

2: When TE is set there is a 1 bit-time delay before the transmission starts.

Bit 2 RE: 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 1 RWU: Receiver wakeup

This bit determines if the USART is in mute mode or not. It is set and cleared by software and can be cleared by hardware when a wakeup sequence is recognized.

0: Receiver in active mode

1: Receiver in mute mode

Note: 1: Before selecting Mute mode (by setting the RWU bit) the USART must first receive a data byte, otherwise it cannot function in Mute mode with wakeup by Idle line detection.

2: In Address Mark Detection wakeup configuration (WAKE bit=1) the RWU bit cannot be modified by software while the RXNE bit is set.

Bit 0 SBK: Send break

This bit set is used to send break characters. It can be set and cleared by software. It should be set by software, and will be reset by hardware during the stop bit of break.

0: No break character is transmitted

1: Break character will be transmitted

27.6.5 Control register 2 (USART_CR2)

Address offset: 0x10

Reset value: 0x0000

31302928272625242322212019181716
Reserved
1514131211109876543210
Res.LINENSTOP[1:0]CLKENCPOLCPHALBCLRes.LBDIELBDLRes.ADD[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:15 Reserved, forced by hardware to 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 Sync Breaks (13 low bits) using the SBK bit in the USART_CR1 register, and to detect LIN Sync breaks.

Bits 13:12 STOP : 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 bit

The 0.5 Stop bit and 1.5 Stop bit are not available for UART4 & UART5.

Bit 11 CLKEN : Clock enable

This bit allows the user to enable the CK pin.

0: CK pin disabled

1: CK pin enabled

This bit is not available for UART4 & UART5.

Bit 10 CPOL : Clock polarity

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

0: Steady low value on CK pin outside transmission window.

1: Steady high value on CK pin outside transmission window.

This bit is not available for UART4 & UART5.

Bit 9 CPHA : Clock phase

This bit allows the user to select the phase of the clock output on the CK pin in synchronous mode. It works in conjunction with the CPOL bit to produce the desired clock/data relationship (see figures 290 to 291)

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

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

This bit is not available for UART4 & UART5.

Bit 8 LBCL : Last bit clock pulse

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

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

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

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

This bit is not available for UART4 & UART5.

Bit 7 Reserved, forced by hardware to 0.

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 LBD=1 in the USART_SR register

Bit 5 LBDL : 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

Bit 4 Reserved, forced by hardware to 0.

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

This bit-field gives the address of the USART node.

This is used in multiprocessor communication during mute mode, for wake up with address mark detection.

Note: These 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.

27.6.6 Control register 3 (USART_CR3)

Address offset: 0x14

Reset value: 0x0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedCTSIECTSERTSEDMATDMARSCENNACKHDSELIRLPIRENEIE
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:11 Reserved, forced by hardware to 0.

Bit 10 CTSIE : CTS interrupt enable

0: Interrupt is inhibited

1: An interrupt is generated whenever CTS=1 in the USART_SR register

This bit is not available for UART4 & UART5.

Bit 9 CTSE : CTS enable

0: CTS hardware flow control disabled

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

This bit is not available for UART4 & UART5.

Bit 8 RTSE : RTS enable

0: RTS hardware flow control disabled

1: RTS interrupt enabled, data is 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 RTS output is asserted (tied to 0) when a data can be received.

This bit is not available for UART4 & UART5.

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

This bit is not available for UART5.

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

This bit is not available for UART5.

Bit 5 SCEN : Smartcard mode enable

This bit is used for enabling Smartcard mode.

0: Smartcard Mode disabled

1: Smartcard Mode enabled

This bit is not available for UART4 & UART5.

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 is not available for UART4 & UART5.

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

Bit 2 IRLP : IrDA low-power

This bit is used for selecting between normal and low-power IrDA modes

0: Normal mode

1: Low-power mode

Bit 1 IREN : IrDA mode enable

This bit is set and cleared by software.

0: IrDA disabled

1: IrDA enabled

Bit 0 EIE : Error interrupt enable

Error Interrupt Enable Bit is required to enable interrupt generation in case of a framing error, overrun error or noise error (FE=1 or ORE=1 or NE=1 in the USART_SR register) in case of Multi Buffer Communication (DMAR=1 in the USART_CR3 register).

0: Interrupt is inhibited

1: An interrupt is generated whenever DMAR=1 in the USART_CR3 register and FE=1 or ORE=1 or NE=1 in the USART_SR register.

27.6.7 Guard time and prescaler register (USART_GTPR)

Address offset: 0x18

Reset value: 0x0000

31302928272625242322212019181716
Reserved
1514131211109876543210
GT[7:0]PSC[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, forced by hardware to 0.

Bits 15:8 GT[7:0] : Guard time value

This bit-field gives the Guard time value in terms of number of baud clocks.

This is used in Smartcard mode. The Transmission Complete flag is set after this guard time value.

This bit is not available for UART4 & UART5.

Bits 7:0 PSC[7:0] : Prescaler value

In IrDA Low-power mode:

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

Used for programming the prescaler for dividing the system 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 normal IrDA mode: PSC must be set to 00000001.

In Smartcard mode:

PSC[4:0] : Prescaler value

Used for programming the prescaler for dividing the system 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

...

Note: Bits [7:5] have no effect if Smartcard mode is used.

This bit is not available for UART4 & UART5.

27.6.8 USART register map

The table below gives the USART register map and reset values.

Table 198. USART register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00USART_SRReservedCTSLBDTXETCRXNEIDLEORENEFEPE
Reset value00011000000
0x04USART_DRReservedDR[8:0]
Reset value00
0x08USART_BRRReservedDIV_Fraction [3:0]
Reset value00
0x0CUSART_CR1ReservedUEMWAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETERERWUSBK
Reset value00000000000000
0x10USART_CR2ReservedADD[3:0]
Reset value00
0x14USART_CR3ReservedCTSE
Reset value00
0x18USART_GTPRReservedPSC[7:0]
Reset value00

Refer to Table 3 on page 50 for the register boundary addresses.