I have been trying to start a project using a WROOM module with an SD card, humifdity, temp, GPS and some other sensors but I am stuck at base level. I want to use different tasks for each sensor, sending messages to the SD card task, so that it will write when needed to the card but I have continuous stack overflows and reboots.
I compiled and run successfully the SD card example alone, but when I try to put it in a task I get the following
Code: Select all
Leaving...
Hard resetting...
MONITOR
--- idf_monitor on COM8 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0010,len:4
load:0x3fff0014,len:4424
load:0x40078000,len:0
ho 12 tail 0 room 4
load:0x40078000,len:11460
entry 0x40078cc4
W (35) rtc_clk: Possibly invalid CONFIG_ESP32_XTAL_FREQ setting (40MHz). Detected 40 MHz.
I (281) cpu_start: Pro cpu up.
I (281) cpu_start: Single core mode
I (283) heap_init: Initializing. RAM available for dynamic allocation:
I (293) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (312) heap_init: At 3FFB1CF8 len 0002E308 (184 KiB): DRAM
I (331) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (350) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (370) heap_init: At 40087E08 len 000181F8 (96 KiB): IRAM
I (389) cpu_start: Pro cpu start user code
I (452) cpu_start: Starting scheduler on PRO CPU.
I (457) appname: Starting program
I (466) appname: Done nvs_flash_init
I (3466) appname: Starting tasks
I (3466) appname: Done starting tasks
I (3466) appname: Initializing SD car***ERROR*** A stack overflow in task task_SD_card has been detected.
abort() was called at PC 0x4008664c on core 0
0x4008664c: vApplicationStackOverflowHook at C:/tools/msys32/home/kgotsis/esp-idf/components/esp32/panic.c:553
Backtrace: 0x40086534:0x3ffb90b0 0x40086633:0x3ffb90d0 0x4008664c:0x3ffb90f0 0x40083a75:0x3ffb9110 0x40085430:0x3ffb9130 0x400853ea:0x0000d000
0x40086534: invoke_abort at C:/tools/msys32/home/kgotsis/esp-idf/components/esp32/panic.c:553
0x40086633: abort at C:/tools/msys32/home/kgotsis/esp-idf/components/esp32/panic.c:553
0x4008664c: vApplicationStackOverflowHook at C:/tools/msys32/home/kgotsis/esp-idf/components/esp32/panic.c:553
0x40083a75: vTaskSwitchContext at C:/tools/msys32/home/kgotsis/esp-idf/components/freertos/tasks.c:4482
0x40085430: _frxt_dispatch at C:/tools/msys32/home/kgotsis/esp-idf/components/freertos/portasm.S:393
0x400853ea: _frxt_int_exit at C:/tools/msys32/home/kgotsis/esp-idf/components/freertos/portasm.S:205
Rebooting...
Code: Select all
#include "freertos/FreeRTOS.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "esp_vfs_fat.h"
#include "driver/gpio.h"
#include "esp_log.h"
static const char *TAG = "appname";
int setupSDCard()
{
ESP_LOGI(TAG, "Initializing SD card");
gpio_pullup_en(GPIO_NUM_2);
vTaskDelay(200 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "Using SDMMC peripheral");
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
// To use 1-line SD mode, uncomment the following line:
host.flags = SDMMC_HOST_FLAG_1BIT;
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
//config.max_freq_khz = SDMMC_FREQ_PROBING; // << add this line
// Options for mounting the filesystem.
// If format_if_mount_failed is set to true, SD card will be partitioned and
// formatted in case when mounting fails.
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 5
};
// Use settings defined above to initialize SD card and mount FAT filesystem.
// Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
// Please check its source code and implement error recovery when developing
// production applications.
sdmmc_card_t* card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount filesystem. "
"If you want the card to be formatted, set format_if_mount_failed = true.");
} else {
ESP_LOGE(TAG, "Failed to initialize the card (%d). "
"Make sure SD card lines have pull-up resistors in place.", ret);
}
return ESP_OK;
}
return ESP_OK;
}
static void tskSDCard()
{
setupSDCard();
// some code will be added here
while (1){
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main(void)
{
ESP_LOGI(TAG, "Starting program");
nvs_flash_init();
ESP_LOGI(TAG, "Done nvs_flash_init");
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
vTaskDelay(3000 / portTICK_PERIOD_MS);
int level = 0;
ESP_LOGI(TAG, "Starting tasks");
xTaskCreate(tskSDCard, "task_SD_card", 1024, NULL, tskIDLE_PRIORITY, NULL);
//xTaskCreate(&tskHumidity, "task_Humidity", 1024, NULL, tskIDLE_PRIORITY, NULL);
//xTaskCreate(&tskTemperature, "task_Temperature", 1024, NULL, tskIDLE_PRIORITY, NULL);
// additional tasks
ESP_LOGI(TAG, "Done starting tasks");
while (true) { //keepalive indicator
gpio_set_level(GPIO_NUM_4, level);
level = !level;
vTaskDelay(300 / portTICK_PERIOD_MS);
}
}
Thank you in advance