Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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)
}
 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 }
 Hardware flow control options. More...
 

Functions

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

Detailed Description

UART Interface.

Enumeration Type Documentation

◆ uart_config_data_bits

#include <include/drivers/uart.h>

Number of data bits.

Enumerator
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 

◆ uart_config_flow_control

#include <include/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 
UART_CFG_FLOW_CTRL_RTS_CTS 
UART_CFG_FLOW_CTRL_DTR_DSR 

◆ uart_config_parity

#include <include/drivers/uart.h>

Parity modes.

Enumerator
UART_CFG_PARITY_NONE 
UART_CFG_PARITY_ODD 
UART_CFG_PARITY_EVEN 
UART_CFG_PARITY_MARK 
UART_CFG_PARITY_SPACE 

◆ uart_config_stop_bits

#include <include/drivers/uart.h>

Number of stop bits.

Enumerator
UART_CFG_STOP_BITS_0_5 
UART_CFG_STOP_BITS_1 
UART_CFG_STOP_BITS_1_5 
UART_CFG_STOP_BITS_2 

◆ uart_line_ctrl

#include <include/drivers/uart.h>

Line control signals.

Enumerator
UART_LINE_CTRL_BAUD_RATE 
UART_LINE_CTRL_RTS 
UART_LINE_CTRL_DTR 
UART_LINE_CTRL_DCD 
UART_LINE_CTRL_DSR 

◆ uart_rx_stop_reason

#include <include/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.

Function Documentation

◆ uart_config_get()

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

#include <include/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.

◆ uart_configure()

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

#include <include/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.

◆ uart_drv_cmd()

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

#include <include/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 <include/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 <include/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 <include/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.