30. Low-power universal asynchronous receiver transmitter (LPUART)

30.1 Introduction

The low-power universal asynchronous receiver transmitter (LPUART) is an UART which allows Full-duplex UART communications with a limited power consumption. Only 32.768 kHz LSE clock is required to allow UART communications up to 9600 baud. Higher baud rates can be reached when the LPUART is clocked by clock sources different from the LSE clock.

Even when the microcontroller is in Stop mode, the LPUART can wait for an incoming UART frame while having an extremely low energy consumption. The LPUART includes all necessary hardware support to make asynchronous serial communications possible with minimum power consumption.

It supports Half-duplex Single-wire communications and Modem operations (CTS/RTS).

It also supports multiprocessor communications.

DMA (direct memory access) can be used for data transmission/reception.

30.2 LPUART main features

30.3 LPUART implementation

The STM32L0x3 devices embed one LPUART. Refer to Section 29.4: USART implementation for LPUART supported features.

Table 148. STM32L0x3 USART/LPUART features (1)
USART modes/featuresUSART1/2USART4USART5LPUART1
Hardware flow control for modemXX-X
Continuous communication using DMAXXXX
Multiprocessor communicationXXXX
Synchronous modeXXX-
Smartcard modeX---
Single-wire Half-duplex communicationXXXX
Ir SIR ENDEC blockX---
LIN modeX---
Dual clock domain and wakeup from Stop modeX--X
Receiver timeout interruptX---
Modbus communicationX---
Auto baud rate detectionX---
Driver EnableXXXX
USART/LPUART data length7 (2) , 8 and 9 bits

1. X = supported.

2. In 7-bit data length mode, Smartcard mode, LIN master mode and Auto baud rate (0x7F and 0x55 frames) detection are not supported.

30.4 LPUART functional description

Any LPUART bidirectional communication requires a minimum of two pins: Receive data In (RX) and Transmit data Out (TX):

This is the serial data input.

When the transmitter is disabled, the output pin returns to its I/O port configuration. When the transmitter is enabled and nothing is to be transmitted, the TX pin is at high level. In Single-wire mode, this I/O is used to transmit and receive the data.

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

Refer to Section 30.7: LPUART registers for the definitions of each bit.

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

The following pin is required in RS485 Hardware control mode:

Note: DE and RTS share the same pin.

Figure 267. LPUART block diagram

LPUART block diagram showing internal components like shift registers, data registers, control registers, and a baud rate generator connected to pins TX, RX, CTS, RTS/DE, and CK.

The block diagram illustrates the internal architecture of the LPUART. At the top, the PRDATA and PWDATA lines connect to a DR (data register) . This register is interfaced with a Transmit shift register (via a 'Read' path from CPU or DMA) and a Receive shift register (via a 'Write' path from CPU or DMA). Below these are the Transmit data register (TDR) and Receive data register (RDR) . The TX pin is connected to the transmit path, and the RX pin is connected to the receive path. A CK (clock) pin is connected to a CK control block, which is configured by the LPUART_GTPR register (containing GT and PSC fields). The RTS/DE/CTS pin is connected to a Hardware flow controller . Control and configuration are managed through several registers: LPUARTx_CR3 , LPUARTx_CR2 , LPUARTx_CR1 , and LPUARTx_BRR . These registers connect to a Transmit control , Wake up unit , and Receiver control block. The Receiver control block also receives a Receiver clock and is connected to the LPUARTx_ISR register and LPUART interrupt control . A Conventional baud rate generator block contains a Transmitter rate controller , BRR[19:0] , and a Receiver rate controller , which are controlled by the LPUARTx_BRR register . The Transmitter clock is derived from \( f_{CK} \) ( \( f_{LSE} \) , \( f_{HSI} \) , \( f_{PCLK} \) or \( f_{SYS} \) ) through a /LPUARTDIV divider. A formula at the bottom left states LPUARTDIV = BRR[19:0] . The diagram is labeled with MSv31884V6 in the bottom right corner.

LPUART block diagram showing internal components like shift registers, data registers, control registers, and a baud rate generator connected to pins TX, RX, CTS, RTS/DE, and CK.

30.4.1 LPUART character description

Word length may be selected as being either 7 or 8 or 9 bits by programming the M[1:0] bits in the LPUART_CR1 register (see Figure 268 ).

By default, 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 268. Word length programming

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

** LBCL bit controls last data clock pulse

MS33194V2

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

30.4.2 LPUART transmitter

The transmitter can send data words of either 7 or 8 or 9 bits depending on the M bits 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.

Character transmission

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

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 LPUART: 1 and 2 stop bits.

Note:

The TE bit must be set before writing the data to be transmitted to the LPUART_TDR.

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.

An idle frame transmission will include the stop bits.

A break transmission will be 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. It is not possible to transmit long breaks (break of length greater than 9/10/11 low bits).

Figure 269. Configurable stop bits

Timing diagrams for 1 and 2 stop bits in LPUART transmission showing bit sequences and clock pulses.

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

a) 1 Stop bit

Data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Possible parity bit, Stop bit. Followed by Next start bit and Next data frame.

CLOCK signal is shown below the data frame. ** LBCL bit controls last data clock pulse.

b) 2 Stop bits

Data frame: Start bit, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Possible parity bit, 2 Stop bits. Followed by Next start bit and Next data frame.

MS31885V1

Timing diagrams for 1 and 2 stop bits in LPUART transmission showing bit sequences and clock pulses.

Character transmission procedure

  1. 1. Program the M bits in LPUART_CR1 to define the word length.
  2. 2. Select the desired baud rate using the LPUART_BRR register.
  3. 3. Program the number of stop bits in LPUART_CR2.
  4. 4. Enable the LPUART by writing the UE bit in LPUART_CR1 register to 1.
  5. 5. Select DMA enable (DMAT) in LPUART_CR3 if multibuffer Communication is to take place. Configure the DMA register as explained in multibuffer communication.
  6. 6. Set the TE bit in LPUART_CR1 to send an idle frame as first transmission.
  7. 7. Write the data to send in the LPUART_TDR 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 LPUART_TDR register, wait until TC=1. This indicates that the transmission of the last frame is complete. This is required for instance when the LPUART is disabled or enters the Halt mode to avoid corrupting the last transmission.

Single byte communication

Clearing the TXE bit is always performed by a write to the transmit 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 LPUART_TDR register stores the data in the TDR register; next, the data is copied in the shift register at the end of the currently ongoing transmission.

When no transmission is taking place, a write instruction to the LPUART_TDR register places the data in the shift register, the data transmission starts, and the TXE bit is 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 LPUART_CR1 register.

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

Figure 270. TC/TXE behavior when transmitting

Timing diagram showing TX line, TXE flag, LPUART_DR, and TC flag signals during transmission of three frames (Frame 1, Frame 2, Frame 3) after an idle preamble. The diagram illustrates the software interaction with the TXE and TC flags to manage data writing into the DR register.

The diagram illustrates the timing and flag behavior for transmitting three frames (Frame 1, Frame 2, Frame 3) following an idle preamble. The signals shown are TX line, TXE flag, LPUART_DR, and TC flag.

Software interaction:

MSv31889V1

Timing diagram showing TX line, TXE flag, LPUART_DR, and TC flag signals during transmission of three frames (Frame 1, Frame 2, Frame 3) after an idle preamble. The diagram illustrates the software interaction with the TXE and TC flags to manage data writing into the DR register.

Break characters

Setting the SBKRQ bit transmits a break character. The break frame length depends on the M bits (see Figure 268).

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 LPUART 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.

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.

Idle characters

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

30.4.3 LPUART receiver

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

Start bit detection

In LPUART, for START bit detection, a falling edge should be detected first on the Rx line, then a sample is taken in the middle of the start bit to confirm that it is still '0'. If the start sample is at '1', then the noise error flag (NF) is set, then the START bit is discarded and the receiver waits for a new START bit. Else, the receiver continues to sample all incoming bits normally.

Character reception

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

Character reception procedure

  1. 1. Program the M bits in LPUART_CR1 to define the word length.
  2. 2. Select the desired baud rate using the baud rate register LPUART_BRR
  3. 3. Program the number of stop bits in LPUART_CR2.
  4. 4. Enable the LPUART by writing the UE bit in LPUART_CR1 register to 1.
  5. 5. Select DMA enable (DMAR) in LPUART_CR3 if multibuffer communication is to take place. Configure the DMA register as explained in multibuffer communication.
  6. 6. Set the RE bit LPUART_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 LPUART 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 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:

Selecting the clock source

The choice of the clock source is done through the Reset and Clock Control system (RCC). The clock source must be chosen before enabling the LPUART (by setting the UE bit).

The choice of the clock source must be done according to two criteria:

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

When the dual clock domain and the wakeup from Stop mode features are supported, the clock source can be one of the following sources: \( f_{PCLK} \) (default), \( f_{LSE} \) , \( f_{HSI} \) or \( f_{SYS} \) . Otherwise, the LPUART clock source is \( f_{PCLK} \) .

Choosing \( f_{LSE} \) , \( f_{HSI} \) as clock source may allow the LPUART to receive data while the MCU is in low-power mode. Depending on the received data and wakeup mode selection, the LPUART wakes up the MCU, when needed, in order to transfer the received data by software reading the LPUART_RDR register or by DMA.

For the other clock sources, the system must be active in order to allow LPUART communication.

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

The receiver samples each incoming bit as close as possible to the middle of the bit-period. Only a single sample is taken of each of the incoming bit.

Note: There is no noise detection for data.

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 LPUART_ICR register.

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.

30.4.4 LPUART 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 LPUART_BRR register.

\[ \text{Tx/Rx baud} = \frac{256 \times f_{\text{CK}}}{\text{LPUARTDIV}} \]

LPUARTDIV is coded on the LPUART_BRR register.

Note: The baud counters are updated to the new value in the baud registers after a write operation to LPUART_BRR. Hence the baud rate register value should not be changed during communication.

It is forbidden to write values less than 0x300 in the LPUART_BRR register.

f ck must be in the range [3 x baud rate, 4096 x baud rate].

The maximum baud rate that can be reached when the LPUART clock source is the LSE, is 9600 baud. Higher baud rates can be reached when the LPUART is clocked by clock sources different than the LSE clock. For example, if the USART clock source is the system clock (maximum is 32 MHz), the maximum baud rate that can be reached is 10 Mbaud.

Table 149. Error calculation for programmed baud rates at\( f_{ck} = 32.768 \) kHz
Baud rate\( f_{ck} = 32.768 \) kHz
S.NoDesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rate
1300 baud300 baud0x6D3A0
2600 baud600 baud0x369D0
31200 baud1200.087 baud0x1B4E0.007
42400 baud2400.17 baud0xDA70.007
54800 baud4801.72 baud0x6D30.035
69600 baud9608.94 baud0x3690.093
Table 150. Error calculation for programmed baud rates at\( f_{ck} = 32 \) MHz
Baud rate\( f_{ck} = 32.768 \) kHz
DesiredActualValue programmed in the baud rate register
DesiredActualValue programmed in the baud rate register% Error = (Calculated - Desired) B.rate / Desired B.rate
9600 baud9608.94 baudD05550.00004
1920019200,030682AA0,0001
3840038400,06341550,0001
5760057600,0922B8E0,0001
115200115200,18115C70,0001
230400230403,608AE30,0015
460800460820,1645710,004
921600921692,1722B80,01
40000004000000,008000
1000000010002442,003330,024

30.4.5 Tolerance of the LPUART receiver to clock deviation

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

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

where

DWU is the error due to sampling point deviation when the wakeup from Stop mode is used.

when M[1:0] = 01:

\[ DWU = \frac{t_{\text{WULPUART}}}{11 \times T_{\text{bit}}} \]

when M[1:0] = 00:

\[ DWU = \frac{t_{\text{WULPUART}}}{10 \times T_{\text{bit}}} \]

when M[1:0] = 10:

\[ DWU = \frac{t_{\text{WULPUART}}}{9 \times T_{\text{bit}}} \]

\( t_{\text{WULPUART}} \) is the time between:

\( t_{\text{WULPUART}} \) corresponds to \( t_{\text{WUSTOP}} \) value provided in the datasheet.

The LPUART receiver can receive data correctly up to the maximum tolerated deviation specified in Table 151 :

Table 151. Tolerance of the LPUART receiver

M bits\( 768 \leq \text{BRR} < 1024 \)\( 1024 \leq \text{BRR} < 2048 \)\( 2048 \leq \text{BRR} < 4096 \)\( 4096 \leq \text{BRR} \)
8 bits (M=00), 1 stop bit1.82%2.56%3.90%4.42%
9 bits (M=01), 1 stop bit1.69%2.33%2.53%4.14%
7 bits (M=10), 1 stop bit2.08%2.86%4.35%4.42%

Table 151. Tolerance of the LPUART receiver (continued)

M bits768 ≤ BRR < 10241024 ≤ BRR < 20482048 ≤ BRR < 40964096 ≤ BRR
8 bits (M=00), 2 stop bit2.08%2.86%4.35%4.42%
9 bits (M=01), 2 stop bit1.82%2.56%3.90%4.42%
7 bits (M=10), 2stop bit2.34%3.23%4.92%4.42%

Note: The data specified in Table 151 may slightly differ in the special case when the received frames contain some Idle frames of exactly 10-bit durations when M bits = 00 (11-bit durations when M bits = 01 or 9- bit durations when M bits = 10).

30.4.6 Multiprocessor communication using LPUART

It is possible to perform multiprocessor communication with the LPUART (with several LPUARTs connected in a network). For instance one of the LPUARTs can be the master, its TX output connected to the RX inputs of the other LPUARTs. 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 LPUART 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 LPUART_CR1 register.

In mute mode:

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

Idle line detection (WAKE=0)

The LPUART 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 LPUART_ISR register. An example of mute mode behavior using Idle line detection is given in Figure 249.

Figure 271. Mute mode using Idle line detection

Timing diagram for Figure 271. The RX line shows a sequence of Data 1, Data 2, Data 3, Data 4, IDLE, Data 5, and Data 6. The RWU line is initially low. When MMRQ is written to 1, the RWU line goes high, entering 'Mute mode'. Upon detection of an IDLE frame, the RWU line goes low, returning to 'Normal mode'. RXNE flags are shown rising at the start of Data 5 and Data 6.

The diagram illustrates the timing for mute mode using idle line detection. The RX line shows a sequence of Data 1, Data 2, Data 3, Data 4, IDLE, Data 5, and Data 6. The RWU line is initially low. When MMRQ is written to 1, the RWU line goes high, entering 'Mute mode'. Upon detection of an IDLE frame, the RWU line goes low, returning to 'Normal mode'. RXNE flags are shown rising at the start of Data 5 and Data 6.

Timing diagram for Figure 271. The RX line shows a sequence of Data 1, Data 2, Data 3, Data 4, IDLE, Data 5, and Data 6. The RWU line is initially low. When MMRQ is written to 1, the RWU line goes high, entering 'Mute mode'. Upon detection of an IDLE frame, the RWU line goes low, returning to 'Normal mode'. RXNE flags are shown rising at the start of Data 5 and Data 6.

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

If the LPUART 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 LPUART_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 LPUART 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 LPUART enters mute mode.

The LPUART also enters mute mode when the MMRQ bit is written to 1. The RWU bit is also automatically set in this case.

The LPUART 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.

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

Figure 272. Mute mode using address mark detection

Timing diagram showing RX and RWU signals. RX shows a sequence of IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. RWU shows Mute mode, Normal mode, and Mute mode transitions. RXNE flags are shown above the RX signal. Annotations include 'MMRQ written to 1 (RXNE was cleared)', 'Non-matching address', 'Matching address', and 'Non-matching address'.

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

MSv31888V2

Timing diagram showing RX and RWU signals. RX shows a sequence of IDLE, Addr=0, Data 1, Data 2, IDLE, Addr=1, Data 3, Data 4, Addr=2, Data 5. RWU shows Mute mode, Normal mode, and Mute mode transitions. RXNE flags are shown above the RX signal. Annotations include 'MMRQ written to 1 (RXNE was cleared)', 'Non-matching address', 'Matching address', and 'Non-matching address'.

30.4.7 LPUART 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 LPUART_CR1 register. Depending on the frame length defined by the M bits, the possible LPUART frame formats are as listed in Table 144 .

Table 152. Frame formats

M bitsPCE bitLPUART frame (1)
000| SB | 8-bit data | STB |
001| SB | 7-bit data | PB | STB |
010| SB | 9-bit data | STB |
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.

2. In the data register, the PB is always taking the MSB position (9th, 8th or 7th, depending on the M bits value).

Even parity

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

As an example, if data=00110101, and 4 bits are set, then the parity bit will be 0 if even parity is selected (PS bit in LPUART_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 bits values) and the parity bit.

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

Parity checking in reception

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

Parity generation in transmission

If the PCE bit is set in LPUARTx_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)).

30.4.8 Single-wire Half-duplex communication using LPUART

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

The LPUART 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 LPUART_CR3.

As soon as HDSEL is written to 1:

Apart from this, the communication protocol is similar to normal LPUART 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 is written in the data register while the TE bit is set.

Note: In LPUART, in the case of 1-stop bit configuration, the RXNE flag is set in the middle of the stop bit.

30.4.9 Continuous communication in DMA mode using LPUART

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

Note: Use the LPUART as explained in Section 30.4.3 . To perform continuous communication, you can clear the TXE/ RXNE flags In the LPUART_ISR register.

Transmission using DMA

DMA mode can be enabled for transmission by setting DMAT bit in the LPUART_CR3 register. Data is loaded from a SRAM area configured using the DMA peripheral (refer to Section Direct memory access controller (DMA) ) to the LPUART_TDR register whenever the TXE bit is set. To map a DMA channel for LPUART transmission, use the following procedure (x denotes the channel number):

  1. 1. Write the LPUART_TDR register address in the DMA control register to configure it as the destination of the transfer. The data is 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 is loaded into the LPUART_TDR 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 flag in the LPUART_ISR register by setting the TCCF bit in the LPUART_ICR register.
  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 LPUART communication is complete. This is required to avoid corrupting the last transmission before disabling the LPUART or entering Stop 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 273. Transmission using DMA

Timing diagram for LPUART transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, LPUART_TDR, TC flag, and DMA TCIF flag over three frames (Frame 1, Frame 2, Frame 3).

The diagram illustrates the sequence of events for LPUART transmission using DMA:

Software sequence:

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

MSv31890V2

Timing diagram for LPUART transmission using DMA. The diagram shows the relationship between the TX line, TXE flag, DMA request, LPUART_TDR, TC flag, and DMA TCIF flag 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 LPUART_CR3 register. Data is loaded from the LPUART_RDR register to a SRAM area configured using the DMA peripheral (refer Section Direct memory access controller (DMA) ) whenever a data byte is received. To map a DMA channel for LPUART reception, use the following procedure:

  1. 1. Write the LPUART_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 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 LPUART_RDR to this memory area after each RXNE 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 274. Reception using DMA

Timing diagram for Figure 274: 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 a series of blocks representing the frames. The RXNE flag is set by hardware when a frame is received and cleared by a DMA read. The DMA request is generated when the RXNE flag is set. The LPUART_RDR register is updated with the received frame (F1, F2, F3). The DMA reads the LPUART_RDR register to receive the frame. The DMA TCIF flag (transfer complete) is set by hardware when the last frame is received and cleared by software. Callouts indicate: 'Software configures the DMA to receive 3 datablocks and enables the LPUART', 'DMA reads F1 from LPUART_RDR', 'DMA reads F2 from LPUART_RDR', 'DMA reads F3 from LPUART_RDR', and 'DMA transfer is complete (TCIF=1 in DMA_ISR)'.
Timing diagram for Figure 274: 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 a series of blocks representing the frames. The RXNE flag is set by hardware when a frame is received and cleared by a DMA read. The DMA request is generated when the RXNE flag is set. The LPUART_RDR register is updated with the received frame (F1, F2, F3). The DMA reads the LPUART_RDR register to receive the frame. The DMA TCIF flag (transfer complete) is set by hardware when the last frame is received and cleared by software. Callouts indicate: 'Software configures the DMA to receive 3 datablocks and enables the LPUART', 'DMA reads F1 from LPUART_RDR', 'DMA reads F2 from LPUART_RDR', 'DMA reads F3 from LPUART_RDR', and 'DMA transfer is complete (TCIF=1 in DMA_ISR)'.

MSv31891V3

Error flagging and interrupt generation in multibuffer communication

In multibuffer 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 in single byte reception, there is a separate error flag interrupt enable bit (EIE bit in the LPUART_CR3 register), which, if set, enables an interrupt after the current byte if any of these errors occur.

30.4.10 RS232 Hardware flow control and RS485 Driver Enable using LPUART

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

Figure 275. Hardware flow control between 2 LPUARTs

Diagram for Figure 275: Hardware flow control between 2 LPUARTs. The diagram shows two LPUART units, LPUART 1 and LPUART 2, connected via their TX and RX circuits. LPUART 1's TX circuit is connected to LPUART 2's RX circuit. LPUART 1's RX circuit is connected to LPUART 2's TX circuit. Flow control signals are connected: LPUART 1's CTS input is connected to LPUART 2's RTS output, and LPUART 1's RTS output is connected to LPUART 2's CTS input.
Diagram for Figure 275: Hardware flow control between 2 LPUARTs. The diagram shows two LPUART units, LPUART 1 and LPUART 2, connected via their TX and RX circuits. LPUART 1's TX circuit is connected to LPUART 2's RX circuit. LPUART 1's RX circuit is connected to LPUART 2's TX circuit. Flow control signals are connected: LPUART 1's CTS input is connected to LPUART 2's RTS output, and LPUART 1's RTS output is connected to LPUART 2's CTS input.

MSv31892V2

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

RS232 RTS flow control

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

Figure 276. RS232 RTS flow control

Timing diagram for RS232 RTS flow control showing RX and RTS lines over time.

The diagram illustrates the relationship between the RX (receive) line and the RTS (Request To Send) line during two data transmissions. The RX line shows two frames: 'Start bit', 'Data 1', 'Stop bit', followed by an 'Idle' state, then 'Start bit', 'Data 2', and 'Stop bit'. The RTS line is initially low. It goes high (asserted) at the start of the first frame and remains high until the 'Stop bit' of the first frame is received. At that point, an RXNE (Receive Not Empty) interrupt is indicated. Once 'Data 1' is read, the RTS line goes low (deasserted). It goes high again at the start of the second frame and returns low after the 'Stop bit' of the second frame is received, indicated by another RXNE interrupt. Text between the frames states 'Data 1 read' and 'Data 2 can now be transmitted'. The diagram is labeled MSv68794V1.

Timing diagram for RS232 RTS flow control showing RX and RTS lines over time.

RS232 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 deasserted (tied low), then the next data is transmitted (assuming that data is to be transmitted, in other words, if TXE=0), else the transmission does not occur. When CTS is asserted 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 LPUART_CR3 register is set. Figure 265 shows an example of communication with CTS flow control enabled.

Figure 277. RS232 CTS flow control

Timing diagram for RS232 CTS flow control showing the relationship between the CTS signal, the Transmit Data Register (TDR), and the Transmit (TX) line. The diagram illustrates that writing Data 3 into the TDR while CTS is still active (low) results in a delay of its transmission until CTS becomes inactive (high).

The diagram shows three horizontal timelines:

Key annotations:

Timing diagram for RS232 CTS flow control showing the relationship between the CTS signal, the Transmit Data Register (TDR), and the Transmit (TX) line. The diagram illustrates that writing Data 3 into the TDR while CTS is still active (low) results in a delay of its transmission until CTS becomes inactive (high).

Note: For correct behavior, CTS must be deasserted at least 3 LPUART 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 LPUART_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 LPUART_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 LPUART_CR1 control register. The polarity of the DE signal can be configured using the DEP bit in the LPUART_CR3 control register.

In LPUART, the DEAT and DEDT are expressed in USART clock source ( \( f_{CK} \) ) cycles:

With \( P = BRR[14:11] \)

30.4.11 Wakeup from Stop mode using LPUART

The LPUART is able to wake up the MCU from Stop mode when the UESM bit is set and the LPUART clock is set to HSI or LSE (refer to the Reset and clock control (RCC) section ).

Note: If the LPUART kernel clock is kept ON during Stop mode, there is no constraint on the maximum baud rate that allows waking up from Stop mode. It is the same as in Run mode.

When the LPUART clock source is configured to be \( f_{LSE} \) or \( f_{HSI} \) , it is possible to keep enabled this clock during STOP mode by setting the UCESM bit in LPUART_CR3 control register.

Note: When LPUART is used to wakeup from stop with LSE is selected as LPUART clock source, and desired baud rate is 9600 baud, the bit UCESM bit in LPUART_CR3 control register must be set.

The MCU wakeup from Stop mode can be done using the standard RXNE interrupt. In this case, the RXNEIE bit must be set before entering Stop mode.

Alternatively, a specific interrupt may be selected through the WUS bit fields.

In order to be able to wake up the MCU from Stop mode, the UESM bit in the LPUART_CR1 control register must be set prior to entering Stop mode.

When the wakeup event is detected, the WUF flag is set by hardware and a wakeup interrupt is generated if the WUFIE bit is set.

For code example, refer to A.18.1: LPUART receiver configuration code example and A.18.2: LPUART receive byte code example .

Note: Before entering Stop mode, the user must ensure that the LPUART is not performing a transfer. BUSY flag cannot ensure that Stop mode is never entered during a running reception.

The WUF flag is set when a wakeup event is detected, independently of whether the MCU is in Stop or in an active mode.

When entering Stop mode just after having initialized and enabled the receiver, the REACK bit must be checked to ensure the LPUART is actually enabled.

When DMA is used for reception, it must be disabled before entering Stop mode and re-enabled upon exit from Stop mode.

The wakeup from Stop mode feature is not available for all modes. For example it doesn't work in SPI mode because the SPI operates in master mode only.

Using Mute mode with Stop mode

If the LPUART is put into Mute mode before entering Stop mode:

Determining the maximum LPUART baud rate allowing to wakeup correctly from Stop mode when the LPUART clock source is the HSI clock

The maximum baud rate allowing to wakeup correctly from Stop mode depends on:

Let us take this example: M bits = 01, 2 stop bits, \( \text{BRR} \geq 4096 \) .

In these conditions, according to Table 151: Tolerance of the LPUART receiver , the LPUART receiver tolerance is 4.42 %.

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

\[ \text{DWU max} = t_{\text{WULPUART}} / (11 \times \text{Tbit Min}) \]

\[ \text{Tbit Min} = t_{\text{WULPUART}} / (11 \times \text{DWU max}) \]

If we consider an ideal case where the parameters DTRA, DQUANT, DREC and DTCL are at 0%, the DWU max is 4.42 %. In reality, we need to consider at least the HSI inaccuracy.

Let us consider the HSI inaccuracy = 1 %, \( t_{\text{WULPUART}} = 8.1 \mu\text{s} \) (in case of Stop mode with main regulator in Run mode, Range 1 ):

\[ \text{DWU max} = 4.42 \% - 1 \% = 3.42 \% \]

\[ \text{Tbit min} = 8.1 \mu\text{s} / (11 \times 3.42 \%) = 2.5 \mu\text{s}. \]

In these conditions, the maximum baud rate allowing to wakeup correctly from Stop mode is \( 1 / 21.5 \mu\text{s} = 46 \text{ kbaud} \) .

30.5 LPUART in low-power mode

Table 153. Effect of low-power modes on the LPUART

ModeDescription
SleepNo effect. USART interrupt causes the device to exit Sleep mode.
Low-power runNo effect.
Low-power sleepNo effect. USART interrupt causes the device to exit Low-power sleep mode.
StopThe LPUART is able to wake up the MCU from Stop mode when the UESM bit is set and the LPUART clock is set to HSI16 or LSE.
The MCU wakeup from Stop mode can be done using either the standard RXNE or the WUF interrupt.
StandbyThe LPUART is powered down and must be reinitialized when the device has exited from Standby mode.

30.6 LPUART interrupts

Table 154. LPUART interrupt requests

Interrupt eventEvent flagEnable Control bit
Transmit data register emptyTXETXEIE
CTS interruptCTSIFCTSIE
Transmission CompleteTCTCIE
Receive data register not empty (data ready to be read)RXNERXNEIE
Overrun error detectedORE
Idle line detectedIDLEIDLEIE
Parity errorPEPEIE
Noise Flag, Overrun error and Framing Error in multibuffer communication.NF or ORE or FEEIE
Character matchCMFCMIE
Wakeup from Stop modeWUF (1)WUFIE

1. The WUF interrupt is active only in Stop mode.

The LPUART interrupt events are connected to the same interrupt vector (see Figure 266 ).

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

Figure 278. LPUART interrupt mapping diagram

Logic diagram showing the mapping of various LPUART flags and enable bits to an interrupt output. The diagram uses AND and OR gates to combine signals like TC, TXE, CTSIF, IDLE, RXNEIF, PE, LBDF, FE, CMF, and WUF with their respective enable bits (TCIE, TXEIE, CTSIE, IDLEIE, RXNEIE, ORE, RXNE, PEIE, LBDIE, EIE, CMIE, WUFIE) to generate the final LPUART interrupt signal.

The diagram illustrates the interrupt mapping for the LPUART. It consists of several logic gates (AND and OR) that combine various flags and enable bits to generate the LPUART interrupt signal. The inputs are as follows:

The outputs of these logic combinations are further combined via a large OR gate to produce the final LPUART interrupt signal. The diagram is labeled MS31886V1 in the bottom right corner.

Logic diagram showing the mapping of various LPUART flags and enable bits to an interrupt output. The diagram uses AND and OR gates to combine signals like TC, TXE, CTSIF, IDLE, RXNEIF, PE, LBDF, FE, CMF, and WUF with their respective enable bits (TCIE, TXEIE, CTSIE, IDLEIE, RXNEIE, ORE, RXNE, PEIE, LBDIE, EIE, CMIE, WUFIE) to generate the final LPUART interrupt signal.

30.7 LPUART registers

Refer to Section 1.2 on page 52 for a list of abbreviations used in register descriptions.

The peripheral registers have to be accessed by words (32 bits).

30.7.1 Control register 1 (LPUART_CR1)

Address offset: 0x00

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.M1Res.Res.DEAT[4:0]DEDT[4:0]
rwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.CMIEMMEM0WAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETEREUESMUE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:29 Reserved, must be kept at reset value

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 bits

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

M[1:0] = 10: 1 Start bit, 7 data bits, n stop bits

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

Bit 27 Reserved, must be kept at reset value

Bit 26 Reserved, must be kept at reset value

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 UCLK (USART clock) clock cycles. For more details, refer to RS485 Driver Enable paragraph.

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

Bits 20:16 DEDT[4:0] : Driver Enable de-assertion time

This 5-bit value defines the time between the end of the last stop bit, in a transmitted message, and the de-activation of the DE (Driver Enable) signal. It is expressed in UCLK (USART clock) clock cycles. For more details, refer to RS485 Driver Enable paragraph.

If the LPUART_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 LPUART is disabled (UE=0).

Bit 15 Reserved, must be kept at reset value

Bit 14 CMIE : Character match interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: A LPUART interrupt is generated when the CMF bit is set in the LPUART_ISR register.

Bit 13 MME: Mute mode enable

This bit activates the mute mode function of the LPUART. When set, the LPUART 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 MO: 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 LPUART is disabled (UE=0).

Bit 11 WAKE: Receiver wakeup method

This bit determines the LPUART 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 LPUART is disabled (UE=0).

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

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

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

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

Bit 8 PEIE: PE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever PE=1 in the LPUART_ISR register

Bit 7 TXEIE: interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever TXE=1 in the LPUART_ISR register

Bit 6 TCIE: Transmission complete interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever TC=1 in the LPUART_ISR register

Bit 5 RXNEIE: RXNE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever ORE=1 or RXNE=1 in the LPUART_ISR register

Bit 4 IDLEIE: IDLE interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever IDLE=1 in the LPUART_ISR 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: During transmission, a “0” pulse on the TE bit (“0” followed by “1”) sends a preamble (idle line) after the current word. 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 LPUART_ISR register.

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 UESM: LPUART enable in Stop mode

When this bit is cleared, the LPUART is not able to wake up the MCU from Stop mode.

When this bit is set, the LPUART is able to wake up the MCU from Stop mode, provided that the LPUART clock selection is HSI or LSE in the RCC.

This bit is set and cleared by software.

0: LPUART not able to wake up the MCU from Stop mode.

1: LPUART able to wake up the MCU from Stop mode. When this function is active, the clock source for the LPUART must be HSI or LSE (see Section Reset and clock control (RCC)).

Note: It is recommended to set the UESM bit just before entering Stop mode and clear it on exit from Stop mode.

Bit 0 UE: LPUART enable

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

0: LPUART prescaler and outputs disabled, low-power mode

1: LPUART 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 LPUART_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.

30.7.2 Control register 2 (LPUART_CR2)

Address offset: 0x04

Reset value: 0x0000

31302928272625242322212019181716
ADD[7:4]ADD[3:0]Res.Res.Res.Res.MSBFIRSTDATAINVTXINVRXINV
rwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SWAPRes.STOP[1:0]Res.Res.Res.Res.Res.Res.Res.ADDM7Res.Res.Res.Res.
rwrwrwrw

Bits 31:28 ADD[7:4]: Address of the LPUART node

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

This is used in multiprocessor communication during Mute mode or Stop 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 LPUART is disabled (UE=0)

Bits 27:24 ADD[3:0]: Address of the LPUART node

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

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

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

Bits 23:20 Reserved, must be kept at reset value

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/9) first, following the start bit.

This bit field can only be written when the LPUART 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 send/received in positive/direct logic. (1=H, 0=L)

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

This bit field can only be written when the LPUART 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 (V DD =1/idle, Gnd=0/mark)

1: TX pin signal values are inverted. (V DD =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 LPUART 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 ( \( V_{DD}=1/\text{idle} \) , \( Gnd=0/\text{mark} \) )

1: RX pin signal values are inverted. ( \( (V_{DD}=0/\text{mark} \) , \( Gnd=1/\text{idle}) \) ).

This allows the use of an external inverter on the RX line.

This bit field can only be written when the LPUART 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 allows to work in the case of a cross-wired connection to another UART.

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

Bit 14 Reserved, must be kept at reset value

Bits 13:12 STOP[1:0] : STOP bits

These bits are used for programming the stop bits.

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

Bits 11:5 Reserved, must be kept at reset value

Bit 4 ADDM7 : 7-bit Address Detection/4-bit Address Detection

This bit is for selection between 4-bit address detection or 7-bit address detection.

This bit can only be written when the LPUART 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.

Bits 3:0 Reserved, must be kept at reset value.

30.7.3 Control register 3 (LPUART_CR3)

Address offset: 0x08

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.UCESMWUFIEWUS[2:0]Res.Res.Res.Res.
rwrwrwrw

1514131211109876543210
DEPDEMDDREOVR DISRes.CTSIECTSERTSEDMATDMARRes.Res.HD SELRes.Res.EIE
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bit 23 UCESM : LPUART Clock Enable in Stop mode.

This bit is set and cleared by software.

0: LPUART Clock is disabled in STOP mode.

1: LPUART Clock is enabled in STOP mode.

Note: In order to be able to wakeup the MCU from Stop mode with LPUART at 9600 baud, the UCESM bit must be set prior to entering the Stop mode.

Bit 22 WUFIE : Wakeup from Stop mode interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited

1: An LPUART interrupt is generated whenever WUF=1 in the LPUART_ISR register

Note: WUFIE must be set before entering in Stop mode.

The WUF interrupt is active only in Stop mode.

If the LPUART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value.

Bits 21:20 WUS[1:0] : Wakeup from Stop mode interrupt flag selection

This bit-field specify the event which activates the WUF (wakeup from Stop mode flag).

00: WUF active on address match (as defined by ADD[7:0] and ADDM7)

01:Reserved.

10: WUF active on Start bit detection

11: WUF active on RXNE.

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

Note: If the LPUART does not support the wakeup from Stop feature, this bit is reserved and must be kept at reset value.

Bits 19: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 LPUART is disabled (UE=0).

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 LPUART is disabled (UE=0).

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 will be transferred.

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 before clearing the error flag.

This bit can only be written when the LPUART 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 LPUART_RDR register.

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

Note: This control bit allows checking the communication flow without reading the data.

Bit 11 Reserved, must be kept at reset value.

Bit 10 CTSIE : CTS interrupt enable

0: Interrupt is inhibited

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

Bit 9 CTSE : CTS enable

0: CTS hardware flow control disabled

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

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

Bit 8 RTSE : RTS enable

0: RTS hardware flow control disabled

1: RTS output 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 deasserted (pulled to 0) when data can be received.

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

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

Bits 5:4 Reserved, must be kept at reset value.

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 LPUART is disabled (UE=0).

Bits 2:1 Reserved, must be kept at reset value.

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 flag (FE=1 or ORE=1 or NF=1 in the LPUART_ISR register).

0: Interrupt is inhibited

1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the LPUART_ISR register.

30.7.4 Baud rate register (LPUART_BRR)

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

Address offset: 0x0C

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BRR[19:16]
rwrwrwrw
1514131211109876543210
BRR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:20 Reserved, must be kept at reset value.

Bits 19:0 BRR[19:0]

Note: It is forbidden to write values less than 0x300 in the LPUART_BRR register.

Provided that LPUARTx_BRR must be \( \geq 0x300 \) and LPUART_BRR is 20-bit, a care should be taken when generating high baud rates using high fck values. fck must be in the range [3 x baud rate, 4096 x baud rate].

30.7.5 Request register (LPUART_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.Res.RXFRQMMRQSBKRQRes.
www

Bits 31:4 Reserved, must be kept at reset value

Bit 3 RXFRQ : Receive data flush request

Writing 1 to this bit clears the RXNE flag.

This allows to discard the received data without reading it, and avoid an overrun condition.

Bit 2 MMRQ : Mute mode request

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

Bit 1 SBKRQ : Send break request

Writing 1 to this bit sets the SBKF flag and request 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 Reserved, must be kept at reset value

30.7.6 Interrupt & status register (LPUART_ISR)

Address offset: 0x1C

Reset value: 0x00C0

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.RE
ACK
TE
ACK
WUFRWUSBKFCMFBUSY
rrrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.CTSCTSIFRes.TXETCRXNEIDLEORENFFEPE
rrrrrrrrrr

Bits 31:23 Reserved, must be kept at reset value.

Bit 22 REACK : Receive enable acknowledge flag

This bit is set/reset by hardware, when the Receive Enable value is taken into account by the LPUART.

It can be used to verify that the LPUART is ready for reception before entering Stop mode.

Note: If the LPUART does not support the wakeup from Stop feature, this bit is reserved and kept at reset value.

Bit 21 TEACK : Transmit enable acknowledge flag

This bit is set/reset by hardware, when the Transmit Enable value is taken into account by the LPUART.

It can be used when an idle frame request is generated by writing TE=0, followed by TE=1 in the LPUART_CR1 register, in order to respect the TE=0 minimum period.

Bit 20 WUF : Wakeup from Stop mode flag

This bit is set by hardware, when a wakeup event is detected. The event is defined by the WUS bit field. It is cleared by software, writing a 1 to the WUCF in the LPUART_ICR register.

An interrupt is generated if WUFIE=1 in the LPUART_CR3 register.

Note: When UESM is cleared, WUF flag is also cleared.

The WUF interrupt is active only in Stop mode.

If the LPUART does not support the wakeup from Stop feature, this bit is reserved and kept at reset value.

Bit 19 RWU : Receiver wakeup from Mute mode

This bit indicates if the LPUART 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 LPUART_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 LPUART_RQR register.

0: Receiver in active mode

1: Receiver in mute mode

Bit 18 SBKF : 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 LPUART_CR3 register. It is automatically reset by hardware during the stop bit of break transmission.

0: No break character is transmitted

1: Break character will be transmitted

Bit 17 CMF : 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 LPUART_ICR register.

An interrupt is generated if CMIE=1 in the LPUART_CR1 register.

0: No Character match detected

1: Character Match detected

Bit 16 BUSY : Busy flag

This bit is set and reset by hardware. It is active when a communication is ongoing on the RX line (successful start bit detected). It is reset at the end of the reception (successful or not).

0: LPUART is idle (no reception)

1: Reception on going

Bits 15:11 Reserved, must be kept at reset value.

Bit 10 CTS : CTS flag

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

0: CTS line set

1: CTS line reset

Note: If the hardware flow control feature is not supported, this bit is reserved and kept at reset value.

Bit 9 CTSIF : CTS interrupt 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 1 to the CTSCF bit in the LPUART_ICR register.

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

0: No change occurred on the CTS status line

1: A change occurred on the CTS status line

Note: If the hardware flow control feature is not supported, this bit is reserved and kept at reset value.

Bit 8 Reserved, must be kept at reset value.

Bit 7 TXE: Transmit data register empty

This bit is set by hardware when the content of the LPUART_TDR register has been transferred into the shift register. It is cleared by a write to the LPUART_TDR register.

An interrupt is generated if the TXEIE bit =1 in the LPUART_CR1 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 LPUART_CR1 register. It is cleared by software, writing 1 to the TCCF in the LPUART_ICR register or by a write to the LPUART_TDR register.

An interrupt is generated if TCIE=1 in the LPUART_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 will be set immediately.

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 LPUART_RDR register. It is cleared by a read to the LPUART_RDR register. The RXNE flag can also be cleared by writing 1 to the RXFRQ in the LPUART_RQR register.

An interrupt is generated if RXNEIE=1 in the LPUART_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 LPUART_CR1 register. It is cleared by software, writing 1 to the IDLECF in the LPUART_ICR 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 (i.e. a new idle line occurs).

If mute mode is enabled (MME=1), IDLE is set if the LPUART 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 RDR register while RXNE=1. It is cleared by a software, writing 1 to the ORECF, in the LPUART_ICR register.

An interrupt is generated if RXNEIE=1 or EIE = 1 in the LPUART_CR1 register.

0: No overrun error

1: Overrun error is detected

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

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

Bit 2 NF : START bit Noise detection flag

This bit is set by hardware when noise is detected on the START bit of a received frame. It is cleared by software, writing 1 to the NFCF bit in the LPUART_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 bit which itself generates an interrupt. An interrupt is generated when the NF flag is set during multibuffer 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 software, writing 1 to the FECF bit in the LPUART_ICR register.

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

0: No Framing error is detected

1: Framing error or break character is detected

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 LPUART_ICR register.

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

0: No parity error

1: Parity error

30.7.7 Interrupt flag clear register (LPUART_ICR)

Address offset: 0x20

Reset value: 0x0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WUCFRes.Res.CMCFRes.
ww
1514131211109876543210
Res.Res.Res.Res.Res.Res.CTSCFRes.Res.TCCFRes.IDLECFORECFNCFFECFPECF
wwwwwww

Bits 31:21 Reserved, must be kept at reset value.

Bit 20 WUCF : Wakeup from Stop mode clear flag

Writing 1 to this bit clears the WUF flag in the LPUART_ISR register.

Note: If the LPUART does not support the wakeup from Stop feature, this bit is reserved and kept at reset value.

Bits 19:18 Reserved, must be kept at reset value.

Bit 17 CMCF : Character match clear flag

Writing 1 to this bit clears the CMF flag in the LPUART_ISR register.

Bits 16:10 Reserved, must be kept at reset value.

Bit 9 CTSCF : CTS clear flag

Writing 1 to this bit clears the CTSIF flag in the LPUART_ISR register.

Bits 8:7 Reserved, must be kept at reset value.

Bit 6 TCF : Transmission complete clear flag

Writing 1 to this bit clears the TC flag in the LPUART_ISR register.

Bit 5 Reserved, must be kept at reset value.

Bit 4 IDLECF : Idle line detected clear flag

Writing 1 to this bit clears the IDLE flag in the LPUART_ISR register.

Bit 3 ORECF : Overrun error clear flag

Writing 1 to this bit clears the ORE flag in the LPUART_ISR register.

Bit 2 NCF : Noise detected clear flag

Writing 1 to this bit clears the NF flag in the LPUART_ISR register.

Bit 1 FECF : Framing error clear flag

Writing 1 to this bit clears the FE flag in the LPUART_ISR register.

Bit 0 PECF : Parity error clear flag

Writing 1 to this bit clears the PE flag in the LPUART_ISR register.

30.7.8 Receive data register (LPUART_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:9 Reserved, 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 242 ).

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

30.7.9 Transmit data register (LPUART_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:9 Reserved, must be kept at reset value.

Bits 8:0 TDR[8:0] : Transmit data value

Contains the data character to be transmitted.

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

When transmitting with the parity enabled (PCE bit set to 1 in the LPUART_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=1.

30.7.10 LPUART register map

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

Table 155. LPUART register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00LPUART_CR1Res.Res.Res.M1Res.Res.DEAT4DEAT3DEAT2DEAT1DEAT0DEDT4DEDT3DEDT2DEDT1DEDT0Res.CMIEMMEMWAKEPCEPSPEIETXEIETCIERXNEIEIDLEIETEREUESMUE
Reset value00000000000000000000000000
0x04LPUART_CR2ADD[7:4]ADD[3:0]Res.Res.Res.Res.MSBFIRSTDATAINVTXINVRXINVSWAPRes.STOP [1:0]Res.Res.Res.Res.Res.Res.Res.ADD7Res.Res.Res.Res.
Reset value0000000000000000
0x08LPUART_CR3Res.Res.Res.Res.Res.Res.Res.Res.UOESMWUFIEWUS [1:0]Res.Res.Res.Res.Res.DEPDEMDDREOVRDISRes.CTSIECTSERTSEDMATDMARRes.Res.HDSELRes.Res.EIE
Reset value00000000000000
0x0CLPUART_BRRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BRR[19:0]
Reset value
0x10-0x14Reserved
0x18LPUART_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.Res.RXFREQMMRQSBKRQRes.
Reset value000
0x1CLPUART_ISRRes.Res.Res.Res.Res.Res.Res.Res.Res.REACKTEACKWUFRWUSBKFCMFBUSYRes.Res.Res.Res.Res.CTSCTSIFRes.TXETCRXNEIDLEORENFFEPE
Reset value0000000001100000
0x20LPUART_ICRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.WUCFRes.Res.CMCFRes.Res.Res.Res.Res.Res.Res.CTSCTSIFRes.TXETCRXNEIDLEORENFFEPE
Reset value00000000
0x24LPUART_RDRRes.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 valueXXXXXXXXXX
0x28LPUART_TDRRes.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 valueXXXXXXXXXX

Refer to Section 2.2 on page 58 for the register boundary addresses.