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>
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef __TRANSPORT_LAYER_INTERFACE_H
|
||||
#define __TRANSPORT_LAYER_INTERFACE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_hosted_log.h"
|
||||
#include "esp_hosted_transport.h"
|
||||
|
||||
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
|
||||
|
||||
#if CONFIG_SOC_SDIO_SLAVE_SUPPORTED
|
||||
#include "driver/sdio_slave.h"
|
||||
#else
|
||||
#error "SDIO is not supported for this chipset"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_SPI_HD_HOST_INTERFACE
|
||||
#include "driver/spi_slave_hd.h"
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LENGTH_1_BYTE = 1,
|
||||
LENGTH_2_BYTE = 2,
|
||||
LENGTH_3_BYTE = 3,
|
||||
LENGTH_4_BYTE = 4,
|
||||
} byte_length;
|
||||
|
||||
typedef void *wlan_buf_handle_t;
|
||||
|
||||
typedef enum {
|
||||
SDIO = 0,
|
||||
SPI = 1,
|
||||
SPI_HD = 2,
|
||||
UART = 3,
|
||||
} transport_layer;
|
||||
|
||||
typedef enum {
|
||||
DEINIT,
|
||||
DEACTIVE,
|
||||
ACTIVE,
|
||||
} INTERFACE_STATE;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
#ifdef CONFIG_ESP_SDIO_HOST_INTERFACE
|
||||
sdio_slave_buf_handle_t sdio_buf_handle;
|
||||
#endif
|
||||
#ifdef CONFIG_ESP_SPI_HD_HOST_INTERFACE
|
||||
spi_slave_hd_data_t * spi_hd_trans_handle;
|
||||
#endif
|
||||
wlan_buf_handle_t wlan_buf_handle;
|
||||
void *priv_buffer_handle;
|
||||
};
|
||||
uint8_t if_type;
|
||||
uint8_t if_num;
|
||||
uint8_t *payload;
|
||||
uint8_t flag;
|
||||
uint16_t payload_len;
|
||||
uint16_t seq_num;
|
||||
#if CONFIG_ESP_SPI_HD_HOST_INTERFACE || CONFIG_ESP_UART_HOST_INTERFACE || CONFIG_ESP_SPI_HOST_INTERFACE
|
||||
uint8_t wifi_flow_ctrl_en;
|
||||
#endif
|
||||
|
||||
void (*free_buf_handle)(void *buf_handle);
|
||||
} interface_buffer_handle_t;
|
||||
|
||||
typedef struct {
|
||||
/*
|
||||
union {
|
||||
} phy_context;
|
||||
*/
|
||||
INTERFACE_STATE state;
|
||||
}interface_handle_t;
|
||||
|
||||
#if CONFIG_ESP_SPI_HOST_INTERFACE
|
||||
#define MAX_TRANSPORT_BUF_SIZE ESP_TRANSPORT_SPI_MAX_BUF_SIZE
|
||||
#elif CONFIG_ESP_SDIO_HOST_INTERFACE
|
||||
#define MAX_TRANSPORT_BUF_SIZE ESP_TRANSPORT_SDIO_MAX_BUF_SIZE
|
||||
#elif CONFIG_ESP_SPI_HD_HOST_INTERFACE
|
||||
#define MAX_TRANSPORT_BUF_SIZE ESP_TRANSPORT_SPI_HD_MAX_BUF_SIZE
|
||||
#elif CONFIG_ESP_UART_HOST_INTERFACE
|
||||
#define MAX_TRANSPORT_BUF_SIZE ESP_TRANSPORT_UART_MAX_BUF_SIZE
|
||||
#endif
|
||||
|
||||
#define BSSID_BYTES_SIZE 6
|
||||
|
||||
typedef struct {
|
||||
interface_handle_t * (*init)(void);
|
||||
int32_t (*write)(interface_handle_t *handle, interface_buffer_handle_t *buf_handle);
|
||||
int (*read)(interface_handle_t *handle, interface_buffer_handle_t *buf_handle);
|
||||
esp_err_t (*reset)(interface_handle_t *handle);
|
||||
void (*deinit)(interface_handle_t *handle);
|
||||
} if_ops_t;
|
||||
|
||||
typedef struct {
|
||||
transport_layer type;
|
||||
void *priv;
|
||||
if_ops_t *if_ops;
|
||||
int (*event_handler)(uint8_t bitmap);
|
||||
} interface_context_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t throttle_high_threshold;
|
||||
uint8_t throttle_low_threshold;
|
||||
} slave_config_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t current_throttling;
|
||||
} slave_state_t;
|
||||
|
||||
interface_context_t * interface_insert_driver(int (*callback)(uint8_t val));
|
||||
int interface_remove_driver(void);
|
||||
void generate_startup_event(uint8_t cap, uint32_t ext_cap);
|
||||
int send_to_host_queue(interface_buffer_handle_t *buf_handle, uint8_t queue_type);
|
||||
void send_dhcp_dns_info_to_host(uint8_t network_up, uint8_t send_wifi_connected);
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
extern slave_config_t slv_cfg_g;
|
||||
extern slave_state_t slv_state_g;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user