Files
jpmschweitzerandClaude Fable 5 cb5826e02b
Test, Build and Push / test-gateway (push) Successful in 12s
Test, Build and Push / release (push) Skipped
Test, Build and Push / build-gateway (push) Skipped
Fork fix: the SDIO wedge is FIXED (esp-hosted-mcu #167)
Root cause (verified against our exact IDF tree, not the community guess):
the "258" in "sdio_write_task: Failed to send data: 258" is NOT a timeout
(that is 263). 258 = 0x102 = ESP_ERR_INVALID_ARG. On the ESP32-P4, block-
mode CMD53 writes require the SOURCE buffer to be 64-byte (cache-line)
aligned; the IDF sdmmc driver rejects a misaligned source with INVALID_ARG
BEFORE any bus activity. esp_hosts write loop then declares "Unrecoverable
host sdio state" and reboots the whole P4. The audio TX payload is not
64-aligned, so streaming mic audio wedged on the very FIRST frame (which is
exactly what we saw: listening -> instant Failed to send -> reboot).

This also explains why buffer/queue/clock/retry tuning all did nothing: the
write never reached the bus. And why our symptom was instant, not after
~100 writes (the community block-mode-desync theory) — it is the first
misaligned buffer, every time.

Fix: vendored esp_hosted 2.12.11 as an editable local component (overrides
the registry copy) and bounce a misaligned TX payload through one aligned
DMA scratch buffer in hosted_sdio_write_block (port_esp_hosted_host_sdio.c).
TX is serialized by the bus lock so a single static bounce buffer is safe;
freed in hosted_sdio_deinit. Host-only change — no C6 reflash.

VERIFIED ON HARDWARE (autonomous self-test): 40s of continuous mic-audio
upstream streaming — the traffic that previously wedged on the first frame
— ran clean, zero timeouts, zero reboots. A guarded SDIO_TX_SELFTEST harness
is kept (compiled out) for future SDIO stress testing.

Credit: root cause + patch designed via multi-agent investigation; the
precise 258=INVALID_ARG decode (correcting the upstream community timeout
assumption) came from checking our actual esp_err.h.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 09:50:27 +02:00
..

Supported Hosts ESP32-P4
Supported Targets Co-processors with Zigbee RCP Support

Thermostat Example

This example demonstrates how to configure a Home Automation thermostat on a Zigbee Coordinator. Is has been modified from the ESP Zigbee SDK Thermostat example.

Hardware Required

  • An ESP32-P4 connected to a coprocessor with 802.15.4 support (e.g., ESP32-H2 or ESP32-C6) running this example. The ESP-Hosted Transport and UART should be connected between the two SOCs. See the OpenThread and Zigbee Support documentation for more information.
  • A second board running as a Zigbee end-device (see the ESP Zigbee SDK temperature_sensor example)

Configure the project

Before project configuration and build, make sure to set the correct chip target using idf.py set-target TARGET command.

Erase the NVRAM

Before flash it to the board, it is recommended to erase NVRAM if user doesn't want to keep the previous examples or other projects stored info using idf.py -p PORT erase-flash

Build and Flash

Build the project, flash it to the board, and start the monitor tool to view the serial output by running idf.py -p PORT flash monitor.

(To exit the serial monitor, type Ctrl-].)

Application Functions

  • When the program starts, the board, acting as a Zigbee Coordinator with the Home Automation Thermostat function, will form an open network within 180 seconds.
I (419) main_task: Calling app_main()
[…]
I (1611) ESP_RADIO_SPINEL: spinel UART interface initialization completed
I (1611) ESP_RADIO_SPINEL: Spinel UART interface has been successfully enabled
I (1611) ESP_ZIGBEE_RADIO_SPINEL_UART: Spinel UART interface enable successfully
I(1621) OPENTHREAD:[I] P-SpinelDrive-: co-processor reset: RESET_POWER_ON
E(1631) OPENTHREAD:[C] P-SpinelDrive-: Software reset co-processor successfully
I (1691) THERMOSTAT: Initialize Zigbee stack
E (1691) gpio: gpio_install_isr_service(537): GPIO isr service already installed
I (1691) THERMOSTAT: Deferred driver initialization successful
I (1691) THERMOSTAT: Device started up in non factory-reset mode
I (1701) THERMOSTAT: Device reboot
I (2831) THERMOSTAT: Network(0x03e2) is open for 180 seconds
  • If a Zigbee device with the Home Automation Temperature Sensor function joins the network, the board read its manufacturer code and model then add it to the binding table.
I (11889) THERMOSTAT: Attempt to find HA temperature sensor device on address(0xd9bc)
I (12279) THERMOSTAT: Attempt to read manuf_code and model_id from device (0xd9bc, 0x0a)
I (12369) THERMOSTAT: ZCL Read Attribute Response message for endpoint(1) cluster(0x0000) client with status(0x00)
I (12369) THERMOSTAT: Model identifier: esp32h2
I (12369) THERMOSTAT: Manufacturer name: ESPRESSIF
I (12379) THERMOSTAT: Attempt to bind temperature sensor device (0xd9bc, 0x0a) to local
I (12389) THERMOSTAT: Attempt to subscribe temperature sensor device (0xd9bc, 0x0a) from local
I (12429) THERMOSTAT: Bound HA temperature sensor device (0x0000, 0x0a) to local successfully
  • By clicking the BOOT button on this board, it will read the temperature value, temperature measurement range, and temperature tolerance from the remote board. Additionally, it will configure the remote temperature sensor to report the measured temperature value every 10 seconds or whenever there is a 2-degree change.
I (25321) THERMOSTAT: Zigbee APP Signal: ZDO Device Update(type: 0x07)
I (25351) THERMOSTAT: New device commissioned or rejoined (short: 0x96cf)
I (25351) THERMOSTAT: Attempt to find HA temperature sensor device on address(0x96cf)
I (25411) THERMOSTAT: Attempt to read manuf_code and model_id from device (0x96cf, 0x0a)
I (25481) THERMOSTAT: ZCL Read Attribute Response message for endpoint(1) cluster(0x0000) client with status(0x00)
I (25481) THERMOSTAT: Model identifier: esp32h2
I (25491) THERMOSTAT: Manufacturer name: ESPRESSIF
I (25491) THERMOSTAT: Attempt to bind temperature sensor device (0x96cf, 0x0a) to local
I (25501) THERMOSTAT: Attempt to subscribe temperature sensor device (0x96cf, 0x0a) from local
I (25511) THERMOSTAT: Bound HA temperature sensor device (0x0000, 0x0a) to local successfully
I (25521) THERMOSTAT: Attempt to configure reporting for HA temperature sensor
I (25591) THERMOSTAT: Subscribed HA temperature sensor device (0x96cf, 0x0a) from local successfully
I (25641) THERMOSTAT: ZCL Report Config Response message for endpoint(1) cluster(0x0402) client with status(0x00)
I (25671) THERMOSTAT: ZCL Report Attribute message for endpoint(1) cluster(0x0402) client with status(0x00)
I (25671) THERMOSTAT: Temperature sensor measured value: -327.68 degrees Celsius
I (26741) THERMOSTAT: ZCL Report Attribute message for endpoint(1) cluster(0x0402) client with status(0x00)
I (26741) THERMOSTAT: Temperature sensor measured value: 29.60 degrees Celsius
I (36841) THERMOSTAT: ZCL Report Attribute message for endpoint(1) cluster(0x0402) client with status(0x00)
I (36841) THERMOSTAT: Temperature sensor measured value: 29.60 degrees Celsius
I (46911) THERMOSTAT: ZCL Report Attribute message for endpoint(1) cluster(0x0402) client with status(0x00)
I (46911) THERMOSTAT: Temperature sensor measured value: 29.60 degrees Celsius
I (56981) THERMOSTAT: ZCL Report Attribute message for endpoint(1) cluster(0x0402) client with status(0x00)
I (56981) THERMOSTAT: Temperature sensor measured value: 29.60 degrees Celsius
[…]
W (206631) THERMOSTAT: Read Temperature Measurement attribute ID: 0x0003 with status: 0x86
I (206631) THERMOSTAT: Max measured value: 80.00 degrees Celsius
I (206641) THERMOSTAT: Min measured value: -10.00 degrees Celsius
I (206641) THERMOSTAT: Measured value: 29.60 degrees Celsius
[…]