# UART API

This page aggregates all C++ UART-related public methods of the class CosmicAsyncSDK.

group CosmicSDK UART API

  Constants and APIs related to UART operations.

  Functions

  uint16_t uartSetBusVoltage(uint16_t id, uint16_t voltage_mV, bool persist = false)

    Set the operating voltage of the UART interface.

    Warning

    On Supernova and Pulsar host adapters, the UART interface shares the same voltage domain as I2C, SPI and GPIOs. As a result, calling this method to set the UART voltage will also affect the voltage of I2C, SPI and GPIO interfaces. This must be taken into account when more than one interface is used simultaneously.

    Parameters:

      - id – uint16_t Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - voltage_mV – uint16_t Voltage in millivolts to set the UART interface to. The valid values are 0 mV, and any value in the range 1200 to 3300 mV. The value 0mV deactivates the VTARG pin and turn offs the downstream devices.

      - persist – bool If true, the voltage setting will be persistent across power cycles. This ensures that any DUT connected to the UART interface (e.g. via Pulsar or Supernova) will receive power immediately upon startup, without waiting for the host to issue the voltage set command. If false, the setting will only apply to the current session.

    Returns:

      uint16_t Result of the request.

  uint16_t uartInit(uint16_t id, UartBaudRate baudrate, UartHwHandshake hardwareHandshake, UartParity parityMode, UartDataSize dataSize, UartStopBit stopBit)

    Initialize the UART interface.

    This function initializes the UART peripheral and must be called successfully before any other UART-related API is used.

    Note

    - This function must be called exactly once.

    - To modify the UART configuration after initialization, use uartSetParameters instead of reinitializing the interface.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - baudrate – UART baud rate used for both transmission (TX) and reception (RX). See UartBaudRate for supported values.

      - hardwareHandshake – Enables or disables hardware flow control (RTS/CTS), if supported by the underlying hardware. See UartHwHandshake for supported values.

      - parityMode – UART parity configuration. See UartParity for supported values.

      - dataSize – Number of data bits per UART frame. See UartDataSize for supported values.

      - stopBit – Number of stop bits per UART frame. See UartStopBit for supported values.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t uartSetParameters(uint16_t id, UartBaudRate baudrate, UartHwHandshake hardwareHandshake, UartParity parityMode, UartDataSize dataSize, UartStopBit stopBit)

    Configure UART peripheral communication parameters.

    This function updates the UART communication parameters after the UART interface has been successfully initialized using uartInit. It allows runtime reconfiguration of the UART without requiring a full deinitialization or reinitialization of the peripheral.

    Note

    - This function must only be called after a successful call to uartInit.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - baudrate – UART baud rate used for both transmission (TX) and reception (RX). See UartBaudRate for supported values.

      - hardwareHandshake – Enables or disables hardware flow control (RTS/CTS), if supported by the underlying hardware. See UartHwHandshake for supported values.

      - parityMode – UART parity configuration. See UartParity for supported values.

      - dataSize – Number of data bits per UART frame. See UartDataSize for supported values.

      - stopBit – Number of stop bits per UART frame. See UartStopBit for supported values.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.

  uint16_t uartSendMessage(uint16_t id, const std::vector<uint8_t> &inData)

    Transmit a UART message through the host adapter device.

    Requests the host adapter to send data using the currently active UART configuration (see uartInit and uartSetParameters).

    Note

    - The UART interface must be successfully initialized with uartInit before calling this function.

    Parameters:

      - id – Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      - inData – Reference to the vector containing the bytes to transmit.

    Return values:

      - SUCCESS – The command was successfully sent to the host adapter.

      - SDK_ERROR_DISCONNECT – The device was disconnected or became unavailable during the operation.