UART API

Defines

K_NUM_UARTS YOTTA_CFG_HARDWARE_UART_COUNT

KubOS-HAL UART Interface.

Author
kubos.co Number of UART interfaces available. Derived from value in target.json
"config": {
  "hardware": {
    "uart": {
      "count": 2
    }
  }
}

K_UART_CONSOLE YOTTA_CFG_HARDWARE_CONSOLE_UART

Uart interface used for console output.

"config": {
  "hardware": {
    "console": {
      "uart": "K_UART1"
    }
  }
}

K_UART_CONSOLE_BAUDRATE YOTTA_CFG_HARDWARE_CONSOLE_BAUDRATE

Baudrate used for console output.

"config": {
  "hardware": {
    "console": {
      "baudrate": "115200"
    }
  }
}

Enums

enum KUARTNum

Available UART interfaces.

Values:

enum KWordLen

Word length.

Note
MSP430F5 does not support 9-bit mode

Values:

K_WORD_LEN_7BIT = 0
K_WORD_LEN_8BIT
K_WORD_LEN_9BIT
enum KStopBits

Number of stop bits.

Values:

K_STOP_BITS_1 = 0
K_STOP_BITS_2
enum KParity

Parity setting.

Values:

K_PARITY_NONE = 0
K_PARITY_EVEN
K_PARITY_ODD
enum KUARTStatus

Uart status values.

Values:

UART_OK
UART_ERROR
UART_ERROR_NULL_HANDLE
UART_ERROR_CONFIG

Functions

KUARTConf k_uart_conf_defaults(void)

Generate KUARTConf with default UART values.

Return
KUARTConf

KUARTStatus k_uart_init(KUARTNum uart, KUARTConf *conf)

Setup and enable UART interface.

Return
KUARTStatus UART_OK if OK, failure otherwise
Parameters
  • uart: UART interface to initialize
  • conf: config values to initialize with

void k_uart_terminate(KUARTNum uart)

Terminates UART interface.

Parameters
  • uart: UART interface to terminate

void k_uart_console_init(void)

Setup and enable console UART interface.

int k_uart_read(KUARTNum uart, char *ptr, int len)

Interrupt driven function for reading data from a UART interface.

This function reads from a queue which is filled up via the UART interrupt handler.

Return
int number of characters read or -1 to indicate a null UART handle
Parameters
  • uart: UART interface to read from
  • ptr: buffer to read data into
  • len: length of data to read

int k_uart_write(KUARTNum uart, char *ptr, int len)

Interrupt driven function for writing data to a UART interface.

This function writes data into a queue which is then written out in the interrupt handler.

Return
int number of characters written or -1 to indicate a null UART handle
Parameters
  • uart: UART interface to write to
  • ptr: buffer to write data from
  • len: length of data to write

KUARTStatus k_uart_write_immediate(KUARTNum uart, char c)

Write data directly to a UART interface.

Return
KUARTStatus UART_OK if success, otherwise failure
Parameters
  • uart: UART interface to write to
  • c: character to write

KUARTStatus k_uart_write_immediate_str(KUARTNum uart, uint8_t *ptr, uint8_t len)

Write data directly to a UART interface.

Return
KUARTStatus UART_OK if success, otherwise failure
Parameters
  • uart: UART interface to write to
  • ptr: buffer to write data from
  • len: length of data to write

int k_uart_rx_queue_len(KUARTNum uart)

Returns the number of characters currently in the UART rx queue.

Return
int length of UART’s rx_queue
Parameters
  • uart: UART interface number or -1 to indicate a null UART handle or -2 to indicate a null rx queue pointer

void k_uart_rx_queue_push(KUARTNum uart, char c, void *task_woken)

Pushes a character into the UART rx queue.

Parameters
  • uart: UART interface number
  • c: character to push
  • task_woken: used by FreeRTOS to determine task blocking

int k_uart_rx_pin(KUARTNum uart)

Returns rx pin for specified UART interface.

Return
int rx pin
Parameters
  • uart: UART interface number

int k_uart_tx_pin(KUARTNum uart)

Returns tx pin for specified UART interface.

Return
int tx pin
Parameters
  • uart: UART interface number

KUART *kprv_uart_get(KUARTNum uart)

Returns UART data structure for specified interface.

Return
KUART* pointer to UART data structure
Parameters
  • uart: UART interface number

KUARTStatus kprv_uart_dev_init(KUARTNum uart)

Performs low-level UART hardware initialization.

Return
KUARTStatus UART_OK if OK, failure otherwise
Parameters
  • uart: UART interface to initialize

void kprv_uart_dev_terminate(KUARTNum uart)

Performs low-level UART hardware termination.

Parameters
  • uart: UART interface to initialize

void kprv_uart_enable_tx_int(KUARTNum uart)

Enables UART transmit interrupt.

Parameters
  • uart: UART interface number

struct KUARTConf
#include <uart.h>

Uart configuration structure.

Public Members

const char *dev_path

The path of the UART bus.

uint32_t baud_rate

The buad rate of the UART bus.

Warning
For the MSP430F5 microcontroller, the speed of the SPI bus can only be defined as a factor of the peripheral clock to which it’s connected (SMCLK for MSP430F5 SPI buses). For example, SMCLK_speed / 2. To make things easier, this speed field will take a normal baud rate number and then it will automatically be converted to the nearest available system speed without exceeding the original value.

KWordLen word_len

The number of data bits in each transmit/receive of the UART bus.

Can be 7-, 8-, or 9-bits, as specified by the KWordLen enumerator

KStopBits stop_bits

The number of stop bits at the end of each transmit/receive of the UART bus.

Can be 1 or 2 bits, as specified by the KStopBits enumerator

KParity parity

The presence and state of the parity bit in each transmit/receive of the UART bus.

Can be none, odd, or even, as specified by the KParity enumerator

uint8_t rx_queue_len

The size of the queue for incoming messages.

uint8_t tx_queue_len

The size of the queue for outgoing messages.

struct KUART
#include <uart.h>

Uart interface data structure.

Public Members

int dev

UART device number.

KUARTConf conf

Copy of UART configuration options.

csp_queue_handle_t rx_queue

Queue filled with received UART data.

csp_queue_handle_t tx_queue

Queue filled with data to be sent.