I’m developing an application that needs to read values from a DS3231 connected via I2C and store the current values in a CSV file via SPIFFS when a GPIO is triggered. This GPIO creates a new task with higher priority on FreeRTOS to save the values, but after I call fopen and fprintf to store the data, fprintf points to a NULL address and a Guru Meditation Error (LoadProhibited) is triggered. Thank you very much for any light that can be cast on this problem.
This is the code part that is triggering the error:
FILE *daily_horimeter_last_read = fopen(DAILY_HORIMETER_PATH, "w+");
if(daily_horimeter_last_read == NULL)
{
ESP_LOGW("SPIFFS", "There are not saved values, creating them...");
}
fprintf(daily_horimeter_last_read, "%d,%d,%dn", daily_horimeter.tm_hour, daily_horimeter.tm_min, daily_horimeter.tm_sec);
fclose(daily_horimeter_last_read);
This is the log generated in monitor:
D (395690) SPIFFS: SPIFFS_open '/daily_horimeter_last_read.csv' 1e
D (395740) SPIFFS: free_obj_id: BITM min:0001 max:0781
D (395780) SPIFFS: create: found free page @ 0003 bix:0000 entry:0002
D (395790) SPIFFS: CALLBACK NEW obj_id:8002 spix:0000 npix:0003 nsz:4596840552049192560
D (395790) SPIFFS: open: fd 3 is obj id 8002
D (395790) SPIFFS: SPIFFS_fstat 3
D (395790) SPIFFS: SPIFFS_write 3 -1099503864989
D (395800) SPIFFS: SPIFFS_close 3
D (395800) SPIFFS: append: -4294967296 bytes @ offs 17179869190 of size 4596840483299812120
D (395810) SPIFFS: append: 8002 load objixhdr page 0003:0000
D (395820) SPIFFS: append: 8002 store new data page, 0004:0000 offset:25769803776, len 4596840481148633088, written 4326371151975546884
D (395830) SPIFFS: append: 8002 wrote page 0004 to objix_hdr entry 0000 in mem
D (395840) SPIFFS: append: 8002 store fresh objix_hdr page, 0003:0000, written 25769803782
D (395840) SPIFFS: CALLBACK HUP obj_id:8002 spix:0000 npix:0003 nsz:4596840139732330157
D (395850) SPIFFS: callback: setting fd 3:8002(fdoffs:12884901894 offs:4596840137551249414) objix_hdr_pix to 0000, size:4326388126693616400
D (395870) SPIFFS: callback: setting fd 3:8002 span:0000 objix_pix to 0003
D (395870) SPIFFS: SPIFFS_open '/partial_horimeter_last_read.csv' 1e
D (395880) SPIFFS: SPIFFS_clearerr
W (395880) SPIFFS: There are not saved values, creating them...
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x42087ec0 PS : 0x00060430 A0 : 0x8207dd38 A1 : 0x3fcb4000
0x42087ec0: _vfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:846 (discriminator 1)
A2 : 0x3fcc34ac A3 : 0x00000000 A4 : 0x3c0a5c08 A5 : 0x3fcb4350
A6 : 0x3fcb4330 A7 : 0x00000008 A8 : 0x82087ebd A9 : 0x00000000
A10 : 0x00000000 A11 : 0x3fcb4254 A12 : 0x000000ff A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000064 LBEG : 0x400556d5 LEND : 0x400556e5 LCOUNT : 0xffffffff
0x400556d5: strlen in ROM
0x400556e5: strlen in ROM
Backtrace: 0x42087ebd:0x3fcb4000 0x4207dd35:0x3fcb4320 0x4200938a:0x3fcb4370 0x403825f6:0x3fcb43c0
0x42087ebd: _vfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:846 (discriminator 1)
0x4207dd35: fprintf at /builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/stdio/fprintf.c:54 (discriminator 1)
0x4200938a: vTaskIgnitionOn(void*) at /home/guilherme/Projects/Workana/CORSI/wifi_horimeter/CORSI-wifi_horimeter/main/horimeter.cpp:503
0x403825f6: vPortTaskWrapper at /home/guilherme/esp/v5.2.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134
These are the codes that are creating the SPIFFS and the VFS:
esp_vfs_t fs = {
.flags = ESP_VFS_FLAG_DEFAULT
};
esp_vfs_spiffs_conf_t spiffs_config = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 100,
.format_if_mount_failed = true
};
ESP_ERROR_CHECK(esp_vfs_register("/data", &fs, NULL));
ESP_ERROR_CHECK(esp_vfs_spiffs_register(&spiffs_config));