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>
99 lines
2.7 KiB
C
99 lines
2.7 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef __SLAVE_LIGHT_SLEEP_H__
|
|
#define __SLAVE_LIGHT_SLEEP_H__
|
|
|
|
#include "esp_err.h"
|
|
|
|
/**
|
|
* @brief Initialize light sleep power management
|
|
*
|
|
* Configures PM framework and creates PM lock for light sleep control.
|
|
* Must be called once during initialization before using start/stop APIs.
|
|
*
|
|
* This function:
|
|
* - Creates PM lock for CPU frequency control
|
|
* - Configures min/max CPU frequencies
|
|
* - Enables automatic light sleep when system is idle
|
|
*
|
|
* Can be used independently of host power save feature.
|
|
*
|
|
* @return
|
|
* - ESP_OK: Success
|
|
* - ESP_ERR_INVALID_STATE: Already initialized
|
|
* - ESP_ERR_NO_MEM: Failed to create PM lock
|
|
* - ESP_ERR_NOT_SUPPORTED: PM not enabled in menuconfig
|
|
*/
|
|
esp_err_t slave_light_sleep_init(void);
|
|
|
|
/**
|
|
* @brief Enter light sleep mode
|
|
*
|
|
* Releases PM lock to allow CPU frequency scaling and automatic light sleep.
|
|
* When system becomes idle (no tasks running), it will automatically enter
|
|
* light sleep based on FreeRTOS tickless idle mechanism.
|
|
*
|
|
* Wake sources:
|
|
* - GPIO interrupts (if configured)
|
|
* - WiFi events
|
|
* - Timer interrupts
|
|
* - UART RX (if peripherals not powered down)
|
|
*
|
|
* Can be called:
|
|
* - Manually by application based on custom conditions
|
|
* - Automatically via host power save callbacks
|
|
* - Multiple times (idempotent - safe to call if already started)
|
|
*
|
|
* @return
|
|
* - ESP_OK: Light sleep enabled
|
|
* - ESP_ERR_INVALID_STATE: Not initialized
|
|
*/
|
|
esp_err_t slave_light_sleep_start(void);
|
|
|
|
/**
|
|
* @brief Exit light sleep mode
|
|
*
|
|
* Acquires PM lock to prevent light sleep and keep CPU at maximum frequency.
|
|
* System will no longer automatically enter light sleep when idle.
|
|
*
|
|
* Use when:
|
|
* - Need guaranteed full CPU performance
|
|
* - Handling time-critical operations
|
|
* - Host has woken up from deep sleep
|
|
*
|
|
* Can be called multiple times safely (idempotent).
|
|
*
|
|
* @return
|
|
* - ESP_OK: Light sleep disabled
|
|
* - ESP_ERR_INVALID_STATE: Not initialized
|
|
*/
|
|
esp_err_t slave_light_sleep_stop(void);
|
|
|
|
/**
|
|
* @brief Check if light sleep is configured and available
|
|
*
|
|
* @return
|
|
* - ESP_OK: Light sleep initialized and ready
|
|
* - ESP_FAIL: Not initialized or not supported
|
|
*/
|
|
esp_err_t slave_light_sleep_is_configured(void);
|
|
|
|
/**
|
|
* @brief Cleanup and deinitialize light sleep
|
|
*
|
|
* Stops light sleep if active, deletes PM lock, and cleans up resources.
|
|
* Should be called during application shutdown.
|
|
*
|
|
* @return
|
|
* - ESP_OK: Cleanup successful
|
|
* - ESP_ERR_INVALID_STATE: Not initialized
|
|
*/
|
|
esp_err_t slave_light_sleep_deinit(void);
|
|
|
|
#endif /* __SLAVE_LIGHT_SLEEP_H__ */
|
|
|