UART and USART Initialization and Configuration#

Overview#

The SiWx917 Software Development Kit (SDK) provides a unified Universal Asynchronous Receiver/Transmitter (UART) and Universal Synchronous/Asynchronous Receiver/Transmitter (USART) driver API that supports multiple instances with configurable communication parameters, interrupt and Direct Memory Access (DMA) support, and power management features. This guide explains the initialization and configuration process for UART and USART communication.

For more details about developing with the WiSeConnect SDK, see the WiSeConnect 3 documentation.

Startup Sequence#

The startup sequence defines how to create, configure, and test UART and USART peripherals in Simplicity Studio. The following section provides a step-by-step process.

Step-by-Step UART and USART Initialization and Configuration in Simplicity Studio#

Follow these steps to set up UART and USART peripherals on Si91x devices using Simplicity Studio and the WiSeConnect SDK:

Step 1. Create or open your project#

  1. Launch Simplicity Studio.

  2. Create a new project for your Si91x device, or open an existing one.

  3. For demonstration, select one of the UART/ USART example projects available in the WiSeConnect SDK.

  4. Connect your Si91x radio board. Simplicity Studio detects it automatically.

    Board detection in Simplicity StudioBoard detection in Simplicity Studio

  5. Open a UART or USART example project from the Example Projects and Demos section.

    UART projectUART project
    USART projectUSART project

  6. Click Create to add the project to your workspace. You can view the project documentation to understand the reference project and its usage.

  7. After project creation and configuration, Simplicity Studio generates the following directory structure. Most examples open readme.md by default.

     ![Project creation](resources/project-creation.png)
    
     - `autogen/`: Auto-generated files (configuration headers,
         linker scripts)
     - `config/` Platform-specific configuration headers
     - `resources/`: Documentation images and resources
     - `simplicity_sdk\`: Gecko SDK platform layer and
         third-party libraries
     - `platform/`: Hardware Abstraction Layer (HAL), Cortex Microcontroller Software Interface Standard (CMSIS) RTOS,
         and common libraries
     - `wiseconnect3_sdk\`: WiSeConnect SDK components
         and resources
     - `app.c`: Main application source file
     - `app.h`: Main application header file
     - `uart_example.c`: UART example source file
     - `uart_example.h`: UART example header file
     - `main.c`: Application entry point
     - `readme.md`: Example documentation and usage
         instructions
     - `sl_si91x_uart.slcp`: Main project configuration file
     - `sl_si91x_uart.pintool`: Pin Tool configuration for UART
         peripheral pins
     - `sl_si91x_uart.slps`: Project set file for managing
         related solutions

Step 2. Add the UART or USART component#

  1. In the project's .slcp configuration file, go to the Software Components tab.

    • Search for "UART" or "USART" and add the required peripheral instance (for example, USART, UART, and ULP_UART).

      The following image shows UART as an example:

      Project creationProject creation

Step 3. Configure UART or USART using the Universal Configurator (UC)#

  1. Click Configure to set up the UART or USART instance.

    UART default UCUART default UC

  2. In the UC graphical interface, configure:

    • Baud rate

    • Data width

    • Stop bits

    • Parity

    • Flow control (CTS/RTS)

    • Pin assignment for RX, TX, CTS, RTS, DE, RE

    Only valid pins for the selected instance appear in the dropdown.

  3. Select pins using the Pin Tool.

    UART PintoolUART Pintool

Step 4. Generate Initialization Code#

Simplicity Studio auto-generates driver and configuration files when you add or modify UART or USART components.

  • Click View Source in the UC configuration UI to view the generated configuration files.

    UART config fileUART config file

Step 5. Build, Flash, and Test#

Simplicity Studio provides a built-in Virtual COM (VCOM) console to view logs. Use it to monitor device logs.

Example initialization and configuration steps in code:

  1. Select the instance for initialization.

    Instance selectionInstance selection

  2. Set baud rate, data bits, stop bits, parity, flow control, and mode as required. Use UC files for default values, or set them at runtime.

    Parameters configureParameters configure

  3. Call initialization APIs to enable clocks, power domains, and register event callbacks.

    API initializationAPI initialization

  4. Configure interrupt sources or DMA for advanced use cases. Register callback and event handlers.

    Register callbackRegister callback

  5. Send and receive data. Use loopback or an external device for validation.

    Send receive dataSend receive data

UC (Universal Configurator) Configuration#

The UC system provides compile-time configuration that optimizes performance and reduces runtime overhead. UC files allow developers to specify default parameters, pin assignments, and peripheral options in one place. This approach is useful for large projects or production firmware where runtime flexibility is less critical.

Benefits of the UC System#

  • Centralized configuration management

  • Reduced runtime code size and complexity

  • Consistent default values across builds

Configurable Parameters and Default Values#

The following sections describe configurable parameters and their defaults when setting up UART and USART peripherals.

Using the UC Configuration Tool for UART Setup#

  • Baud rate: Enter the desired baud rate (for example, 115200).

  • Parity: Choose None, Even, or Odd.

  • Stop bits: Set the number of stop bits (usually 1 or 2).

  • Data width: Select the number of data bits (typically 8).

  • Flow control: Enable or disable hardware flow control (CTS/RTS).

UART default UCUART default UC

Using the UC Configuration Tool for USART Setup#

  • Baud rate: Enter the desired baud rate.

  • Mode: Select the communication mode (for example, Synchronous Master, Asynchronous).

  • Parity: Choose None, Even, or Odd.

  • Stop bits: Set the number of stop bits.

  • Data width: Select the number of data bits (typically 8).

  • Flow control: Enable or disable hardware flow control (CTS/RTS).

Examples:

USART asynchronous modeUSART asynchronous mode USART synchronous master modeUSART synchronous master mode USART synchronous slave modeUSART synchronous slave mode

Note: If the Universal Configurator (UC) is disabled or not used, all UART/USART configuration parameters can be set directly in the application code. Below is the snippet for setting configuration parameters from application.

  sl_si91x_usart_control_config_t uart_config;
  uart_config.baudrate      = UART_BAUDRATE;
  uart_config.mode          = SL_USART_MODE_ASYNCHRONOUS;
  uart_config.parity        = SL_USART_NO_PARITY;
  uart_config.stopbits      = SL_USART_STOP_BITS_1;
  uart_config.hwflowcontrol = SL_USART_FLOW_CONTROL_NONE;
  uart_config.databits      = SL_USART_DATA_BITS_8;
  uart_config.misc_control  = SL_USART_MISC_CONTROL_NONE;
  uart_config.usart_module  = UART_1;
  uart_config.config_enable = ENABLE;
  uart_config.synch_mode    = DISABLE;

General-Purpose Input/Output (GPIO) Pin Assignment#

Assign pins for UART and USART signals as part of UC setup.

  • RX/TX pins: Use the dropdowns to assign pins. Only listed pins are valid.

  • CTS/RTS pins: If flow control is enabled, assign pins for CTS and RTS. Otherwise, leave them set to None.

GPIO pin selectionGPIO pin selection

RS-485 Configuration and Usage#

The SiWx917 UART and USART peripheral supports RS-485 communication for multi-drop and industrial applications.

  • Purpose: RS-485 enables half-duplex or full-duplex serial communication with multiple devices on a shared bus. It supports 9-bit addressing for multi-slave systems.

  • Pin assignment: RS-485 requires Driver Enable (DE) and Receiver Enable (~RE) pins in addition to TX and RX.

  • Configuration:

    • Use the UC configuration tool to select RS-485 transfer mode (hardware/software half-duplex, full-duplex).

    • Configure DE and RE polarity, timing, and turnaround.

    • Assign unique addresses to slave devices.

      Hardware half-duplex UC Hardware half-duplexHardware half-duplex

      Software half-duplex UC Software half-duplexSoftware half-duplex

  • Initialization:

    // Initialize the UART
        status = sl_si91x_usart_init(UART_INSTANCE, &uart_rs485_handle);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_usart_initialize: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("UART initialization is successful \n");
        // Configure the UART configurations
        status = sl_si91x_usart_set_configuration(uart_rs485_handle, &uart_rs485_config);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_usart_set_configuration: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("UART configuration is successful \n");
        // Initialize RS485 pins and Enable RS485 module
        status = sl_si91x_uart_rs485_init(UART_INSTANCE);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_uart_rs485_init: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("RS485 initialization successful\n");
        // Enable Driver enable
        status = sl_si91x_uart_rs485_de_enable(UART_INSTANCE, ENABLE);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_uart_rs485_de_enable: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("RS485 DE enable successful\n");
        // Enable Receiver Enable
        status = sl_si91x_uart_rs485_re_enable(UART_INSTANCE, ENABLE);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_uart_rs485_re_enable: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("RS485 RE enable successful\n");
        // Configure RS485 configurations
        status = sl_si91x_uart_rs485_set_configuration(UART_INSTANCE);
        if (status != SL_STATUS_OK) {
        DEBUGOUT("sl_si91x_uart_rs485_set_configuration: Error Code : %lu \n", status);
        break;
        }
        DEBUGOUT("RS485 configuration is successful \n");
  • Addressing:

    • In hardware-controlled half-duplex, use dedicated APIs for send and receive operations.

    • In software-controlled mode, use standard APIs.

  • DMA support: Enable DMA in UC for high-throughput transfers.

  • Best practices:

    • Use uint16_t buffers for 9-bit data.

    • Start slave devices before the master.

    • Adjust UC settings for transmit and receive as required.

    • See the UART RS-485 example for details.