General Serial Peripheral Interface (GSPI) Debugging and Error Handling#

This section provides guidance for debugging Generic Serial Peripheral Interface (GSPI) communication and managing errors on the SiWx917 device.
It covers practical debugging procedures, common error codes, and interrupt-based event handling for GSPI-based communication.

Common Debugging Tips#

Debugging GSPI communication involves validating both hardware connections and software configuration.
Use the following best practices to identify and resolve communication issues effectively.

Reference: For detailed troubleshooting steps, see the WiSeConnect Debugging Guide.

Visual Inspection and Connection Verification#

Before running GSPI tests, confirm that all physical connections are properly established and functioning.

  • Ensure CLK, CS, MOSI, and MISO lines are connected between the Primary and Secondary devices.

  • Verify that both devices share a common ground connection.

  • Inspect cables, connectors, and PCBs for damage or loose contacts.

  • Use proper PCB design practices—keep traces short, minimize crosstalk, and maintain consistent impedance for reliable high-speed SPI communication.

Interfacing with SiWx917 Development Kits (Primary Setup)#

To test GSPI communication on a SiWx917 development kit:

  1. Connect the SiWx917 kit as the GSPI Primary to a compatible Secondary device.

  2. Wire the CLK, CS, MOSI, and MISO signals between the two boards.

  3. Connect a common ground between both devices.

  4. Power both boards using stable, regulated supplies.

Use Simplicity Studio to flash and debug firmware on the SiWx917 board.
Run GSPI transactions and observe the behavior with a logic analyzer or oscilloscope while using Simplicity Studio’s built-in debug tools.

Note: For custom Secondary devices, ensure configuration matches the Primary GSPI setup:

  • SPI mode (clock polarity and phase – CPOL/CPHA)

  • Frame size and data width

  • Clock frequency and chip-select timing

Using a Logic Analyzer for Debugging#

A logic analyzer (LA) is a critical tool for verifying GSPI timing and data integrity.

  • Attach probes to CLK, CS, MOSI, and MISO lines.

  • Confirm voltage levels match the board’s logic (for example, 3.3 V).

  • Capture communication during read/write operations.

  • Configure the LA to decode the SPI protocol for detailed timing analysis.

Tip: Verify setup and hold times, duty cycles, and clock polarity alignment between the SiWx917 Primary and the Secondary device.

Software Debugging and Monitoring#

Alongside hardware validation, use software-level debugging techniques to identify GSPI-related issues.

Enable Debug Logging

Use debug logs to track GSPI operations and print status or error messages:

if (status != SL_STATUS_OK) {
    DEBUGOUT("GSPI Error: 0x%02X", status);
}

Monitor Status Registers

Read GSPI status registers to track FIFO levels, detect busy states, and confirm successful transmission or reception.

Measure Performance

Profile transfer rates and latency to identify bottlenecks or inefficiencies in DMA- or polling-based transfers.
Analyzing these metrics helps improve throughput and optimize power efficiency.

Error Code Handling#

GSPI driver APIs return standardized status codes (sl_status_t) that indicate whether an operation was successful or failed.
Always check for SL_STATUS_OK after each API call to ensure the configuration or transfer completed successfully.

GSPI Error Codes#

The following table lists common GSPI status codes, their meanings, and recommended recovery actions.

Error Code

Description

Recommended Recovery Action

SL_STATUS_OK

Operation successful.

Continue normal operation.

SL_STATUS_INVALID_PARAMETER

Invalid configuration or argument.

Verify all parameter values (mode, frame size, clock, and buffers).

SL_STATUS_BUSY

GSPI or DMA is currently busy.

Wait for the ongoing transfer to finish or reset the peripheral.

SL_STATUS_TIMEOUT

Operation timed out.

Check connections, chip-select timing, and retry the transaction.

SL_STATUS_TRANSMIT

Transmission error detected.

Verify chip-select timing, SCLK configuration, and MOSI signal integrity.

SL_STATUS_RECEIVE

Reception error detected.

Check MISO signal integrity and ensure the Secondary device is ready.

SL_STATUS_NOT_INITIALIZED

GSPI or DMA not initialized.

Call sl_si91x_gspi_init() (and sl_si91x_dma_init() if using DMA) before performing transfers.

SL_STATUS_INVALID_MODE

Invalid or unsupported SPI mode.

Verify CPOL/CPHA configuration and data width.

SL_STATUS_DMA_NO_CHANNEL_AVAILABLE

No DMA channel available for transfer.

Reassign or release DMA channels; use IO mode if necessary.

SL_STATUS_DMA_CHANNEL_ALLOCATED

Requested DMA channel already in use.

Use automatic DMA allocation or select a free channel.

Tip: If persistent errors occur, reset and reinitialize the GSPI using sl_si91x_gspi_deinit() followed by sl_si91x_gspi_init() to restore a stable state.

Interrupt Error Handling#

The SiWx917 GSPI generates interrupts to signal events that require software handling.
Monitor and handle these interrupts to maintain synchronization between the Primary and Secondary devices.

Event Type

Description

Recommended Action

Transfer Complete

Indicates that a data transfer finished successfully.

Clear interrupt flags and prepare for the next transaction.

DMA Error Event

Signifies an issue during a DMA-assisted transfer.

Reinitialize DMA and retry the operation.

Note: Always clear interrupt status bits after handling an event to prevent repeated interrupt triggers.