Erase size not set for external chip in esp_partition_register_external

oedzee
Posts: 5
Joined: Mon Oct 30, 2023 10:19 am

Erase size not set for external chip in esp_partition_register_external

Postby oedzee » Mon Jan 29, 2024 10:02 am

We are using a external chip spi flash chip on our board.

We can successfully init this chip with the following code:

Code: Select all

 // Init External Flash
    ESP_LOGI(Tag, "Init External Flash");
    const esp_flash_spi_device_config_t config = {
        .host_id = SPI2_HOST,
        .cs_io_num = GPIO_NUM_10,
        .io_mode = SPI_FLASH_DIO,
        .speed = ESP_FLASH_5MHZ, // Deprecrated
        .input_delay_ns = 0,
        .cs_id = 0,
        .freq_mhz = ESP_FLASH_5MHZ               ///< The frequency of flash chip(MHZ)
    };

    esp_flash_t* chip = nullptr;
    const esp_partition_t* partition = nullptr;
    spi_bus_add_flash_device(&chip, &config);
    esp_flash_init(chip);
    
    err = esp_partition_register_external(chip, 0, chip->size, "ext_lfs", ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_UNDEFINED, &partition);
We want to run the LFS filesytem on this chip. However, to use LFS, we need to know the erase_size. This property is never set in the esp_partition_register_external call and remains 0.

Is this intended behaviour?
I've got a workarround and that is by forcefully setting the variable after the register_external command.

Code: Select all

((esp_partition_t*)(partition))->erase_size = 4096;
This means i have to cast it to not be const, and then i can change it, which is not ideal.
is there a better way to solve this?

RathiSonika
Posts: 11
Joined: Thu Jun 22, 2023 2:58 pm

Re: Erase size not set for external chip in esp_partition_register_external

Postby RathiSonika » Tue Jan 30, 2024 12:29 pm

Hi, I'm not sure why you need to know the erase_size for using LFS. Check out the IDF examples at https://github.com/espressif/esp-idf/tr ... lash_fatfs and https://github.com/espressif/esp-idf/tr ... e/littlefs – it should help.

Who is online

Users browsing this forum: No registered users and 222 guests