espressif/esp_flash_dispatcher

1.0.1

Latest
uploaded 1 day ago
This component allows flash operations to be performed by tasks with stacks in PSRAM.

readme

## Overview

When a task stack resides in PSRAM, invoking `esp_flash_*` directly in that task can cause crashes during moments when the Flash driver temporarily disables the CPU cache (resulting in the PSRAM stack being inaccessible). Typical failures include Cache errors and Guru Meditation.

The `esp_flash_dispatcher` component intercepts common Flash APIs and executes the real Flash operations in a dedicated background task whose stack lives in internal RAM. This guarantees that even while cache is disabled, Flash operations run on an always-accessible stack. Therefore, application tasks can keep their stacks in PSRAM without worrying about Flash operations breaking them.

## Usage

1. Add esp_flash_dispatcher component to your project: `idf.py add-dependency espressif/esp_flash_dispatcher`
2. Initialize esp_flash_dispatcher in app_main:

    ```c
    #include "esp_flash_dispatcher.h"

    const esp_flash_dispatcher_config_t cfg = {
        .task_stack_size = 2048,
        .task_priority = 10,
        .task_core_id = tskNO_AFFINITY,
        .queue_size = 1, // deprecated, see note below
    };
    ESP_ERROR_CHECK(esp_flash_dispatcher_init(&cfg));
    ```

    > Note: `queue_size` is kept only for backward compatibility. The dispatcher
    > serializes all requests with an internal mutex and uses a single shared
    > slot between the caller and the worker task, so this field has no effect
    > on behavior.

3. Now you can call any API which writes or reads SPI Flash from a task with the stack in PSRAM, no other changes are required.

The list of Flash APIs intercepted by the dispatcher is:

- `esp_flash_read`, `esp_flash_write`, `esp_flash_write_encrypted`
- `esp_flash_erase_region`, `esp_flash_erase_chip`
- `spi_flash_mmap`, `spi_flash_munmap`

Links

Supports all targets

License: Apache-2.0

To add this component to your project, run:

idf.py add-dependency "espressif/esp_flash_dispatcher^1.0.1"

download archive

Stats

  • Archive size
    Archive size ~ 14.47 KB
  • Downloaded in total
    Downloaded in total 212 times
  • Weekly Downloads Weekly Downloads (All Versions)
  • Downloaded this version
    This version: 0 times

Badge

espressif/esp_flash_dispatcher version: 1.0.1
|