Drives CP-side GPIOs from the host as if the coprocessor were a remote
GPIO expander. The host calls esp_hosted_cp_gpio_* (configure / set
level / get level / reset) over RPC; the CP applies each call to its
own gpio_* peripheral. Useful when the host MCU runs out of pins and
the coprocessor has spare ones.
| Coprocessor | ESP32 | ESP32-C Series | ESP32-S Series |
|---|---|---|---|
| Support | Yes | Yes | Yes |
| Host Device | ESP32-P4 | ESP32-H2 | Other MCUs | Linux |
|---|---|---|---|---|
| Support | Yes | Yes | Yes | Yes |
| Connection bus | SDIO | SPI Full-Duplex | SPI Half-Duplex | UART |
|---|---|---|---|---|
| Linux host | Yes | Yes | No | No |
| MCU host | Yes | Yes | Yes | Yes |
gpio_expander/
├── cp/ ESP coprocessor firmware
├── mcu_host/ ESP-IDF MCU host app
└── linux_802_3_host/ Linux host
├── c_app/ native C app
├── kmod/ kernel module
└── py_app/ Python (ctypes) app
The host drives and reads the co-processor's GPIOs remotely over the control path (RPC).
sequenceDiagram
participant App as Host app
participant CP as Co-processor GPIO
App->>CP: esp_hosted_cp_gpio_config(pin) (RPC)
App->>CP: esp_hosted_cp_gpio_set_level(pin, 1) (RPC)
CP-->>App: ok
App->>CP: esp_hosted_cp_gpio_get_level(pin) (RPC)
CP-->>App: level
Important
New here? Get a base example working first. Follow Getting Started: Linux or Getting Started: MCU to wire the boards, install tools, choose a transport, and confirm the host↔co-processor handshake. The steps below only add what is specific to this example.
Set up the tools once (from the repo root):
cd /path/to/esp_hosted
./install.sh # install.fish for the fish shell
. ./export.sh # . ./export.fish for the fish shellGPIO-expander support is enabled by the co-processor's sdkconfig.defaults
(ESP_HOSTED_CP_FEAT_GPIO_EXP) — no extra option to enable. Select the
transport via eh.py menuconfig:
cd examples/gpio_expander/cp
eh.py set-target esp32c6
eh.py menuconfigComponent config
└── ESP-Hosted
└── Configure coprocessor
└── CP transport
├── Communication bus (co-processor <== bus ==> host)
│ ├── ( ) SPI Full Duplex
│ ├── (X) SDIO <── default
│ ├── ( ) SPI Half Duplex ← MCU host only
│ └── ( ) UART ← MCU host only
└── SDIO Configuration ← clock, GPIOs, checksum (defaults OK)
The CP-side pin under test (default GPIO 2) is set in code via
SLAVE_GPIO_PIN. Each bus has its own settings submenu (pins, clock,
checksum) — defaults are fine for bring-up.
The CP dependency config is pre-set in sdkconfig.defaults (do not remove):
CONFIG_ESP_HOSTED_CP_FEAT_GPIO_EXP=y # CP GPIO-expander feature
CONFIG_BT_ENABLED=n # BT off (unused by this example)
Then flash and monitor:
eh.py -p <cp_usb_serial_port> flash monitorNote
Base wiring, OS setup, and transport bring-up live in Getting Started: Linux. This section assumes that already works.
Set up the tools once (from the repo root):
cd /path/to/esp_hosted
./install.sh # install.fish for the fish shell
. ./export.sh # . ./export.fish for the fish shellKernel module (creates ethsta0 / ethap0 and /dev/esps0):
cd examples/gpio_expander/linux_802_3_host/kmod
./build.sh --bus sdio --reload --reset-gpio 518 --clock-mhz 50
# SPI instead: ./build.sh --bus spi --reload --reset-gpio 518 --clock-mhz 10 --spi-mode 3--reload builds, unloads, and reloads with the given module params. On SPI, start at --clock-mhz 10; once stable, raise it in steps to the co-processor's max SPI clock (see Performance).
Native C app:
cd examples/gpio_expander/linux_802_3_host/c_app
eh.py set-target linux
eh.py menuconfigExample Configuration
└── [ ] Use legacy esp_hosted_* compat-surface main <── default off
The Host dependency config is pre-set in sdkconfig.defaults (do not remove):
CONFIG_ESP_HOSTED_HOST_FEAT_GPIO_EXP=y # host GPIO-expander feature
CONFIG_ESP_HOSTED_HOST_FEAT_RPC=y # RPC control path
CONFIG_ESP_HOSTED_HOST_FEAT_RPC_EXT_V2=y # required RPC ext-v2
Then build and run:
eh.py build
eh.py runPython app — same RPC surface, driven from main/main.py:
cd examples/gpio_expander/linux_802_3_host/py_app
eh.py set-target linux
eh.py build
eh.py run-
Each demo step toggles the same CP pin through every mode supported by the
gpio_expfeature: input, input-pullup, output, open-drain. -
The Linux variants exercise exactly the same RPC surface from user-space C, kernel-space, and Python.
Set up the tools once (from the repo root):
cd /path/to/esp_hosted
./install.sh # install.fish for the fish shell
. ./export.sh # . ./export.fish for the fish shellGPIO-expander support is enabled by the co-processor's sdkconfig.defaults
(ESP_HOSTED_CP_FEAT_GPIO_EXP) — no extra option to enable. Select the
transport via eh.py menuconfig:
cd examples/gpio_expander/cp
eh.py set-target esp32c6
eh.py menuconfigComponent config
└── ESP-Hosted
└── Configure coprocessor
└── CP transport
├── Communication bus (co-processor <== bus ==> host)
│ ├── ( ) SPI Full Duplex
│ ├── (X) SDIO <── default
│ ├── ( ) SPI Half Duplex ← MCU host only
│ └── ( ) UART ← MCU host only
└── SDIO Configuration ← clock, GPIOs, checksum (defaults OK)
The CP-side pin under test (default GPIO 2) is set in code via
SLAVE_GPIO_PIN. Each bus has its own settings submenu (pins, clock,
checksum) — defaults are fine for bring-up.
The CP dependency config is pre-set in sdkconfig.defaults (do not remove):
CONFIG_ESP_HOSTED_CP_FEAT_GPIO_EXP=y # CP GPIO-expander feature
CONFIG_BT_ENABLED=n # BT off (unused by this example)
Then flash and monitor:
eh.py -p <cp_usb_serial_port> flash monitorSet up the tools once (from the repo root):
cd /path/to/esp_hosted
./install.sh # install.fish for the fish shell
. ./export.sh # . ./export.fish for the fish shellSelect the transport (must match the co-processor):
cd examples/gpio_expander/mcu_host
eh.py set-target esp32p4
eh.py menuconfigComponent config
└── ESP-Hosted
└── Configure host
└── Host transport
├── Communication bus (co-processor <== bus ==> host)
│ ├── ( ) SPI Full Duplex
│ ├── (X) SDIO <── default (match the co-processor)
│ ├── ( ) SPI Half Duplex
│ └── ( ) UART
└── SDIO Configuration ← slot, bus width, GPIOs (defaults OK)
The host GPIO-expander feature is enabled by sdkconfig.defaults
(ESP_HOSTED_HOST_FEAT_GPIO_EXP); this host has no example-specific menu.
The CP-side pin under test (default GPIO 2) is set in code via
SLAVE_GPIO_PIN.
The Host dependency config is pre-set in sdkconfig.defaults (do not remove):
CONFIG_ESP_HOSTED_HOST_FEAT_GPIO_EXP=y # host GPIO-expander feature
CONFIG_ESP_HOSTED_HOST_FEAT_RPC=y # RPC control path
CONFIG_ESP_HOSTED_HOST_FEAT_RPC_EXT_V2=y # required RPC ext-v2
CONFIG_ESP_HOSTED_HOST_FEAT_SYSTEM=y # system RPC calls
Then flash and monitor:
eh.py -p <host_usb_serial_port> flash monitor-
Each demo step toggles the same CP pin through every mode supported by the
gpio_expfeature: input, input-pullup, output, open-drain. -
The Linux variants exercise exactly the same RPC surface from user-space C, kernel-space, and Python.