"Cache disabled but cached memory region accessed" error for large stack size

ozgury
Posts: 1
Joined: Thu Dec 26, 2019 1:40 pm

"Cache disabled but cached memory region accessed" error for large stack size

Postby ozgury » Thu Dec 26, 2019 2:30 pm

Hi,
I am a WROVER user and getting exception while accessing a file from a static task. The problem occurs for large stack sizes, when I shrink the stack size it works. I searched for it and I could NOT find any similar post.. :(

Can anybody faced with the same problem and find a solution for it? Or is there anyone have any opinion about this..

Regards

Ozgur
esp_get_idf_version : v3.3-127-g0a0f2Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed)
Core 0 register dump:
PC : 0x40084d6b PS : 0x00060734 A0 : 0x800837f0 A1 : 0x3ffb02b0
A2 : 0x00000000 A3 : 0x00000001 A4 : 0x3ffafef0 A5 : 0x00000000
A6 : 0x00000001 A7 : 0x00000000 A8 : 0x3ffc0990 A9 : 0x00000000
A10 : 0x00000001 A11 : 0x12000248 A12 : 0x3ffbdc08 A13 : 0x00000018
A14 : 0x000000fe A15 : 0x00000000 SAR : 0x00000000 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000

ELF file SHA256: ad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0baad0bd0ba

Backtrace: 0x40084d6b:0x3ffb02b0 0x400837ed:0x3ffb02d0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0x3 (SW_RESET),boot:0x37 (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:1
load:0x3fff0018,len:4
load:0x3fff001c,len:612
load:0x40078000,len:9044
ho 0 tail 12 room 4
load:0x40080400,len:5196
entry 0x40080648
I (203) psram: This chip is ESP32-D0WD
I (204) spiram: Found 32MBit SPI RAM device
I (204) spiram: SPI RAM mode: flash 80m sram 80m
I (207) spiram: PSRAM initialized, cache is in low/high (2-core) mode.
I (214) cpu_start: Pro cpu up.
I (218) cpu_start: Application information:
I (223) cpu_start: Project name: ttSmartMultimeter
I (228) cpu_start: App version: 1
I (233) cpu_start: Compile time: Dec 26 2019 10:28:36
I (239) cpu_start: ELF file SHA256: 4f928746ca4f2d0f...
I (245) cpu_start: ESP-IDF: v3.3-127-g0a0f2caa1-dirty
I (251) cpu_start: Starting app cpu, entry point is 0x40081338
I (0) cpu_start: App cpu up.
I (262) heap_init: Initializing. RAM available for dynamic allocation:
I (269) heap_init: At 3FFAE6E0 len 0000F480 (61 KiB): DRAM
I (275) heap_init: At 3FFC2208 len 0001DDF8 (119 KiB): DRAM
I (281) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (287) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (294) heap_init: At 4008D5D4 len 00012A2C (74 KiB): IRAM
I (300) cpu_start: Pro cpu start user code
I (305) spiram: Adding pool of 4096K of external SPI memory to heap allocator
I (103) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (104) spiram: Reserving pool of 64K of internal memory for DMA/internal allocations
I (144) TEST_APP: Starting task1_task - Free Ram :4023504

I (154) TEST_APP: Starting task2_task - Free Ram :4023312
  1. #include <stdio.h>
  2. #include <fstream>
  3. #include <string.h>
  4. #include <iostream>
  5.  
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8.  
  9. #include "esp_log.h"
  10. #include "esp_spiffs.h"
  11.  
  12. #include "nvs_flash.h"
  13.  
  14. using namespace std;
  15.  
  16. #define TAG                            "TEST_APP"
  17.  
  18. #define TASK1_STACKSIZE   256 * 1024
  19. StackType_t  *task1_stack;
  20. StaticTask_t  task1_tcb;
  21.  
  22. #define TASK2_STACKSIZE   128 * 1024
  23. StackType_t  *task2_stack;
  24. StaticTask_t  task2_tcb;
  25.  
  26. /****************************** HANDLERS************************************/
  27. void task1_task(void *ignore) {
  28.        ESP_LOGI(TAG, "Starting task1_task - Free Ram :%d\n", esp_get_free_heap_size());
  29.  
  30.        while (true) {
  31.               vPortYield();
  32.               vTaskDelay(1000/portTICK_PERIOD_MS);
  33.        }
  34.  
  35.        vTaskDelete(NULL);
  36. }
  37.  
  38. void task2_task(void *ignore) {
  39.        ESP_LOGI(TAG, "Starting task2_task - Free Ram :%d\n", esp_get_free_heap_size());
  40.  
  41.        while (true) {
  42.               ofstream inFile ("/tt/testfile.txt", ios::out | ios::trunc);
  43.               if (inFile.is_open())
  44.               {
  45.                      inFile.write("Hello World", strlen("Hello World"));
  46.                      inFile.close();
  47.                      ESP_LOGI(TAG, "file written successfully.");
  48.               }
  49.               else ESP_LOGE(TAG, "file error.");
  50.  
  51.               vPortYield();
  52.               vTaskDelay(10000/portTICK_PERIOD_MS);
  53.        }
  54.  
  55.        vTaskDelete(NULL);
  56. }
  57.  
  58. extern "C" void app_main() {
  59.        nvs_flash_init();
  60.  
  61.     esp_vfs_spiffs_conf_t conf = {
  62.       .base_path = "/tt",
  63.       .partition_label = NULL,
  64.       .max_files = 5,
  65.       .format_if_mount_failed = true
  66.     };
  67.  
  68.     esp_err_t err = esp_vfs_spiffs_register(&conf);
  69.     if(err){
  70.         ESP_LOGE(TAG, "Mounting SPIFFS failed! Error: %d", err);
  71.         esp_restart();
  72.     }
  73.  
  74.        task1_stack                = (StackType_t *)malloc(TASK1_STACKSIZE);
  75.        task2_stack                = (StackType_t *)malloc(TASK2_STACKSIZE);
  76.  
  77.        xTaskCreateStatic(task1_task,    "task1_task", TASK1_STACKSIZE, NULL, (tskIDLE_PRIORITY + 2),    task1_stack, &task1_tcb);
  78.        xTaskCreateStatic(task2_task,    "task2_task", TASK2_STACKSIZE, NULL, (tskIDLE_PRIORITY + 2),    task2_stack, &task2_tcb);
  79.  
  80.        printf("021-Free Ram Disp %d\n", esp_get_free_heap_size());
  81.        printf("esp_get_idf_version : %s\n", esp_get_idf_version());
  82. }
  83.  

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby ESP_Sprite » Fri Dec 27, 2019 3:47 am

Interesting... can you see where the backtrace points? (Ether use addr2line on the addresses, or use 'make monitor' as your terminal)

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby chegewara » Fri Dec 27, 2019 5:59 am

Task stack can be allocated only from internal memory, so you cant to create task with stack 256kB.
#define TASK1_STACKSIZE 256 * 1024

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby ESP_Sprite » Fri Dec 27, 2019 9:04 am

Oh wow, I did not spot that. Please do not use taskCreateStatic with PSRAM unless you know what you're doing; if the normal taskCreate fails, it does so for a reason.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby chegewara » Thu Jan 09, 2020 2:16 pm

After studying problem i found this:
1) https://www.freertos.org/xTaskCreateStatic.html
Create a new task and add it to the list of tasks that are ready to run. configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for this RTOS API function to be available.
which is not enabled in arduino
https://github.com/espressif/arduino-es ... onfig#L558

2) most likely you would have to use ps_malloc to allocate stack/memory from PSRAM (but im not 100% sure here)

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby ESP_Sprite » Fri Jan 10, 2020 3:02 am

@chegewara: There isn't really a good reason to use xTaskCreateStatic on the ESP32 unless 1. for some reason you hate the memory allocator and want to allocate the task entirely on statically allocated BSS memory, or 2. you need the stack to be in PSRAM and know for 100% sure what consequences that has and are prepared to accept and work around those. For all circumstances, just use xTaskCreate and let esp-idf figure out how to get the memory.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: "Cache disabled but cached memory region accessed" error for large stack size

Postby chegewara » Fri Jan 10, 2020 4:01 pm

@ESP_Sprite, i just wanted to correct myself, because my first answer was incorrect. It is possible to to create task with stack in PSRAM, which i just learned (only theory). So, his/her code should works if settings in menuconfig are enabled.
What i would do is to allocate memory for stack with heap_caps_malloc, just in case. Also make sure its returning not NULL value:
If neither puxStackBuffer or pxTaskBuffer are NULL then the task will be created, and the task’s handle is returned. If either puxStackBuffer or pxTaskBuffer is NULL then the task will not be created and NULL will be returned.

Who is online

Users browsing this forum: No registered users and 103 guests