spi_flash_read panic'ed

arespno
Posts: 8
Joined: Sat Feb 20, 2016 12:19 pm

spi_flash_read panic'ed

Postby arespno » Tue Dec 20, 2016 9:01 am

Error when using core 1 to test spi_flash_read:

Code: Select all

void testTask(void *arg)
{
   const uint32_t cpuid = (uint32_t) arg;
   assert(cpuid == xPortGetCoreID());

   vTaskDelay(100 / portTICK_PERIOD_MS);   
   const uint32_t sector = cpuid + 6;
   const uint32_t n = SPI_FLASH_SEC_SIZE;
   ets_printf("t%d\n", cpuid);
   uint32_t val_read;
   for (uint32_t offset = 0; offset < n; offset += 4) {
      if (spi_flash_read(sector * SPI_FLASH_SEC_SIZE + offset, (uint8_t *) &val_read, 4) != ESP_OK) {
         ets_printf("Read failed at offset=%d\r\n", offset);
         break;
      }
   }
   ets_printf("td%d\n", cpuid);
   vTaskDelete(NULL);
}

void app_main()
{
    nvs_flash_init();
    tcpip_adapter_init();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t save_sta_config;
    ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &save_sta_config));
    if (save_sta_config.sta.ssid[0] == '\x0') {
        wifi_config_t sta_config = {
            .sta = {
                .ssid = "ssid",
                .password = "password",
                .bssid_set = false
            }
        };
        ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    }
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );

   xTaskCreatePinnedToCore(testTask, "TestTask", 2048, (void *) 1, 1, NULL, 1);
}



Error message:

Code: Select all


I (840) heap_alloc_caps: Initializing. RAM available for dynamic allocation:
I (840) heap_alloc_caps: At 3FFC18BC len 0001E744 (121 KiB): DRAM
I (848) heap_alloc_caps: At 3FFE8000 len 00018000 (96 KiB): D/IRAM
I (858) heap_alloc_caps: At 4009B9B0 len 00004650 (17 KiB): IRAM
I (868) cpu_start: Pro cpu up.
I (874) cpu_start: Starting app cpu, entry point is 0x40080ba0
I (0) cpu_start: App cpu up.
I (889) cpu_start: Pro cpu start user code
I (1118) phy: phy_version: 258, Nov 29 2016, 15:51:07, 0, 0
I (1638) cpu_start: Starting scheduler on PRO CPU.
I (765) cpu_start: Starting scheduler on APP CPU.
tcpip_task_hdlxxx : 3ffc6144, prio:18,stack:2048
I (769) wifi: frc2_timer_task_hdl:3ffc7c34, prio:22, stack:2048
I (784) wifi: pp_task_hdl : 3ffca494, prio:23, stack:8192
I (785) wifi: mode : sta (24:0a:c4:00:3d:6e)
t1
Guru Meditation Error: Core  0 panic'ed (Double exception)
Register dump:
PC      : 0xffffffff  PS      : 0x00060036  A0      : 0x7fffffff  A1      : 0x3ff81fa0 
A2      : 0x3ff82010  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x3ffb0000 
A6      : 0x00009058  A7      : 0x00004001  A8      : 0x8005a2a2  A9      : 0x00000000 
A10     : 0x3ff96162  A11     : 0x3ff9c357  A12     : 0x00000000  A13     : 0x00000000 
A14     : 0x00000301  A15     : 0x00060223  SAR     : 0x00000017  EXCCAUSE: 0x00000002 
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff 

Backtrace: 0x00000000:0x3ff81fa0

CPU halted.


How to solve?

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

Re: spi_flash_read panic'ed

Postby ESP_Sprite » Tue Dec 20, 2016 9:34 am

Can you retry this on the latest esp-idf? For some time in the past, there has been a bug in the exception handler, causing a double exception obscuring the real problem. I'm not saying this should make your base bug go away, but it should give you a backtrace that is more useful.

arespno
Posts: 8
Joined: Sat Feb 20, 2016 12:19 pm

Re: spi_flash_read panic'ed

Postby arespno » Tue Dec 20, 2016 10:32 am

Thanks for reply.

Yes, I do it with the latest esp-idf.

When I use NVS instead of EEPROM in arduino-esp32, a similar error occurs randomly.

So after DEBUG, found to be caused by spi_flash_* app. Wrote a simple test
program with ESP-IDF, that produces the same error. If not used WiFi is normal,
I suspect that the caused by WiFi interruption.

On /esp-idf/components/spi_flash/cache_utils.h, I found:

// Suspend the scheduler on both CPUs, disable cache.
// Contrary to its name this doesn't do anything with interrupts, yet.
// Interrupt disabling capability will be added once we implement
// interrupt allocation API.
void spi_flash_disable_interrupts_caches_and_other_cpu();


Well, I try it in esp-idf updated today, the error was:

Code: Select all


Guru Meditation Error of type IllegalInstruction occurred on core  0. Exception was unhandled.
Register dump:
PC      : 0x400d1f6a  PS      : 0x00060b33  A0      : 0x8008257b  A1      : 0x3ffc00f0 
A2      : 0x00000001  A3      : 0x00060b23  A4      : 0x00060b23  A5      : 0xb33f0000 
A6      : 0xb33fffff  A7      : 0x40081c34  A8      : 0x80083954  A9      : 0x3ffc00e0 
A10     : 0x00060b23  A11     : 0x00060b23  A12     : 0x00060b23  A13     : 0xb33f0000 
A14     : 0xb33fffff  A15     : 0x3ffc0228  SAR     : 0x00000012  EXCCAUSE: 0x00000000 
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff 

Backtrace: 0x400d1f6a:0x3ffc00f0 0x4008257b:0x3ffc0110 0x4008329b:0x3ffc0130 0x40083f40:0x3ffc0150 0x40096905:0x3ffc0170 0x400929d8:0x3ffc01c0 0x4009a68c:0x3ffc01e0 0x400811c1:0x3ffc0210

CPU halted.



or

Code: Select all


I (890) wifi: n:1 1, o:1 0, ap:255 255, sta:1 1, prof:1
Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU1)
Register dump:
PC      : 0x40081c5c  PS      : 0x00060e34  A0      : 0x80080d2e  A1      : 0x3ffc20b0 
A2      : 0x00000000  A3      : 0x00000001  A4      : 0x00000000  A5      : 0x00000000 
A6      : 0x3ffc1bc0  A7      : 0x3ffc1b88  A8      : 0x00000000  A9      : 0x3ffbde61 
A10     : 0x00000000  A11     : 0x3ffbde68  A12     : 0x3ffcbe1c  A13     : 0x3ffc3590 
A14     : 0x00000017  A15     : 0x00000001  SAR     : 0x00000020  EXCCAUSE: 0x00000006 
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000 

Backtrace: 0x40081c5c:0x3ffc20b0 0x40080d2e:0x3ffc20d0

CPU halted.


ESP_igrr
Posts: 834
Joined: Tue Dec 01, 2015 8:37 am

Re: spi_flash_read panic'ed

Postby ESP_igrr » Tue Dec 20, 2016 3:00 pm

Wrote a simple test
program with ESP-IDF, that produces the same error.


Could you please attach this test program?

arespno
Posts: 8
Joined: Sat Feb 20, 2016 12:19 pm

Re: spi_flash_read panic'ed

Postby arespno » Tue Dec 20, 2016 3:30 pm

The test program:

Code: Select all


#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_spi_flash.h"
#include "nvs.h"
#include "nvs_flash.h"

esp_err_t event_handler(void *ctx, system_event_t *event)
{
    return ESP_OK;
}

void testTask(void *arg)
{
   const uint32_t cpuid = (uint32_t) arg;
   assert(cpuid == xPortGetCoreID());

   vTaskDelay(100 / portTICK_PERIOD_MS);   
   const uint32_t sector = cpuid + 6;
   const uint32_t n = SPI_FLASH_SEC_SIZE;
   ets_printf("t%d\n", cpuid);
   uint32_t val_read;
   for (uint32_t offset = 0; offset < n; offset += 4) {
      if (spi_flash_read(sector * SPI_FLASH_SEC_SIZE + offset, (uint8_t *) &val_read, 4) != ESP_OK) {
         ets_printf("Read failed at offset=%d\r\n", offset);
         break;
      }
   }
   ets_printf("td%d\n", cpuid);
   vTaskDelete(NULL);
}

void app_main()
{
    nvs_flash_init();
    tcpip_adapter_init();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t save_sta_config;
    ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &save_sta_config));
    if (save_sta_config.sta.ssid[0] == '\x0') {
        wifi_config_t sta_config = {
            .sta = {
                .ssid = "ssid",
                .password = "password",
                .bssid_set = false
            }
        };
        ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    }
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );

   xTaskCreatePinnedToCore(testTask, "TestTask", 2048, (void *) 1, 1, NULL, 1);
}


Who is online

Users browsing this forum: No registered users and 3 guests