| M480 BSP V3.05.001 The Board Support Package for M480 Series

Macros | Functions
UART Exported Functions
Standard Driver » UART Driver

## Macros
#define | UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate)
| Calculate UART baudrate mode0 divider. More...
#define | UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate)
| Calculate UART baudrate mode2 divider. More...
#define | UART_WRITE(uart, u8Data)
| Write UART data. More...
#define | UART_READ(uart)
| Read UART data. More...
#define | UART_GET_TX_EMPTY(uart)
| Get Tx empty. More...
#define | UART_GET_RX_EMPTY(uart)
| Get Rx empty. More...
#define | UART_IS_TX_EMPTY(uart)
| Check specified UART port transmission is over. More...
#define | UART_WAIT_TX_EMPTY(uart)
| Wait specified UART port transmission is over. More...
#define | UART_IS_RX_READY(uart)
| Check RX is ready or not. More...
#define | UART_IS_TX_FULL(uart)
| Check TX FIFO is full or not. More...
#define | UART_IS_RX_FULL(uart)
| Check RX FIFO is full or not. More...
#define | UART_GET_TX_FULL(uart)
| Get Tx full register value. More...
#define | UART_GET_RX_FULL(uart)
| Get Rx full register value. More...
#define | UART_ENABLE_INT(uart, u32eIntSel)
| Enable specified UART interrupt. More...
#define | UART_DISABLE_INT(uart, u32eIntSel)
| Disable specified UART interrupt. More...
#define | UART_GET_INT_FLAG(uart, u32eIntTypeFlag)
| Get specified interrupt flag/status. More...
#define | UART_RS485_CLEAR_ADDR_FLAG(uart)
| Clear RS-485 Address Byte Detection Flag. More...
#define | UART_RS485_GET_ADDR_FLAG(uart)
| Get RS-485 Address Byte Detection Flag. More...
#define | UART_PDMA_ENABLE(uart, u32FuncSel)
| Enable specified UART PDMA function. More...
#define | UART_PDMA_DISABLE(uart, u32FuncSel)
| Disable specified UART PDMA function. More...

## Functions
__STATIC_INLINE void | UART_CLEAR_RTS (UART_T *uart)
| Set RTS pin to low. More...
__STATIC_INLINE void | UART_SET_RTS (UART_T *uart)
| Set RTS pin to high. More...
void | UART_ClearIntFlag (UART_T *uart, uint32_t u32InterruptFlag)
| Clear UART specified interrupt flag. More...
void | UART_Close (UART_T *uart)
| Disable UART interrupt. More...
void | UART_DisableFlowCtrl (UART_T *uart)
| Disable UART auto flow control function. More...
void | UART_DisableInt (UART_T *uart, uint32_t u32InterruptFlag)
| Disable UART specified interrupt. More...
void | UART_EnableFlowCtrl (UART_T *uart)
| Enable UART auto flow control function. More...
void | UART_EnableInt (UART_T *uart, uint32_t u32InterruptFlag)
| The function is used to enable UART specified interrupt and enable NVIC UART IRQ. More...
void | UART_Open (UART_T *uart, uint32_t u32baudrate)
| Open and set UART function. More...
uint32_t | UART_Read (UART_T *uart, uint8_t pu8RxBuf[], uint32_t u32ReadBytes)
| Read UART data. More...
void | UART_SetLineConfig (UART_T *uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits)
| Set UART line configuration. More...
void | UART_SetTimeoutCnt (UART_T *uart, uint32_t u32TOC)
| Set Rx timeout count. More...
void | UART_SelectIrDAMode (UART_T *uart, uint32_t u32Buadrate, uint32_t u32Direction)
| Select and configure IrDA function. More...
void | UART_SelectRS485Mode (UART_T *uart, uint32_t u32Mode, uint32_t u32Addr)
| Select and configure RS485 function. More...
void | UART_SelectLINMode (UART_T *uart, uint32_t u32Mode, uint32_t u32BreakLength)
| Select and configure LIN function. More...
uint32_t | UART_Write (UART_T *uart, uint8_t pu8TxBuf[], uint32_t u32WriteBytes)
| Write UART data. More...

## Detailed Description

## Macro Definition Documentation

## ◆ UART_BAUD_MODE0_DIVIDER

#define UART_BAUD_MODE0_DIVIDER | ( |  | u32SrcFreq,
|  |  | u32BaudRate
| ) |  |

Calculate UART baudrate mode0 divider.

Parameters

  [in] | u32SrcFreq | UART clock frequency
  [in] | u32BaudRate | Baudrate of UART module

Returns
  UART baudrate mode0 divider

This macro calculate UART baudrate mode0 divider.

Definition at line 135 of file uart.h.

## ◆ UART_BAUD_MODE2_DIVIDER

#define UART_BAUD_MODE2_DIVIDER | ( |  | u32SrcFreq,
|  |  | u32BaudRate
| ) |  |

Calculate UART baudrate mode2 divider.

Parameters

  [in] | u32SrcFreq | UART clock frequency
  [in] | u32BaudRate | Baudrate of UART module

Returns
  UART baudrate mode2 divider

This macro calculate UART baudrate mode2 divider.

Definition at line 149 of file uart.h.

## ◆ UART_DISABLE_INT

#define UART_DISABLE_INT | ( |  | uart,
|  |  | u32eIntSel
| ) |  |

Disable specified UART interrupt.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u32eIntSel | Interrupt type select UART_INTEN_ABRIEN_Msk : Auto baud rate interrupt UART_INTEN_WKIEN_Msk : Wakeup interrupt UART_INTEN_LINIEN_Msk : Lin bus interrupt UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt UART_INTEN_MODEMIEN_Msk : Modem status interrupt UART_INTEN_RLSIEN_Msk : Receive Line status interrupt UART_INTEN_THREIEN_Msk : Tx empty interrupt UART_INTEN_RDAIEN_Msk : Rx ready interrupt

Returns
  None

This macro enable specified UART interrupt.

Definition at line 348 of file uart.h.

## ◆ UART_ENABLE_INT

#define UART_ENABLE_INT | ( |  | uart,
|  |  | u32eIntSel
| ) |  |

Enable specified UART interrupt.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u32eIntSel | Interrupt type select UART_INTEN_ABRIEN_Msk : Auto baud rate interrupt UART_INTEN_WKIEN_Msk : Wakeup interrupt UART_INTEN_LINIEN_Msk : Lin bus interrupt UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt UART_INTEN_MODEMIEN_Msk : Modem interrupt UART_INTEN_RLSIEN_Msk : Rx Line status interrupt UART_INTEN_THREIEN_Msk : Tx empty interrupt UART_INTEN_RDAIEN_Msk : Rx ready interrupt

Returns
  None

This macro enable specified UART interrupt.

Definition at line 325 of file uart.h.

## ◆ UART_GET_INT_FLAG

#define UART_GET_INT_FLAG | ( |  | uart,
|  |  | u32eIntTypeFlag
| ) |  |

Get specified interrupt flag/status.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u32eIntTypeFlag | Interrupt Type Flag, should be UART_INTSTS_HWBUFEINT_Msk : In DMA Mode, Buffer Error Interrupt Indicator UART_INTSTS_HWTOINT_Msk : In DMA Mode, Time-out Interrupt Indicator UART_INTSTS_HWMODINT_Msk : In DMA Mode, MODEM Status Interrupt Indicator UART_INTSTS_HWRLSINT_Msk : In DMA Mode, Receive Line Status Interrupt Indicator UART_INTSTS_HWBUFEIF_Msk : In DMA Mode, Buffer Error Interrupt Flag UART_INTSTS_HWTOIF_Msk : In DMA Mode, Time-out Interrupt Flag UART_INTSTS_HWMODIF_Msk : In DMA Mode, MODEM Interrupt Flag UART_INTSTS_HWRLSIF_Msk : In DMA Mode, Receive Line Status Flag UART_INTSTS_LININT_Msk : LIN Bus Interrupt Indicator UART_INTSTS_BUFERRINT_Msk : Buffer Error Interrupt Indicator UART_INTSTS_RXTOINT_Msk : Time-out Interrupt Indicator UART_INTSTS_MODEMINT_Msk : Modem Status Interrupt Indicator UART_INTSTS_RLSINT_Msk : Receive Line Status Interrupt Indicator UART_INTSTS_THREINT_Msk : Transmit Holding Register Empty Interrupt Indicator UART_INTSTS_RDAINT_Msk : Receive Data Available Interrupt Indicator UART_INTSTS_LINIF_Msk : LIN Bus Flag UART_INTSTS_BUFERRIF_Msk : Buffer Error Interrupt Flag UART_INTSTS_RXTOIF_Msk : Rx Time-out Interrupt Flag UART_INTSTS_MODEMIF_Msk : Modem Interrupt Flag UART_INTSTS_RLSIF_Msk : Receive Line Status Interrupt Flag UART_INTSTS_THREIF_Msk : Tx Empty Interrupt Flag UART_INTSTS_RDAIF_Msk : Rx Ready Interrupt Flag

Return values

  0 | The specified interrupt is not happened. 1 The specified interrupt is happened.

This macro get specified interrupt flag or interrupt indicator status.

Definition at line 385 of file uart.h.

## ◆ UART_GET_RX_EMPTY

#define UART_GET_RX_EMPTY | ( |  | uart | ) |

Get Rx empty.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Rx FIFO is not empty
  >=1 | Rx FIFO is empty

This macro get Receiver FIFO empty register value.

Definition at line 204 of file uart.h.

## ◆ UART_GET_RX_FULL

#define UART_GET_RX_FULL | ( |  | uart | ) |

Get Rx full register value.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Rx FIFO is not full.
  >=1 | Rx FIFO is full.

This macro get Rx full register value.

Definition at line 302 of file uart.h.

## ◆ UART_GET_TX_EMPTY

#define UART_GET_TX_EMPTY | ( |  | uart | ) |

Get Tx empty.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Tx FIFO is not empty
  >=1 | Tx FIFO is empty

This macro get Transmitter FIFO empty register value.

Definition at line 190 of file uart.h.

## ◆ UART_GET_TX_FULL

#define UART_GET_TX_FULL | ( |  | uart | ) |

Get Tx full register value.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Tx FIFO is not full.
  >=1 | Tx FIFO is full.

This macro get Tx full register value.

Definition at line 288 of file uart.h.

## ◆ UART_IS_RX_FULL

#define UART_IS_RX_FULL | ( |  | uart | ) |

Check RX FIFO is full or not.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  1 | RX FIFO is full
  0 | RX FIFO is not full

This macro check RX FIFO is full or not.

Definition at line 274 of file uart.h.

## ◆ UART_IS_RX_READY

#define UART_IS_RX_READY | ( |  | uart | ) |

Check RX is ready or not.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | The number of bytes in the RX FIFO is less than the RFITL
  1 | The number of bytes in the RX FIFO equals or larger than RFITL

This macro check receive data available interrupt flag is set or not.

Definition at line 246 of file uart.h.

## ◆ UART_IS_TX_EMPTY

#define UART_IS_TX_EMPTY | ( |  | uart | ) |

Check specified UART port transmission is over.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Tx transmission is not over
  1 | Tx transmission is over

This macro return Transmitter Empty Flag register bit value. It indicates if specified UART port transmission is over nor not.

Definition at line 219 of file uart.h.

## ◆ UART_IS_TX_FULL

#define UART_IS_TX_FULL | ( |  | uart | ) |

Check TX FIFO is full or not.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  1 | TX FIFO is full
  0 | TX FIFO is not full

This macro check TX FIFO is full or not.

Definition at line 260 of file uart.h.

## ◆ UART_PDMA_DISABLE

#define UART_PDMA_DISABLE | ( |  | uart,
|  |  | u32FuncSel
| ) |  |

Disable specified UART PDMA function.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u32FuncSel | Combination of following functions UART_INTEN_TXPDMAEN_Msk UART_INTEN_RXPDMAEN_Msk

Returns
  None

Definition at line 474 of file uart.h.

## ◆ UART_PDMA_ENABLE

#define UART_PDMA_ENABLE | ( |  | uart,
|  |  | u32FuncSel
| ) |  |

Enable specified UART PDMA function.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u32FuncSel | Combination of following functions UART_INTEN_TXPDMAEN_Msk UART_INTEN_RXPDMAEN_Msk

Returns
  None

Definition at line 461 of file uart.h.

## ◆ UART_READ

#define UART_READ | ( |  | uart | ) |

Read UART data.

Parameters

  [in] | uart | The pointer of the specified UART module

Returns
  The oldest data byte in RX FIFO.

This macro read Rx data register.

Definition at line 176 of file uart.h.

## ◆ UART_RS485_CLEAR_ADDR_FLAG

#define UART_RS485_CLEAR_ADDR_FLAG | ( |  | uart | ) |

Clear RS-485 Address Byte Detection Flag.

Parameters

  [in] | uart | The pointer of the specified UART module

Returns
  None

This macro clear RS-485 address byte detection flag.

Definition at line 398 of file uart.h.

## ◆ UART_RS485_GET_ADDR_FLAG

#define UART_RS485_GET_ADDR_FLAG | ( |  | uart | ) |

Get RS-485 Address Byte Detection Flag.

Parameters

  [in] | uart | The pointer of the specified UART module

Return values

  0 | Receiver detects a data that is not an address bit.
  1 | Receiver detects a data that is an address bit.

This macro get RS-485 address byte detection flag.

Definition at line 412 of file uart.h.

## ◆ UART_WAIT_TX_EMPTY

#define UART_WAIT_TX_EMPTY | ( |  | uart | ) |

Wait specified UART port transmission is over.

Parameters

  [in] | uart | The pointer of the specified UART module

Returns
  None

This macro wait specified UART port transmission is over.

Definition at line 232 of file uart.h.

## ◆ UART_WRITE

#define UART_WRITE | ( |  | uart,
|  |  | u8Data
| ) |  |

Write UART data.

Parameters

  [in] | uart | The pointer of the specified UART module
  [in] | u8Data | Data byte to transmit.

Returns
  None

This macro write Data to Tx data register.

Definition at line 163 of file uart.h.

## Function Documentation

## ◆ UART_CLEAR_RTS()

__STATIC_INLINE void UART_CLEAR_RTS | ( | UART_T * | uart | ) |

Set RTS pin to low.

Parameters

  [in] | uart | The pointer of the specified UART module

Returns
  None

This macro set RTS pin to low.

Definition at line 428 of file uart.h.

## ◆ UART_ClearIntFlag()

void UART_ClearIntFlag | ( | UART_T * | uart,
|  | uint32_t | u32InterruptFlag
| ) |  |

Clear UART specified interrupt flag.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32InterruptFlag | The specified interrupt of UART module. UART_INTSTS_LININT_Msk : LIN bus interrupt UART_INTSTS_WKIF_Msk : Wake-up interrupt UART_INTSTS_BUFERRINT_Msk : Buffer Error interrupt UART_INTSTS_MODEMINT_Msk : Modem Status interrupt UART_INTSTS_RLSINT_Msk : Receive Line Status interrupt

Returns
  None

The function is used to clear UART specified interrupt flag.

Definition at line 41 of file uart.c.

## ◆ UART_Close()

void UART_Close | ( | UART_T * | uart | ) |

Disable UART interrupt.

Parameters

  [in] | uart | The pointer of the specified UART module.

Returns
  None

The function is used to disable UART interrupt.

Definition at line 89 of file uart.c.

## ◆ UART_DisableFlowCtrl()

void UART_DisableFlowCtrl | ( | UART_T * | uart | ) |

Disable UART auto flow control function.

Parameters

  [in] | uart | The pointer of the specified UART module.

Returns
  None

The function is used to disable UART auto flow control.

Definition at line 104 of file uart.c.

## ◆ UART_DisableInt()

void UART_DisableInt | ( | UART_T * | uart,
|  | uint32_t | u32InterruptFlag
| ) |  |

Disable UART specified interrupt.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32InterruptFlag | The specified interrupt of UART module. UART_INTEN_WKIEN_Msk : Wake-up interrupt UART_INTEN_LINIEN_Msk : Lin bus interrupt UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt UART_INTEN_MODEMIEN_Msk : Modem status interrupt UART_INTEN_RLSIEN_Msk : Receive Line status interrupt UART_INTEN_THREIEN_Msk : Tx empty interrupt UART_INTEN_RDAIEN_Msk : Rx ready interrupt *

Returns
  None

The function is used to disable UART specified interrupt and disable NVIC UART IRQ.

Definition at line 128 of file uart.c.

## ◆ UART_EnableFlowCtrl()

void UART_EnableFlowCtrl | ( | UART_T * | uart | ) |

Enable UART auto flow control function.

Parameters

  [in] | uart | The pointer of the specified UART module.

Returns
  None

The function is used to Enable UART auto flow control.

Definition at line 144 of file uart.c.

## ◆ UART_EnableInt()

void UART_EnableInt | ( | UART_T * | uart,
|  | uint32_t | u32InterruptFlag
| ) |  |

The function is used to enable UART specified interrupt and enable NVIC UART IRQ.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32InterruptFlag | The specified interrupt of UART module: UART_INTEN_WKIEN_Msk : Wake-up interrupt UART_INTEN_LINIEN_Msk : Lin bus interrupt UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt UART_INTEN_MODEMIEN_Msk : Modem status interrupt UART_INTEN_RLSIEN_Msk : Receive Line status interrupt UART_INTEN_THREIEN_Msk : Tx empty interrupt UART_INTEN_RDAIEN_Msk : Rx ready interrupt *

Returns
  None

The function is used to enable UART specified interrupt and enable NVIC UART IRQ.

Definition at line 175 of file uart.c.

## ◆ UART_Open()

void UART_Open | ( | UART_T * | uart,
|  | uint32_t | u32baudrate
| ) |  |

Open and set UART function.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32baudrate | The baudrate of UART module.

Returns
  None

This function use to enable UART function and set baud-rate.

Definition at line 192 of file uart.c.

## ◆ UART_Read()

uint32_t UART_Read | ( | UART_T * | uart,
|  | uint8_t | pu8RxBuf[],
|  | uint32_t | u32ReadBytes
| ) |  |

Read UART data.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | pu8RxBuf | The buffer to receive the data of receive FIFO.
  [in] | u32ReadBytes | The the read bytes number of data.

Returns
  u32Count Receive byte count

The function is used to read Rx data from RX FIFO and the data will be stored in pu8RxBuf.

Definition at line 285 of file uart.c.

## ◆ UART_SelectIrDAMode()

void UART_SelectIrDAMode | ( | UART_T * | uart,
|  | uint32_t | u32Buadrate,
|  | uint32_t | u32Direction
| ) |  |

Select and configure IrDA function.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32Buadrate | The baudrate of UART module.
  [in] | u32Direction | The direction of UART module in IrDA mode: UART_IRDA_TXEN UART_IRDA_RXEN

Returns
  None

The function is used to configure IrDA relative settings. It consists of TX or RX mode and baudrate.

Definition at line 460 of file uart.c.

## ◆ UART_SelectLINMode()

void UART_SelectLINMode | ( | UART_T * | uart,
|  | uint32_t | u32Mode,
|  | uint32_t | u32BreakLength
| ) |  |

Select and configure LIN function.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32Mode | The LIN direction : UART_ALTCTL_LINTXEN_Msk UART_ALTCTL_LINRXEN_Msk
  [in] | u32BreakLength | The break field length.

Returns
  None

The function is used to set LIN relative setting.

Definition at line 590 of file uart.c.

## ◆ UART_SelectRS485Mode()

void UART_SelectRS485Mode | ( | UART_T * | uart,
|  | uint32_t | u32Mode,
|  | uint32_t | u32Addr
| ) |  |

Select and configure RS485 function.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32Mode | The operation mode(NMM/AUD/AAD). UART_ALTCTL_RS485NMM_Msk UART_ALTCTL_RS485AUD_Msk UART_ALTCTL_RS485AAD_Msk
  [in] | u32Addr | The RS485 address.

Returns
  None

The function is used to set RS485 relative setting.

Definition at line 566 of file uart.c.

## ◆ UART_SET_RTS()

__STATIC_INLINE void UART_SET_RTS | ( | UART_T * | uart | ) |

Set RTS pin to high.

Parameters

  [in] | uart | The pointer of the specified UART module

Returns
  None

This macro set RTS pin to high.

Definition at line 444 of file uart.h.

## ◆ UART_SetLineConfig()

void UART_SetLineConfig | ( | UART_T * | uart,
|  | uint32_t | u32baudrate,
|  | uint32_t | u32data_width,
|  | uint32_t | u32parity,
|  | uint32_t | u32stop_bits
| ) |  |

Set UART line configuration.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32baudrate | The register value of baudrate of UART module. If u32baudrate = 0, UART baudrate will not change.
  [in] | u32data_width | The data length of UART module. UART_WORD_LEN_5 UART_WORD_LEN_6 UART_WORD_LEN_7 UART_WORD_LEN_8
  [in] | u32parity | The parity setting (none/odd/even/mark/space) of UART module. UART_PARITY_NONE UART_PARITY_ODD UART_PARITY_EVEN UART_PARITY_MARK UART_PARITY_SPACE
  [in] | u32stop_bits | The stop bit length (1/1.5/2 bit) of UART module. UART_STOP_BIT_1 UART_STOP_BIT_1_5 UART_STOP_BIT_2

Returns
  None

This function use to config UART line setting.

Definition at line 348 of file uart.c.

## ◆ UART_SetTimeoutCnt()

void UART_SetTimeoutCnt | ( | UART_T * | uart,
|  | uint32_t | u32TOC
| ) |  |

Set Rx timeout count.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | u32TOC | Rx timeout counter.

Returns
  None

This function use to set Rx timeout count.

Definition at line 437 of file uart.c.

## ◆ UART_Write()

uint32_t UART_Write | ( | UART_T * | uart,
|  | uint8_t | pu8TxBuf[],
|  | uint32_t | u32WriteBytes
| ) |  |

Write UART data.

Parameters

  [in] | uart | The pointer of the specified UART module.
  [in] | pu8TxBuf | The buffer to send the data to UART transmission FIFO.
  [out] | u32WriteBytes | The byte number of data.

Returns
  u32Count transfer byte count

The function is to write data into TX buffer to transmit data by UART.

Definition at line 612 of file uart.c.