Need help for "Cache disabled but cached memory region accessed"

yuwenpeng
Posts: 30
Joined: Tue Apr 12, 2022 6:25 am

Need help for "Cache disabled but cached memory region accessed"

Postby yuwenpeng » Tue Apr 12, 2022 6:52 am

I'm suffering from the crash of "Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)". I've done a lot of searches and roughly know it is caused by an interrupt accessing a disabled cache, and the interrupt should be put in IRAM. Some similar post is https://www.esp32.com/viewtopic.php?f=2 ... e&start=10. But somehow I failed to fix the problem. I also tried using 'IRAM_ATTR' to force the interrupt handler in IRAM, but it didn't help.

Environment is ESP32 v3, Arduino, c/c++. Don't know which library did Arduino link to (could any one tell me how to find out?). I'm coding on Windows 10. VSCode also installed and can burn the code to ESP32 board.

I'm using ESP32 to periodically trigger an ADC chip (AD7606) by a timer, and read the data from AD7606 in the timer's interrupt via SPI. At the same time, I need to connect to Wifi and send the data to a computer via wifi network. The timer drives the ADC by 6000 samples per second, timer is set to 40M Hz, and period is 6666.
With the same code, if I ran either the ADC sampling or Wifi connecting, it works without any problem. But if I ran them together, it will crash immediately when I initial Wifi. Some post mentioned to modify parameters of 'menuconfig', but I don't know how to find/run 'menuconfig', anyone can help?

Code: Select all

CONFIG_SPI_MASTER_IN_IRAM=
CONFIG_SPI_MASTER_ISR_IN_IRAM=y
The code and Guru trace is attached below.

Code: Select all

PC: 0x400d0868: SPIClass::transferBytes(unsigned char const*, unsigned char*, unsigned int) at C:\Users\yuwen\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI\src\SPI.cpp line 242
EXCVADDR: 0x00000000

Decoding stack results
0x400d0868: SPIClass::transferBytes(unsigned char const*, unsigned char*, unsigned int) at C:\Users\yuwen\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI\src\SPI.cpp line 242
0x40081305: __timerISR at C:\Users\yuwen\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32\esp32-hal-timer.c line 88
0x4008edd3: esp_rom_spiflash_read_status at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/spi_flash_rom_patch.c line 262
0x4008ee0e: esp_rom_spiflash_wait_idle at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/spi_flash_rom_patch.c line 35
0x4008eeba: esp_rom_spiflash_read_data at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/spi_flash_rom_patch.c line 215
0x4008f6b1: esp_rom_spiflash_read at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/spi_flash_rom_patch.c line 588
0x40087d08: spi_flash_read at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spi_flash/flash_ops.c line 599
0x40134725: nvs::nvs_flash_read(unsigned int, void*, unsigned int) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_ops.cpp line 76
0x40132fe5: nvs::Page::readEntry(unsigned int, nvs::Item&) const at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_page.cpp line 739
0x40133417: nvs::Page::findItem(unsigned char, nvs::ItemType, char const*, unsigned int&, nvs::Item&, unsigned char, nvs::VerOffset) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_page.cpp line 783
0x40131def: nvs::Storage::findItem(unsigned char, nvs::ItemType, char const*, nvs::Page*&, nvs::Item&, unsigned char, nvs::VerOffset) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_storage.cpp line 154
0x401328ad: nvs::Storage::getItemDataSize(unsigned char, nvs::ItemType, char const*, unsigned int&) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_storage.cpp line 589
0x401313a6: nvs_get_str_or_blob(nvs_handle, nvs::ItemType, char const*, void*, size_t*) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_api.cpp line 525
0x40131921: nvs_get_blob(nvs_handle, char const*, void*, size_t*) at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/nvs_flash/src/nvs_api.cpp line 551
0x4012bf05: esp_wifi_init at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/wifi_init.c line 155
0x400d0fb9: WiFiGenericClass::mode(wifi_mode_t) at C:\Users\yuwen\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi\src\WiFiGeneric.cpp line 135
0x400d0662: ConnectToWifi() at C:\Users\yuwen\Documents\Arduino\UGA_ESP32\UGA_ESP32/UGA_ESP32.ino line 56
0x400d0733: setup() at C:\Users\yuwen\Documents\Arduino\UGA_ESP32\UGA_ESP32/UGA_ESP32.ino line 82
0x400d32a6: loopTask(void*) at C:\Users\yuwen\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32\main.cpp line 18
0x40089ca2: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

Code: Select all

#include <SPI.h>
#include "WiFi.h"
#include "esp32-hal-timer.h"

#define AD7607_PIN_CS       33
#define AD7606_PIN_SCLK     25
#define AD7606_PIN_MISO     27      //ESP32 master, AD7606 slave
#define AD7606_PIN_MOSI     26
#define AD7607_PIN_CNAB 21
#define AD7606_PIN_BUSY 17

int ADCTimerPeriod=6666;
SPIClass AD7606_SPI(VSPI);
uint8_t ReceiveBuff[2];
hw_timer_t* ADCTimer = NULL;
const char * WifiSSID = "YU"; //Wifi SSID
const char * WifiPWD = "yuPWD"; //Wifi password
boolean connected = false;
int valueIndex=0;
void IRAM_ATTR OnTimerAlarm()
{
    //----------Start ADC by sending a pulse to ADC CNAB ------------ 
    digitalWrite(AD7607_PIN_CNAB, LOW);
    digitalWrite(AD7607_PIN_CNAB, HIGH);
    //----------Read data from ADC ------------
    while(digitalRead(AD7606_PIN_BUSY)) {}
    AD7606_SPI.transferBytes(NULL,ReceiveBuff,2);
    int16_t value=(ReceiveBuff[0]<<8) | ReceiveBuff[1];
    if(valueIndex++>=30){
        Serial.printf("%d\r\n",value);
        valueIndex=0;
    }          
    //RawPOWBuff->AddToLast(value); //do something to the data.
}
///////////////////////////////////
//wifi event handler
void WiFiEvent(WiFiEvent_t event){
    switch(event) {
      case SYSTEM_EVENT_STA_GOT_IP:
          Serial.print("WiFi connected! IP address: ");
          Serial.println(WiFi.localIP());
          Serial.println(WiFi.gatewayIP());
          connected = true;
          break;
      case SYSTEM_EVENT_STA_DISCONNECTED:
          Serial.println("WiFi lost connection");
          connected = false;
          break;
      default: break;
    }
}
void ConnectToWifi()
{       
    Serial.println("Start to connect WIFI.\r\n");
    delay(3000);
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();    
    WiFi.onEvent(WiFiEvent);
    WiFi.begin(WifiSSID, WifiPWD);
    Serial.println("Waiting for WIFI connection...");
    delay(2000);
}
/////////////////////////////////////
void setup()
{
    Serial.begin(115200);
    Serial.println("Start");    
    //SPI to receive data from AD7606
    AD7606_SPI.begin(AD7606_PIN_SCLK, AD7606_PIN_MISO, AD7606_PIN_MOSI, AD7607_PIN_CS);
    AD7606_SPI.setFrequency(2000000);
    //Ini Pins which connect to AD7606
    pinMode(AD7607_PIN_CS, OUTPUT);
    pinMode(AD7606_PIN_BUSY, INPUT_PULLUP); 
    pinMode(AD7607_PIN_CNAB,OUTPUT_OPEN_DRAIN);
    digitalWrite(AD7607_PIN_CNAB, LOW); 
    ADCTimer=timerBegin(0,2,true);  //frequency 80M, divider=2, counter=40 M/s
    timerAttachInterrupt(ADCTimer,OnTimerAlarm,true);
    timerAlarmWrite(ADCTimer, ADCTimerPeriod, true);  //counter 40 M/s, 6000 sampling rate, the interval is 6666.666..
    timerAlarmEnable(ADCTimer);
    Serial.println("Start up done.");

    ConnectToWifi();        
}
void loop()
{
    delay(300);
}


WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Need help for "Cache disabled but cached memory region accessed"

Postby WiFive » Tue Apr 12, 2022 9:40 pm

the functions called in the isr have to be in iram too

yuwenpeng
Posts: 30
Joined: Tue Apr 12, 2022 6:25 am

Re: Need help for "Cache disabled but cached memory region accessed"

Postby yuwenpeng » Wed Apr 13, 2022 4:50 am

WiFive wrote:
Tue Apr 12, 2022 9:40 pm
the functions called in the isr have to be in iram too
Thank you WiFive! As you may see, all the functions called in the isr are defined in the library. Some of them are not in iram, but I can't modify them since a lot more function are called inside them. For this situation, what should I do?

Code: Select all

void IRAM_ATTR OnTimerAlarm()
{
    //----------Start ADC by sending a pulse to ADC CNAB ------------ 
    digitalWrite(AD7607_PIN_CNAB, LOW);
    digitalWrite(AD7607_PIN_CNAB, HIGH);
    //----------Read data from ADC ------------
    while(digitalRead(AD7606_PIN_BUSY)) {}
    AD7606_SPI.transferBytes(NULL,ReceiveBuff,2);
    int16_t value=(ReceiveBuff[0]<<8) | ReceiveBuff[1];
    if(valueIndex++>=30){
        Serial.printf("%d\r\n",value);
        valueIndex=0;
    }          
    //RawPOWBuff->AddToLast(value); //do something to the data.
}

Who is online

Users browsing this forum: Google [Bot] and 98 guests