As I understand, when accessing the files on the SPIFFS partition, the cache gets disabled but my function tries to access cached data. How can I resolve this problem?
This is the function which is called from the HTTP server:
Code: Select all
ssize_t valuelogger_get(channel_id_t channel_id, time_t from_time, sensor_val_t** values) {
char* filename;
char line[32];
uint32_t val_idx = 0;
uint32_t line_num = 0;
asprintf(&filename, "/spiffs/%d.txt", channel_id);
ESP_LOGI(TAG, "Retrieving content of %s where time >= %lu", filename, from_time);
FILE* fp = fopen(filename, "r");
if (fp == NULL) {
ESP_LOGE(TAG, "Failed to open file");
free(filename);
return -1;
}
int32_t startingPos = -1;
int32_t filepos = ftell(fp);
int32_t value_num = 0;
while (fgets(line, 64, fp)) {
char* token = strtok(line, ",");
time_t time = 0;
float val = 0;
char* end;
for (uint8_t i = 0; i < 2 && token; i++) {
if (i == 0) {
time = strtoul(token, &end, 10);
} else if (i == 1) {
val = strtod(token, &end);
}
token = strtok(NULL, ",");
}
if (time != 0 && val != 0) {
// ESP_LOGI(TAG, "Parsed values: t=%lu, val=%.2f", time, val);
if (time >= from_time) {
value_num++;
if (startingPos == -1) {
startingPos = filepos;
}
}
} else {
ESP_LOGW(TAG, "Line errornous (line: %s)", line);
}
line_num++;
filepos = ftell(fp);
}
ESP_LOGI(TAG, "Allocating for %u values", value_num);
*values = malloc(value_num * sizeof(sensor_val_t));
fseek(fp, startingPos, SEEK_SET);
while (fgets(line, 64, fp)) {
char* token = strtok(line, ",");
time_t time = 0;
float val = 0;
char* end;
for (uint8_t i = 0; i < 2 && token; i++) {
if (i == 0) {
time = strtoul(token, &end, 10);
} else if (i == 1) {
val = strtod(token, &end);
}
token = strtok(NULL, ",");
}
if (time != 0 && val != 0) {
if (time >= from_time) {
(*values)[val_idx++] = (sensor_val_t){.time = time, .value = val};
}
}
}
fclose(fp);
free(filename);
ESP_LOGI(TAG, "Retrieved %u values of total %u", val_idx, line_num);
return val_idx;
}
Code: Select all
I (20258) VALLOG: Retrieving content of /spiffs/0.txt where time >= 1650683590
Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed).
Core 0 register dump:
PC : 0x4017ae40 PS : 0x00060035 A0 : 0x8008229c A1 : 0x3ffbe8d0
0x4017ae40: rmt_ll_get_tx_err_interrupt_status at /home/marcel/esp/esp-idf/components/hal/esp32/include/hal/rmt_ll.h:307
A2 : 0x3ffbf2dc A3 : 0x00000000 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x80083d50 A9 : 0x000e0f20
A10 : 0x3ff56000 A11 : 0x3ffbe8d4 A12 : 0x3ffba0f8 A13 : 0x3ffba14c
A14 : 0x00060023 A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0xffffffff
Backtrace:0x4017ae3d:0x3ffbe8d00x40082299:0x3ffbe910 0x40082cfd:0x3ffbe930 0x400847f2:0x3ffb01b0 0x40083310:0x3ffb01d0
0x4017ae3d: rmt_ll_enable_tx_err_interrupt at /home/marcel/esp/esp-idf/components/hal/esp32/include/hal/rmt_ll.h:252
0x40082299: shared_intr_isr at /home/marcel/esp/esp-idf/components/esp_hw_support/intr_alloc.c:407
0x40082cfd: _xt_lowint1 at /home/marcel/esp/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1111
0x400847f2: spi_flash_op_block_func at /home/marcel/esp/esp-idf/components/spi_flash/cache_utils.c:122
0x40083310: ipc_task at /home/marcel/esp/esp-idf/components/esp_ipc/src/esp_ipc.c:77
ELF file SHA256: 7bc1ea7c6dccd751
Rebooting...
- IDF Version 4.4
- Custom PCB with a ESP32-WROMM-32E