Hello
I am trying to write some data to an SD card on an OLIMEX ESP32-EVB.
Starting from the examples in esp-idf and from olimex, this works fine.
However, when I want to put this in a freertos task, I always get errors:
E (16919) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
E (16919) diskio_sdmmc: sdmmc_read_blocks failed (263)
E (16919) example: Failed to open file for writing
E (16929) FreeRTOS: FreeRTOS Task "task_SD_storage" should not return, Aborting now!
abort() was called at PC 0x40087fab on core 0
And then the system reboots. Everytime this task is started, this error pops up and the ESP32 restarts. The other tasks seems to work fine...
This is the task that needs to write and where the problem seems to occur:
void store_SD(void *ignore)
{
/* Low priority variables */
//uint8_t output_data=0;
// sample_read holds the measurement sample that is about to be processed in this task
// note: the variable is initialized to {0} to set all bits to zero
sample_t sample_read = {0};
while(1) {
/* Update the DAC setting */
//printf("Updating the DAC setting\n");
//dac_output_voltage(DAC_EXAMPLE_CHANNEL, output_data++);
/* Write buffer to file */
// The next element into the data_to_store_queue is copied into the memory at location &sample_read (pointing to the address of sample_read)
if(xQueueReceive(data_to_store_queue, &sample_read, 10000)){
// A log message flags that the process to open the file holding the data is opened
ESP_LOGI(TAG, "Opening file");
// Open the data file
//FILE* f = fopen("/sdcard/data19_03_2020.csv", "a");
//FILE* f = fopen("/sdcard/data2602.csv", "w");
FILE* f = fopen("/sdcard/testen.txt", "w");
// Flag an error if the file could not be opened
// todo Handle the file open error such that the data is discarded and the firmware continues operation
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return; //THis will reboot the ESP
}
printf("Starting some writing to csv \n");
// Write the data to a csv file
uint8_t i = 0;
// Add the timestamp to the csv file
fprintf(f, "%lu%s", sample_read.timestamp_unix, CSV_SEPARATOR);
printf("%lu \n", sample_read.timestamp_unix);
fprintf(f, "%lu%s", sample_read.timestamp_us, CSV_SEPARATOR);
printf("%lu \n", sample_read.timestamp_us);
for(i = 0; i < COUNT_OF(sample_read.data)-1; i++)
{
// Add the next value to the csv file
fprintf(f, "%f%s", sample_read.data, CSV_SEPARATOR);
// User feedback
printf("%u : %f \n", i, sample_read.data);
}
// User feedback
printf("%u : %f \n", i, sample_read.data);
// Add the final line to the csv file
fprintf(f, "%f%s", sample_read.data, CSV_NEWLINE);
fclose(f);
ESP_LOGI(TAG, "File written");
/* Sleep */
//vTaskDelay(2000 / portTICK_RATE_MS);
}
}
}
Is there something which I am doing wrong?
THis is the creation of the tasks in app_main:
xTaskCreate(START, "task_start", 4096, NULL, 1, NULL);
printf("Task 1 OK \n");
xTaskCreate(DAQ, "task_DAQ", 4096, NULL, 1, NULL);
printf("Task 2 OK \n");
xTaskCreate(PROT, "task_PROT", 4096, NULL, 1, NULL);
printf("Task 3 OK \n");
xTaskCreate(control_converter, "task_CRTL", 4096, NULL, 1, xHandle_CTRL);
printf("Task 4 OK \n");
xTaskCreate(store_SD, "task_SD_storage", 8192, NULL, 1, NULL);
printf("Task 5 OK \n");
File on SD card does not want to open
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: No registered users and 178 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.