Files
desklock/firmware/components/esp_hosted/slave/main/slave_wifi_config.h
T
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

121 lines
3.6 KiB
C

/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __SLAVE_WIFI_CONFIG_H__
#define __SLAVE_WIFI_CONFIG_H__
#include "esp_idf_version.h"
// HE support changed after ESP-IDF v5.3
#if CONFIG_SOC_WIFI_HE_SUPPORT && (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 3, 0))
#define H_WIFI_HE_GREATER_THAN_ESP_IDF_5_3 1
#else
#define H_WIFI_HE_GREATER_THAN_ESP_IDF_5_3 0
#endif
/* ESP-IDF 5.5.0: renamed reserved fields to reserved1/reserved2 */
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
#define H_WIFI_NEW_RESERVED_FIELD_NAMES 1
#define H_PRESENT_IN_ESP_IDF_5_5_0 1
#define H_IF_AVAILABLE_SPI_SLAVE_ENABLE_DISABLE 1
#else
#define H_WIFI_NEW_RESERVED_FIELD_NAMES 0
#define H_PRESENT_IN_ESP_IDF_5_5_0 0
#define H_IF_AVAILABLE_SPI_SLAVE_ENABLE_DISABLE 0
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
#define H_PRESENT_IN_ESP_IDF_5_4_0 1
#else
#define H_PRESENT_IN_ESP_IDF_5_4_0 0
#endif
/*
* wifi_twt_config_t::twt_enable_keep_alive only found in
* IDF v5.3.2 and above
*/
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 3, 1)
#define H_GOT_TWT_ENABLE_KEEP_ALIVE 1
#else
#define H_GOT_TWT_ENABLE_KEEP_ALIVE 0
#endif
/* wifi_ap_config_t::transition_disable only found in
* IDF v5.3.3 and above, or
* IDF v5.4.1 and above
*/
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 3) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0)) || \
(ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 1))
#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 1
#else
#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 0
#endif
/* WIFI_ENABLE_CACHE_TX_BUFFER only found in
* IDF 5.3.3 and above
* reused config for WIFI_ENABLE_SPIRAM
*/
#ifndef WIFI_ENABLE_CACHE_TX_BUFFER
#define WIFI_ENABLE_CACHE_TX_BUFFER WIFI_ENABLE_SPIRAM
#endif
#ifdef CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT
#define H_WIFI_ENTERPRISE_SUPPORT 1
#else
#define H_WIFI_ENTERPRISE_SUPPORT 0
#endif
/** esp_eap_client_set_eap_methods() is only found in these versions of ESP-IDF:
* release/v5.3, v5.3.4, not in earlier versions.
* release/v5.4, not in v5.4.2 or earlier.
* release/v5.5, v5.5.1, not in v5.5.
*/
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 4) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0)) || \
(ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 3) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 5, 0)) || \
(ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 1)))
#define H_GOT_SET_EAP_METHODS_API 1
#else
#define H_GOT_SET_EAP_METHODS_API 0
#endif
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 4) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0)) || \
(ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 3))
#define H_GOT_EAP_SET_DOMAIN_NAME 1
#else
#define H_GOT_EAP_SET_DOMAIN_NAME 0
#endif
/**
* Wi-Fi Easy Connect (DPP) events is returned to user via
* Supplicant Callback or Wi-Fi DPP events,
* depending on IDF version
*
* IDF v6.0 and above only support Wi-Fi DPP events
* IDF v5.5 support Wi-Fi and Supplicant DPP events
* earlier versions support only Supplicant DPP events
*/
// Supplicant Callback DPP Events: removed from IDF v6.0
#if CONFIG_ESP_WIFI_DPP_SUPPORT && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0))
#define H_SUPP_DPP_SUPPORT 1
#else
#define H_SUPP_DPP_SUPPORT 0
#endif
// Wi-Fi DPP Events: only in IDF v5.5 and above
#if CONFIG_ESP_WIFI_DPP_SUPPORT && (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0))
#define H_WIFI_DPP_SUPPORT 1
#else
#define H_WIFI_DPP_SUPPORT 0
#endif
// for generic DPP support
#if H_SUPP_DPP_SUPPORT || H_WIFI_DPP_SUPPORT
#define H_DPP_SUPPORT 1
#else
#define H_DPP_SUPPORT 0
#endif
#endif