Skip to content

UART

Introduction

The MikroSDK.Driver.UART library provides a standardized API for controlling UART (Universal Asynchronous Receiver-Transmitter) peripherals on microcontrollers. This documentation covers essential functions, data structures, and examples needed to effectively use the UART driver in your projects.

UART is a widely used serial communication protocol in embedded systems for transmitting and receiving data. It is often used for communication between microcontrollers and peripherals such as sensors, displays, and other modules. The MikroSDK.Driver.UART library simplifies UART communication by providing a consistent API to configure, transmit, and receive data.

API Name

  • MikroSDK.Driver.UART

API Files

Prerequisites

  • Library Manager:

    • Select Driver.UART to add the API to your project using the Library Manager in NECTO Studio.
  • Headers:

    • Include the Driver.UART header in your source files to access the UART functions.
    • This header pops up in the lower right part of NECTO Studio once you perform the previous task (while selecting Driver.UART in Library Manager)
    • Alternatively, include the drv_uart.h header in your source files to access the UART functions.
  • CMakeLists:

    • You do not have to perform anything, configuration (CMake) file is already taken care of automatically while you performed the first task in this Prerequisites!
    • You can ensure that your CMakeLists.txt includes the necessary configurations to link against the MikroSDK.Driver.UART library.

Code Examples

  • How to properly test UART?
/* Project name:
 *  UART demo
 * Copyright:
 *  (c) MIKROE, 2024.
 * Description:
 *  Example is meant for demonstrating UART functionality using mikroSDK 2.0.
 * Library dependencies?
 *   - Make sure `Driver.UART`, `Driver.GPIO.Out` and `Board` libraries
 *     are enabled in NECTO's Library Manager to ensure a successful
 *     build.
 * How to test this code example?
 *   - If you're using one of the
 *     [MIKROE v8 boards](https://www.mikroe.com/development-boards-v8),
 *     make sure to plug in an USB Type C cable into USB-UART port,
 *     and make sure to enable Rx and Tx switches on the dev board.
 *     Otherwise you'll need the
 *     [USB UART Click](https://www.mikroe.com/usb-uart-click).
 *     If the latter, place it in a mikroBUS socket on the board
 *     you're using.
 *   - Make sure your hardware setup is properly configured:
 *     1. Go to `Setups` menu in the left navigation bar of NECTO
 *     2. Select your preferred hardware setup
 *     3. Select `Edit` to edit the hardware setup's configuration
 *     4. Select `Edit` in the `Compilers` category
 *     5. Make sure `Redirect standard output to` field
 *        has `UART` selected instead of `Application output`
 *     6. Save and finish configuring your hardware setup
 *   - Utilize NECTO's `UART Terminal` for UART transmission:
 *     1. Go to `Tools` -> `UART Terminal`
 *     2. Click on `Options`
 *     3. Select adequate port and set baud rate to 115200
 *     4. Click on `Configure` and then `Connect`
 *     5. Program the example by clicking on `Flash`
 *     6. You should see the greeting message on the terminal
 *     7. Now you can also send data and see it in the `Received data` section
 */

/**
 * @brief For a detailed explanation of this demo, please visit:
 * <https://libstock.mikroe.com/projects/view/5396/uart-demo>
 */

// ------------------------------------------------------------------ INCLUDES

/**
 * Any initialization code needed for MCU to function properly.
 * Do not remove this line or clock might not be set correctly.
 */
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif

#include "MikroSDK.Driver.GPIO.Out" // NOTE: this header is the same as `drv_digital_out.h`
#include "MikroSDK.Driver.UART" // NOTE: this header is the same as `drv_uart.h`
#include "MikroSDK.Board" // NOTE: this header is the same as `board.h`

#ifdef MikroCCoreVersion
    #if MikroCCoreVersion >= 1
        #include "delays.h"
    #endif
#endif

// -------------------------------------------------------------------- MACROS
// Return value in case of error
#define RET_FAIL (-1)

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_TX
#define USB_UART_TX NC // example: replace `NC` with `PA0`
#endif

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_RX
#define USB_UART_RX NC // example: replace `NC` with `PA1`
#endif

// UART baud rate
#define USB_UART_BAUD (115200)

#define TEST_PIN_UART_TX USB_UART_TX
#define TEST_PIN_UART_RX USB_UART_RX

// Define test pins yourself. If an error happens, assigned pin
// will go high and the program will stop there
#define TEST_PIN_1 NC
#define TEST_PIN_2 NC
#define TEST_PIN_3 NC
#define TEST_PIN_4 NC
#define TEST_PIN_5 NC
#define TEST_PIN_6 NC
#define TEST_PIN_7 NC
#define TEST_PIN_8 NC
#define TEST_PIN_9 NC
#define TEST_PIN_10 NC
#define TEST_PIN_11 NC
#define TEST_PIN_12 NC
#define TEST_PIN_13 NC
#define TEST_PIN_14 NC

#define signal_error(pin) digital_out_init( &test_pin, pin ); \
                          digital_out_high( &test_pin ); \
                          while(1)

// ----------------------------------------------------------------- VARIABLES
static uart_t uart;  // UART driver context structure
static uart_config_t uart_cfg;  // UART driver config context structure

static uint8_t uart_rx_buffer[128];
static uint8_t uart_tx_buffer[128];
static uint8_t buffer[32];

static int32_t read_size = 0;

static digital_out_t test_pin;
// ----------------------------------------------------------------- USER CODE
int main(void) {
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    if( TEST_PIN_UART_TX == HAL_PIN_NC || TEST_PIN_UART_RX == HAL_PIN_NC ) {
        printf_me( "Pins are not defined!\n" );
        signal_error( TEST_PIN_1 );
    }

    // Default config
    uart_configure_default( &uart_cfg );

    // Ring buffer mapping
    uart.tx_ring_buffer = uart_tx_buffer;
    uart.rx_ring_buffer = uart_rx_buffer;

    uart_cfg.tx_pin = TEST_PIN_UART_TX;  // UART TX pin
    uart_cfg.rx_pin = TEST_PIN_UART_RX;  // UART RX pin

    uart_cfg.tx_ring_size = sizeof( uart_tx_buffer );
    uart_cfg.rx_ring_size = sizeof( uart_rx_buffer );

    if( ACQUIRE_FAIL == uart_open( &uart, &uart_cfg ) ) {
        printf_me( "UART open failed.\n" );
        signal_error( TEST_PIN_2 );
    }

    //------------------------------------------------------------------------
    // UART settings
    //------------------------------------------------------------------------

    // Set baud rate
    if ( UART_SUCCESS != uart_set_baud( &uart, USB_UART_BAUD ) ) {
        printf_me( "UART set baud failed.\n" );
        signal_error( TEST_PIN_3 );
    }

    // Set data parity ( no parity )
    if ( UART_SUCCESS != uart_set_parity( &uart, UART_PARITY_DEFAULT ) ) {
        printf_me( "UART set parity failed.\n" );
        signal_error( TEST_PIN_4 );
    };

    // Set stop bits ( one stop bit )
    if ( UART_SUCCESS != uart_set_stop_bits( &uart, UART_STOP_BITS_DEFAULT ) ) {
        printf_me( "UART set stop bits failed.\n" );
        signal_error( TEST_PIN_5 );
    }

    // Set data bits ( 8-bit data )
    if ( UART_SUCCESS != uart_set_data_bits( &uart, UART_DATA_BITS_DEFAULT ) ) {
        printf_me( "UART set data bits failed.\n" );
        signal_error( TEST_PIN_6 );
    }

    Delay_100ms();

    //------------------------------------------------------------------------
    // EOF UART settings
    //------------------------------------------------------------------------

    // Write out data with new line
    if ( UART_ERROR == uart_println( &uart, "UART DEMO" ) ) {
        printf_me( "UART print failed.\n" );
        signal_error( TEST_PIN_7 );
    }

    // Delay needed because of `uart_clear` function,
    // so all data is transmitted
    Delay_100ms();

    // Write out data
    if ( UART_ERROR == uart_print( &uart, "Hello!" ) ) {
        printf_me( "UART println failed.\n" );
        signal_error( TEST_PIN_8 );
    }

    // Print new line
    if ( UART_ERROR == uart_println( &uart, "" ) ) {
        printf_me( "UART print failed.\n" );
        signal_error( TEST_PIN_9 );
    }

    // Delay needed because of `uart_clear` function,
    // so all data is transmitted
    Delay_100ms();

    // Clear rx and tx buffers
    uart_clear( &uart );

    // Check if buffers have been cleared
    if ( uart.config.tx_buf.head ||
         uart.config.tx_buf.tail ||
         uart.config.tx_buf.size )
    {
        printf_me( "UART TX buffer has not been cleared.\n" );
        signal_error( TEST_PIN_10 );
    }
    if ( uart.config.rx_buf.head ||
         uart.config.rx_buf.tail ||
         uart.config.rx_buf.size )
    {
        printf_me( "UART RX buffer has not been cleared.\n" );
        signal_error( TEST_PIN_11 );
    }

    // Set blocking mode
    uart_set_blocking( &uart, true );

    // Infinite number of reads - echo example
    while(1)
    {
        // Read data
        read_size = uart_read( &uart, buffer, sizeof( buffer ) );

        if ( read_size > 0 )  // If anything was read
        {
            // Write what you read
            read_size = uart_write( &uart, buffer, read_size );
        } else {
            printf_me( "UART read failed.\n" );
            signal_error( TEST_PIN_12 );
        }

        if ( uart.is_blocking && ( UART_ERROR == read_size ) ) {
            printf_me( "UART write failed.\n" );
            signal_error( TEST_PIN_13 );
        }
    }

    return 0;
}

// ----------------------------------------------------------------------- END
  • How do I initialize the UART with default settings?
/* Project name:
 *  How do I initialize the UART with default settings?
 * Copyright:
 *  (c) MIKROE, 2024.
 * Description:
 *  Example is meant for demonstrating UART functionality using mikroSDK 2.0.
 * Library dependencies?
 *   - Make sure `Driver.UART` and `Board` libraries
 *     are enabled in NECTO's Library Manager to ensure a successful
 *     build.
 */

/**
 * @brief For a detailed explanation of this demo, please visit:
 * <https://libstock.mikroe.com/projects/view/5396/uart-demo>
 */

// ------------------------------------------------------------------ INCLUDES

/**
 * Any initialization code needed for MCU to function properly.
 * Do not remove this line or clock might not be set correctly.
 */
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif

#include "MikroSDK.Driver.UART" // NOTE: this header is the same as `drv_uart.h`
#include "MikroSDK.Board" // NOTE: this header is the same as `board.h`

#ifdef MikroCCoreVersion
    #if MikroCCoreVersion >= 1
        #include "delays.h"
    #endif
#endif

// -------------------------------------------------------------------- MACROS
// Return value in case of error
#define RET_FAIL (-1)

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_TX
#define USB_UART_TX NC // example: replace `NC` with `PA0`
#endif

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_RX
#define USB_UART_RX NC // example: replace `NC` with `PA1`
#endif

// UART baud rate
#define USB_UART_BAUD (115200)

#define TEST_PIN_UART_TX USB_UART_TX
#define TEST_PIN_UART_RX USB_UART_RX

// ----------------------------------------------------------------- VARIABLES
static uart_t uart;  // UART driver context structure
static uart_config_t uart_cfg;  // UART driver config context structure

static uint8_t uart_rx_buffer[128];
static uint8_t uart_tx_buffer[128];

// ----------------------------------------------------------------- USER CODE
int main(void) {
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    if( TEST_PIN_UART_TX == HAL_PIN_NC || TEST_PIN_UART_RX == HAL_PIN_NC ) {
        printf_me( "Pins are not defined!\n" );
    }

    // Default config
    uart_configure_default( &uart_cfg );

    // Ring buffer mapping
    uart.tx_ring_buffer = uart_tx_buffer;
    uart.rx_ring_buffer = uart_rx_buffer;

    uart_cfg.tx_pin = TEST_PIN_UART_TX;  // UART TX pin
    uart_cfg.rx_pin = TEST_PIN_UART_RX;  // UART RX pin

    uart_cfg.tx_ring_size = sizeof( uart_tx_buffer );
    uart_cfg.rx_ring_size = sizeof( uart_rx_buffer );

    if( ACQUIRE_FAIL == uart_open( &uart, &uart_cfg ) ) {
        printf_me( "UART open failed.\n" );
    }

    //------------------------------------------------------------------------
    // UART default settings
    //------------------------------------------------------------------------

    // Set baud rate
    if ( UART_SUCCESS != uart_set_baud( &uart, USB_UART_BAUD ) ) {
        printf_me( "UART set baud failed.\n" );
    }

    // Set data parity ( no parity )
    if ( UART_SUCCESS != uart_set_parity( &uart, UART_PARITY_DEFAULT ) ) {
        printf_me( "UART set parity failed.\n" );
    };

    // Set stop bits ( one stop bit )
    if ( UART_SUCCESS != uart_set_stop_bits( &uart, UART_STOP_BITS_DEFAULT ) ) {
        printf_me( "UART set stop bits failed.\n" );
    }

    // Set data bits ( 8-bit data )
    if ( UART_SUCCESS != uart_set_data_bits( &uart, UART_DATA_BITS_DEFAULT ) ) {
        printf_me( "UART set data bits failed.\n" );
    }

    Delay_100ms();

    //------------------------------------------------------------------------
    // EOF UART default settings
    //------------------------------------------------------------------------

    return 0;
}

// ----------------------------------------------------------------------- END
  • How do I write/read data to/from the UART?
/* Project name:
 *  How do I write/read data to/from the UART?
 * Copyright:
 *  (c) MIKROE, 2024.
 * Description:
 *  Example is meant for demonstrating UART functionality using mikroSDK 2.0.
 * Library dependencies?
 *   - Make sure `Driver.UART`, `Driver.GPIO.Out` and `Board` libraries
 *     are enabled in NECTO's Library Manager to ensure a successful
 *     build.
 * How to test this code example?
 *   - If you're using one of the
 *     [MIKROE v8 boards](https://www.mikroe.com/development-boards-v8),
 *     make sure to plug in an USB Type C cable into USB-UART port,
 *     and make sure to enable Rx and Tx switches on the dev board.
 *     Otherwise you'll need the
 *     [USB UART Click](https://www.mikroe.com/usb-uart-click).
 *     If the latter, place it in a mikroBUS socket on the board
 *     you're using.
 *   - Make sure your hardware setup is properly configured:
 *     1. Go to `Setups` menu in the left navigation bar of NECTO
 *     2. Select your preferred hardware setup
 *     3. Select `Edit` to edit the hardware setup's configuration
 *     4. Select `Edit` in the `Compilers` category
 *     5. Make sure `Redirect standard output to` field
 *        has `UART` selected instead of `Application output`
 *     6. Save and finish configuring your hardware setup
 *   - Utilize NECTO's `UART Terminal` for UART transmission:
 *     1. Go to `Tools` -> `UART Terminal`
 *     2. Click on `Options`
 *     3. Select adequate port and set baud rate to 115200
 *     4. Click on `Configure` and then `Connect`
 *     5. Program the example by clicking on `Flash`
 *     6. You should see the greeting message on the terminal
 *     7. Now you can also send data and see it in the `Received data` section
 */

// ------------------------------------------------------------------ INCLUDES

/**
 * Any initialization code needed for MCU to function properly.
 * Do not remove this line or clock might not be set correctly.
 */
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif

#include "MikroSDK.Driver.GPIO.Out" // NOTE: this header is the same as `drv_digital_out.h`
#include "MikroSDK.Driver.UART" // NOTE: this header is the same as `drv_uart.h`
#include "MikroSDK.Board" // NOTE: this header is the same as `board.h`

#ifdef MikroCCoreVersion
    #if MikroCCoreVersion >= 1
        #include "delays.h"
    #endif
#endif

// -------------------------------------------------------------------- MACROS
// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_TX
#define USB_UART_TX NC // example: replace `NC` with `PA0`
#endif

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_RX
#define USB_UART_RX NC // example: replace `NC` with `PA1`
#endif

// UART baud rate
#define USB_UART_BAUD (115200)

#define TEST_PIN_UART_TX USB_UART_TX
#define TEST_PIN_UART_RX USB_UART_RX

// ----------------------------------------------------------------- VARIABLES
static uart_t uart;  // UART driver context structure
static uart_config_t uart_cfg;  // UART driver config context structure

static uint8_t uart_rx_buffer[128];
static uint8_t uart_tx_buffer[128];
static uint8_t buffer[32];

static int32_t read_size = 0;

// ----------------------------------------------------------------- USER CODE
int main(void) {
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    if( TEST_PIN_UART_TX == HAL_PIN_NC || TEST_PIN_UART_RX == HAL_PIN_NC ) {
        printf_me( "Pins are not defined!\n" );
    }

    // Default config
    uart_configure_default( &uart_cfg );

    // Ring buffer mapping
    uart.tx_ring_buffer = uart_tx_buffer;
    uart.rx_ring_buffer = uart_rx_buffer;

    uart_cfg.tx_pin = TEST_PIN_UART_TX;  // UART TX pin
    uart_cfg.rx_pin = TEST_PIN_UART_RX;  // UART RX pin

    uart_cfg.tx_ring_size = sizeof( uart_tx_buffer );
    uart_cfg.rx_ring_size = sizeof( uart_rx_buffer );

    if( ACQUIRE_FAIL == uart_open( &uart, &uart_cfg ) ) {
        printf_me( "UART open failed.\n" );
    }

    //------------------------------------------------------------------------
    // UART default settings
    //------------------------------------------------------------------------

    // Set baud rate
    if ( UART_SUCCESS != uart_set_baud( &uart, USB_UART_BAUD ) ) {
        printf_me( "UART set baud failed.\n" );
    }

    // Set data parity ( no parity )
    if ( UART_SUCCESS != uart_set_parity( &uart, UART_PARITY_DEFAULT ) ) {
        printf_me( "UART set parity failed.\n" );
    };

    // Set stop bits ( one stop bit )
    if ( UART_SUCCESS != uart_set_stop_bits( &uart, UART_STOP_BITS_DEFAULT ) ) {
        printf_me( "UART set stop bits failed.\n" );
    }

    // Set data bits ( 8-bit data )
    if ( UART_SUCCESS != uart_set_data_bits( &uart, UART_DATA_BITS_DEFAULT ) ) {
        printf_me( "UART set data bits failed.\n" );
    }

    // Delay needed because of `uart_clear` function,
    // so all data is transmitted
    Delay_100ms();

    //------------------------------------------------------------------------
    // EOF UART default settings
    //------------------------------------------------------------------------

    // Clear rx and tx buffers
    uart_clear( &uart );

    // Check if buffers have been cleared
    if ( uart.config.tx_buf.head ||
         uart.config.tx_buf.tail ||
         uart.config.tx_buf.size )
    {
        printf_me( "UART TX buffer has not been cleared.\n" );
    }
    if ( uart.config.rx_buf.head ||
         uart.config.rx_buf.tail ||
         uart.config.rx_buf.size )
    {
        printf_me( "UART RX buffer has not been cleared.\n" );
    }

    // Set blocking mode
    uart_set_blocking( &uart, true );

    // Infinite number of reads - echo example
    while(1)
    {
        // Read data
        read_size = uart_read( &uart, buffer, sizeof( buffer ) );

        if ( read_size > 0 )  // If anything was read
        {
            // Write what you read
            read_size = uart_write( &uart, buffer, read_size );
        } else {
            printf_me( "UART read failed.\n" );
        }

        if ( uart.is_blocking && ( UART_ERROR == read_size ) ) {
            printf_me( "UART write failed.\n" );
        }
    }

    return 0;
}
  • How do I print a string to the UART?
/* Project name:
 *  How do I print a string to the UART?
 * Copyright:
 *  (c) MIKROE, 2024.
 * Description:
 *  Example is meant for demonstrating UART functionality using mikroSDK 2.0.
 * Library dependencies?
 *   - Make sure `Driver.UART`, `Driver.GPIO.Out` and `Board` libraries
 *     are enabled in NECTO's Library Manager to ensure a successful
 *     build.
 * How to test this code example?
 *   - If you're using one of the
 *     [MIKROE v8 boards](https://www.mikroe.com/development-boards-v8),
 *     make sure to plug in an USB Type C cable into USB-UART port,
 *     and make sure to enable Rx and Tx switches on the dev board.
 *     Otherwise you'll need the
 *     [USB UART Click](https://www.mikroe.com/usb-uart-click).
 *     If the latter, place it in a mikroBUS socket on the board
 *     you're using.
 *   - Make sure your hardware setup is properly configured:
 *     1. Go to `Setups` menu in the left navigation bar of NECTO
 *     2. Select your preferred hardware setup
 *     3. Select `Edit` to edit the hardware setup's configuration
 *     4. Select `Edit` in the `Compilers` category
 *     5. Make sure `Redirect standard output to` field
 *        has `UART` selected instead of `Application output`
 *     6. Save and finish configuring your hardware setup
 *   - Utilize NECTO's `UART Terminal` for UART transmission:
 *     1. Go to `Tools` -> `UART Terminal`
 *     2. Click on `Options`
 *     3. Select adequate port and set baud rate to 115200
 *     4. Click on `Configure` and then `Connect`
 *     5. Program the example by clicking on `Flash`
 *     6. You should see the greeting message on the terminal
 */

// ------------------------------------------------------------------ INCLUDES

/**
 * Any initialization code needed for MCU to function properly.
 * Do not remove this line or clock might not be set correctly.
 */
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif

#include "MikroSDK.Driver.GPIO.Out" // NOTE: this header is the same as `drv_digital_out.h`
#include "MikroSDK.Driver.UART" // NOTE: this header is the same as `drv_uart.h`
#include "MikroSDK.Board" // NOTE: this header is the same as `board.h`

#ifdef MikroCCoreVersion
    #if MikroCCoreVersion >= 1
        #include "delays.h"
    #endif
#endif

// -------------------------------------------------------------------- MACROS
// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_TX
#define USB_UART_TX NC // example: replace `NC` with `PA0`
#endif

// If hardware without USB_UART port is used, make sure
// to define adequate pin.
#ifndef USB_UART_RX
#define USB_UART_RX NC // example: replace `NC` with `PA1`
#endif

// UART baud rate
#define USB_UART_BAUD (115200)

#define TEST_PIN_UART_TX USB_UART_TX
#define TEST_PIN_UART_RX USB_UART_RX

// ----------------------------------------------------------------- VARIABLES
static uart_t uart;  // UART driver context structure
static uart_config_t uart_cfg;  // UART driver config context structure

static uint8_t uart_rx_buffer[128];
static uint8_t uart_tx_buffer[128];
static uint8_t buffer[32];

static int32_t read_size = 0;

// ----------------------------------------------------------------- USER CODE
int main(void) {
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    if( TEST_PIN_UART_TX == HAL_PIN_NC || TEST_PIN_UART_RX == HAL_PIN_NC ) {
        printf_me( "Pins are not defined!\n" );
    }

    // Default config
    uart_configure_default( &uart_cfg );

    // Ring buffer mapping
    uart.tx_ring_buffer = uart_tx_buffer;
    uart.rx_ring_buffer = uart_rx_buffer;

    uart_cfg.tx_pin = TEST_PIN_UART_TX;  // UART TX pin
    uart_cfg.rx_pin = TEST_PIN_UART_RX;  // UART RX pin

    uart_cfg.tx_ring_size = sizeof( uart_tx_buffer );
    uart_cfg.rx_ring_size = sizeof( uart_rx_buffer );

    if( ACQUIRE_FAIL == uart_open( &uart, &uart_cfg ) ) {
        printf_me( "UART open failed.\n" );
    }

    //------------------------------------------------------------------------
    // UART default settings
    //------------------------------------------------------------------------

    // Set baud rate
    if ( UART_SUCCESS != uart_set_baud( &uart, USB_UART_BAUD ) ) {
        printf_me( "UART set baud failed.\n" );
    }

    // Set data parity ( no parity )
    if ( UART_SUCCESS != uart_set_parity( &uart, UART_PARITY_DEFAULT ) ) {
        printf_me( "UART set parity failed.\n" );
    };

    // Set stop bits ( one stop bit )
    if ( UART_SUCCESS != uart_set_stop_bits( &uart, UART_STOP_BITS_DEFAULT ) ) {
        printf_me( "UART set stop bits failed.\n" );
    }

    // Set data bits ( 8-bit data )
    if ( UART_SUCCESS != uart_set_data_bits( &uart, UART_DATA_BITS_DEFAULT ) ) {
        printf_me( "UART set data bits failed.\n" );
    }

    // Delay needed because of `uart_clear` function,
    // so all data is transmitted
    Delay_100ms();

    //------------------------------------------------------------------------
    // EOF UART default settings
    //------------------------------------------------------------------------

    // Write out data
    if ( UART_ERROR == uart_print( &uart, "Hello!" ) ) {
        printf_me( "UART println failed.\n" );
    }

    // Set blocking mode
    uart_set_blocking( &uart, true );

    return 0;
}