jeremyjh / ESP32_TFT_library

Full featured TFT library for ESP32 with demo application
47 stars 23 forks source link

ESP v3.3 Spiffs fwrite error #22

Closed elieDaan closed 3 years ago

elieDaan commented 4 years ago

Environment

Problem Description

Hello, I'm using ESP32 on Amazon FreeRtos with the loboris library library to use a tft lcd screen. In this library, there is a specific spiffs component so in my project I'm using this spiffs functions. I must use this because with the spiffs esp idf component, it's impossible to display images on tft screen.

The problem is that when my application is running, randomly a write on a file contained on the spiffs is not working and then every write/read is failed until I reset the board.

On this example, I'm writing a structure into a file as binary. It's the same for other functions...

Thank you very much for your help.

Expected Behavior

fwrite/fread/fclose successed

Actual Behavior

Randomly Failed with error -10012

Steps to reproduce

  1. Flash your code
  2. Flash your images with make flashfs
  3. Write a file and reboot until you've got the error

Code to reproduce this issue

/* Function to write Parameters_bob into a file to save it    */
int writeParametersFile(char *fname, char *mode, Parameters_bob *parameters)
{   
    FILE *fd =NULL;
    #if PRINT_DEBUG
    printf("=======================\n");
    printf("==== Write the parameters settings to file ====\n");
    printf("=======================\n");
    printf("  file: \"%s\"\n", fname);
    #endif
    if (fileExists(fname)==0){
        fd = fopen(fname, "wb+");

    }
    else {
        fd = fopen(fname, "wb+");
    }
    if (fd == NULL) {
        ESP_LOGE("[write]", "fopen failed");
        ESP_LOGE("[write]","errno : %d ",errno );
        return -1;
    }
    int size = sizeof(Parameters_bob);

    int res = fwrite(parameters, size, 1, fd);
    if (res != 1) {
        ESP_LOGE("[write]", "fwrite failed: %d  ", res);
        ESP_LOGE("[write]","errno : %d ",errno );
        res = fclose(fd);
        if (res) {
            ESP_LOGE("[write]", "fclose failed: %d", res);
            ESP_LOGE("[write]","errno : %d ",errno );
            return -2;
        }
        return -3;
    }
    res = fclose(fd);
    if (res) {
        ESP_LOGE("[write]", "fclose failed: %d", res);
        ESP_LOGE("[write]","errno : %d ",errno );
        return -4;
    }
    return 0;
}

======================= ==== Write the parameters settings to file ====

file: "/spiffs/config_data.txt" E (60734) [write]: fclose failed: -1 E (60734) [write]: errno : -10012



## Other items if possible
[sdkconfig](https://gist.github.com/elieDaan/f5e1a5d1c01836e14d7dc928e77e57fd)
jeremyjh commented 3 years ago

I'm no longer maintaining this fork, sorry. I've updated the README to let people know.