Main Content

Configure GPIO Behavior

R2026b
Since R2026b

NI™ USRP™ radios provide GPIO connectors for interfacing with external hardware. Wireless Testbench™ lets you manage these GPIO signals either automatically, based on the radio state, or manually, under explicit user control.

Configure GPIO pins in one of two modes:

  • ATR — Synchronize external hardware, such as RF switches, LNAs, or PAs, with the radio transmit and receive state.

  • Manual control — Drive or read GPIO signals independently of the radio state.

For connector pinouts and signal-to-pin mapping for your radio, see GPIO Connectors and Pin Mapping.

GPIO Signals

In Wireless Testbench, a GPIO signal is a logical, software-addressable signal such as Data[0] or Data[1]. A GPIO signal does not correspond directly to a physical pin number on the connector. For the mapping between GPIO signals and physical connector pins, see GPIO Connectors and Pin Mapping.

GPIO Banks

GPIO banks are a logical grouping of GPIO signals that are physically routed to a connector on your radio. The GPIO banks available depend on the radio model.

  • GPIO banks associated with front-panel GPIO connectors are typically named FP0.

  • USRP X410 radios, which have two external GPIO connectors, have two GPIO banks named GPIO0 and GPIO1.

To query the GPIO banks available on your radio, use the getGPIOBanks function.

GPIO Sources

GPIO sources are internal radio components that can drive GPIO signals. To enable ATR control, you map a specific GPIO signal to a radio source so the signal state follows the radio state machine.

To manage the GPIO source mapping for a specific GPIO bank, use these functions:

The behavior of GPIO source and attribute settings can vary between radio models depending on the hardware implementation. For details on source-to-pin routing for your device, consult the manufacturer documentation.

GPIO Attributes

GPIO attributes define the behavior of GPIO signals after a source is assigned. Attributes control properties such as signal direction, output state, and ATR behavior.

To manage the behavior of signals in a specific GPIO bank, use these functions:

  • getGPIOAttribute — Query current attribute values.

  • setGPIOAttribute — Configure GPIO behavior, such as setting a signal as an output, driving it high or low, or configuring its ATR masks.

Configure GPIO Pins for ATR Operation

To configure a GPIO signal for ATR operation and set the output state for each radio condition, follow these steps:

  1. Choose the GPIO bank on the radio and assign a radio source to the GPIO signal that you want to control.

  2. Enable ATR operation on the selected GPIO signal by setting the control and direction attribute register values.

  3. Configure the GPIO output state for each radio state by setting the ATR attribute register values.

Create Radio Object and Preload Application

Create a radio object and preload the application onto the radio. This example uses a basebandTransceiver application object to validate ATR behavior.

Note

The following actions reset the GPIO configuration:

  • Loading an application onto the radio. This occurs when you specify the Preload name-value argument as true during object creation, or the first time you call the transmit or capture function on an object created without Preload=true.

  • Calling the setup function on a usrp System object™.

  • Changing properties that select radio antennas, such as Antennas, TransmitAntennas, ReceiveAntennas, DUTInputAntennas, or DUTOutputAntennas.

  • Changing the SampleRate property to a value derived from a different master clock rate. For more information on how the baseband sample rate is derived, see Baseband Sample Rate in NI USRP Radios.

To preserve the GPIO configuration, perform these actions before you configure GPIO pins.

radio = radioConfigurations("MyRadio");
bbtrx = basebandTransceiver(radio,Preload=true);

Select GPIO Bank and Source

Assign a radio source to the GPIO signal that you want to control. Update the source and signal indices to match your hardware configuration. In this example, "RF0" drives the second GPIO signal based on the state of the radio front end.

Note

GPIO signal indices such as Data[0] do not map directly to physical connector pin numbers. Before wiring external hardware, identify the correct connector pin for your radio. For details, see GPIO Connectors and Pin Mapping.

banks = getGPIOBanks(radio);
disp(banks)
FP0
gpioBank = banks(1);
sources = getAvailableGPIOSources(radio,gpioBank);
disp(sources)
    "PS"
    "RF0"
    "RF1"
radioSource = sources(2);
signalIndex = 2;

srcMap = getGPIOSource(radio,gpioBank);
srcMap(signalIndex) = radioSource;
setGPIOSource(radio,gpioBank,srcMap);

Enable ATR Operation

Enable ATR operation on the selected GPIO signal and set its direction to output. Each attribute is a bitmask. Use bitset to modify only the target signal without affecting other signals.

% Resolve attribute bank and signal index for USRP X410 radios
if strcmp(radio.Hardware,"USRP X410")
    attrBank = "GPIO";
    if strcmp(gpioBank,"GPIO1")
        attrSignalIndex = signalIndex + 12;
    else
        attrSignalIndex = signalIndex;
    end
else
    attrBank = gpioBank;
    attrSignalIndex = signalIndex;
end

ctrl = getGPIOAttribute(radio,attrBank,radioSource,"CTRL");
setGPIOAttribute(radio,attrBank,radioSource,"CTRL",bitset(ctrl,attrSignalIndex,1));

ddr = getGPIOAttribute(radio,attrBank,radioSource,"DDR");
setGPIOAttribute(radio,attrBank,radioSource,"DDR",bitset(ddr,attrSignalIndex,1));

Set ATR Masks

Define the GPIO output state for each radio state. In this example, the signal drives high during the transmit and full-duplex states, and low when idle or receiving.

% Drive signal low when idle
atr0x = getGPIOAttribute(radio,attrBank,radioSource,"ATR_0X");
setGPIOAttribute(radio,attrBank,radioSource,"ATR_0X",bitset(atr0x,attrSignalIndex,0));

% Drive signal low when receiving
atrRx = getGPIOAttribute(radio,attrBank,radioSource,"ATR_RX");
setGPIOAttribute(radio,attrBank,radioSource,"ATR_RX",bitset(atrRx,attrSignalIndex,0));

% Drive signal high when transmitting
atrTx = getGPIOAttribute(radio,attrBank,radioSource,"ATR_TX");
setGPIOAttribute(radio,attrBank,radioSource,"ATR_TX",bitset(atrTx,attrSignalIndex,1));

% Drive signal high in full-duplex state
atrXx = getGPIOAttribute(radio,attrBank,radioSource,"ATR_XX");
setGPIOAttribute(radio,attrBank,radioSource,"ATR_XX",bitset(atrXx,attrSignalIndex,1));

The GPIO signal now updates automatically as the radio transitions between states.

Validate ATR Behavior

Verify the ATR configuration by transmitting a dummy waveform and reading back the GPIO pin state. When the radio is transmitting, the configured GPIO signal drives high. When the transmission has ended, the configured GPIO signal drives low.

waveform = complex(zeros(1000,1,"int16"));
transmit(bbtrx,waveform,"continuous");

readback = getGPIOAttribute(radio,attrBank,radioSource,"READBACK");
pinState = bitget(readback,attrSignalIndex);
disp("GPIO pin state during TX: " + pinState)
GPIO pin state during TX: 1
stopTransmission(bbtrx);
readback = getGPIOAttribute(radio,attrBank,radioSource,"READBACK");
pinState = bitget(readback,attrSignalIndex);
disp("GPIO pin state when idle: " + pinState)
GPIO pin state when idle: 0

If the read-back values match the ATR masks you configured, the GPIO signal is operating correctly. You can also verify by measuring the voltage on the corresponding connector pin with a multimeter or logic analyzer. For the pin mapping on your radio, see GPIO Connectors and Pin Mapping.

Configure Manual Control

To control a GPIO signal independently of the radio transmit and receive state, follow these steps:

  1. Use getGPIOBanks to query the available GPIO banks on your radio.

  2. Use getAvailableGPIOSources to list the radio sources that can drive GPIO signals in the selected bank.

  3. Use setGPIOSource to assign a radio source to the GPIO signal that you want to control. A source is required even in manual mode because it identifies which FPGA radio block owns the GPIO registers.

  4. Use setGPIOAttribute to configure the signal for manual control by setting these attributes:

    • CTRL — Disable ATR control on the signal.

    • DDR — Set the signal direction to output or input.

    • OUT — For output signals, drive the signal high or low.

  5. Use getGPIOAttribute with the READBACK attribute to verify the pin state matches your expected configuration. For output signals, confirm the readback value reflects the OUT value you set.

For output signals, the GPIO signal holds the specified state regardless of radio activity. To change the signal state, call setGPIOAttribute again with the OUT attribute. For input signals, use getGPIOAttribute with the READBACK attribute to read the current pin state.

See Also

Functions

Topics