Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
UART Interface

UART Interface. More...

Modules

 Async UART API
 
 Interrupt-driven UART API
 
 Polling UART API
 

Data Structures

struct  uart_config
 UART controller configuration structure. More...
 

Enumerations

enum  uart_line_ctrl {
  UART_LINE_CTRL_BAUD_RATE = BIT(0) , UART_LINE_CTRL_RTS = BIT(1) , UART_LINE_CTRL_DTR = BIT(2) , UART_LINE_CTRL_DCD = BIT(3) ,
  UART_LINE_CTRL_DSR = BIT(4)
}
 Line control signals. More...
 
enum  uart_rx_stop_reason {
  UART_ERROR_OVERRUN = (1 << 0) , UART_ERROR_PARITY = (1 << 1) , UART_ERROR_FRAMING = (1 << 2) , UART_BREAK = (1 << 3) ,
  UART_ERROR_COLLISION = (1 << 4) , UART_ERROR_NOISE = (1 << 5)
}
 Reception stop reasons. More...
 
enum  uart_config_parity {
  UART_CFG_PARITY_NONE , UART_CFG_PARITY_ODD , UART_CFG_PARITY_EVEN , UART_CFG_PARITY_MARK ,
  UART_CFG_PARITY_SPACE
}
 Parity modes. More...
 
enum  uart_config_stop_bits { UART_CFG_STOP_BITS_0_5 , UART_CFG_STOP_BITS_1 , UART_CFG_STOP_BITS_1_5 , UART_CFG_STOP_BITS_2 }
 Number of stop bits. More...
 
enum  uart_config_data_bits {
  UART_CFG_DATA_BITS_5 , UART_CFG_DATA_BITS_6 , UART_CFG_DATA_BITS_7 , UART_CFG_DATA_BITS_8 ,
  UART_CFG_DATA_BITS_9
}
 Number of data bits. More...
 
enum  uart_config_flow_control { UART_CFG_FLOW_CTRL_NONE , UART_CFG_FLOW_CTRL_RTS_CTS , UART_CFG_FLOW_CTRL_DTR_DSR , UART_CFG_FLOW_CTRL_RS485 }
 Hardware flow control options. More...
 

Functions

int uart_err_check (const struct device *dev)
 Check whether an error was detected.
 
int uart_configure (const struct device *dev, const struct uart_config *cfg)
 Set UART configuration.
 
int uart_config_get (const struct device *dev, struct uart_config *cfg)
 Get UART configuration.
 
int uart_line_ctrl_set (const struct device *dev, uint32_t ctrl, uint32_t val)
 Manipulate line control for UART.
 
int uart_line_ctrl_get (const struct device *dev, uint32_t ctrl, uint32_t *val)
 Retrieve line control for UART.
 
int uart_drv_cmd (const struct device *dev, uint32_t cmd, uint32_t p)
 Send extra command to driver.
 

Detailed Description

UART Interface.

Since
1.0
Version
1.0.0

Enumeration Type Documentation

◆ uart_config_data_bits

#include <zephyr/drivers/uart.h>

Number of data bits.

Enumerator
UART_CFG_DATA_BITS_5 

5 data bits

UART_CFG_DATA_BITS_6 

6 data bits

UART_CFG_DATA_BITS_7 

7 data bits

UART_CFG_DATA_BITS_8 

8 data bits

UART_CFG_DATA_BITS_9 

9 data bits

◆ uart_config_flow_control

#include <zephyr/drivers/uart.h>

Hardware flow control options.

With flow control set to none, any operations related to flow control signals can be managed by user with uart_line_ctrl functions. In other cases, flow control is managed by hardware/driver.

Enumerator
UART_CFG_FLOW_CTRL_NONE 

No flow control.

UART_CFG_FLOW_CTRL_RTS_CTS 

RTS/CTS flow control.

UART_CFG_FLOW_CTRL_DTR_DSR 

DTR/DSR flow control.

UART_CFG_FLOW_CTRL_RS485 

RS485 flow control.

◆ uart_config_parity

#include <zephyr/drivers/uart.h>

Parity modes.

Enumerator
UART_CFG_PARITY_NONE 

No parity.

UART_CFG_PARITY_ODD 

Odd parity.

UART_CFG_PARITY_EVEN 

Even parity.

UART_CFG_PARITY_MARK 

Mark parity.

UART_CFG_PARITY_SPACE 

Space parity.

◆ uart_config_stop_bits

#include <zephyr/drivers/uart.h>

Number of stop bits.

Enumerator
UART_CFG_STOP_BITS_0_5 

0.5 stop bit

UART_CFG_STOP_BITS_1 

1 stop bit

UART_CFG_STOP_BITS_1_5 

1.5 stop bits

UART_CFG_STOP_BITS_2 

2 stop bits

◆ uart_line_ctrl

#include <zephyr/drivers/uart.h>

Line control signals.

Enumerator
UART_LINE_CTRL_BAUD_RATE 

Baud rate.

UART_LINE_CTRL_RTS 

Request To Send (RTS)

UART_LINE_CTRL_DTR 

Data Terminal Ready (DTR)

UART_LINE_CTRL_DCD 

Data Carrier Detect (DCD)

UART_LINE_CTRL_DSR 

Data Set Ready (DSR)

◆ uart_rx_stop_reason

#include <zephyr/drivers/uart.h>

Reception stop reasons.

Values that correspond to events or errors responsible for stopping receiving.

Enumerator
UART_ERROR_OVERRUN 

Overrun error.

UART_ERROR_PARITY 

Parity error.

UART_ERROR_FRAMING 

Framing error.

UART_BREAK 

Break interrupt.

A break interrupt was received. This happens when the serial input is held at a logic '0' state for longer than the sum of start time + data bits + parity + stop bits.

UART_ERROR_COLLISION 

Collision error.

This error is raised when transmitted data does not match received data. Typically this is useful in scenarios where the TX and RX lines maybe connected together such as RS-485 half-duplex. This error is only valid on UARTs that support collision checking.

UART_ERROR_NOISE 

Noise error.

Function Documentation

◆ uart_config_get()

int uart_config_get ( const struct device dev,
struct uart_config cfg 
)

#include <zephyr/drivers/uart.h>

Get UART configuration.

Stores current UART configuration to *cfg, can be used to retrieve initial configuration after device was initialized using data from DTS.

Parameters
devUART device instance.
cfgUART configuration structure.
Return values
0If successful.
-errnoNegative errno code in case of failure.
-ENOSYSIf driver does not support getting current configuration.
-ENOTSUPIf API is not enabled.

◆ uart_configure()

int uart_configure ( const struct device dev,
const struct uart_config cfg 
)

#include <zephyr/drivers/uart.h>

Set UART configuration.

Sets UART configuration using data from *cfg.

Parameters
devUART device instance.
cfgUART configuration structure.
Return values
0If successful.
-errnoNegative errno code in case of failure.
-ENOSYSIf configuration is not supported by device or driver does not support setting configuration in runtime.
-ENOTSUPIf API is not enabled.

◆ uart_drv_cmd()

int uart_drv_cmd ( const struct device dev,
uint32_t  cmd,
uint32_t  p 
)

#include <zephyr/drivers/uart.h>

Send extra command to driver.

Implementation and accepted commands are driver specific. Refer to the drivers for more information.

Parameters
devUART device instance.
cmdCommand to driver.
pParameter to the command.
Return values
0If successful.
-ENOSYSIf this function is not implemented.
-ENOTSUPIf API is not enabled.
-errnoOther negative errno value in case of failure.

◆ uart_err_check()

int uart_err_check ( const struct device dev)

#include <zephyr/drivers/uart.h>

Check whether an error was detected.

Parameters
devUART device instance.
Return values
0If no error was detected.
errError flags as defined in uart_rx_stop_reason
-ENOSYSIf not implemented.

◆ uart_line_ctrl_get()

int uart_line_ctrl_get ( const struct device dev,
uint32_t  ctrl,
uint32_t val 
)

#include <zephyr/drivers/uart.h>

Retrieve line control for UART.

Parameters
devUART device instance.
ctrlThe line control to retrieve (see enum uart_line_ctrl).
valPointer to variable where to store the line control value.
Return values
0If successful.
-ENOSYSIf this function is not implemented.
-ENOTSUPIf API is not enabled.
-errnoOther negative errno value in case of failure.

◆ uart_line_ctrl_set()

int uart_line_ctrl_set ( const struct device dev,
uint32_t  ctrl,
uint32_t  val 
)

#include <zephyr/drivers/uart.h>

Manipulate line control for UART.

Parameters
devUART device instance.
ctrlThe line control to manipulate (see enum uart_line_ctrl).
valValue to set to the line control.
Return values
0If successful.
-ENOSYSIf this function is not implemented.
-ENOTSUPIf API is not enabled.
-errnoOther negative errno value in case of failure.