Guru Meditation Error: Cache disabled but cached memory region accessed

raduangelescu
Posts: 2
Joined: Mon Jun 10, 2019 5:02 am

Guru Meditation Error: Cache disabled but cached memory region accessed

Postby raduangelescu » Mon Jun 10, 2019 5:06 am

Hello,

I have piece of code that after running a few hours (3-5 hours) gives me the above kernel panic "Guru Meditation Error: Cache disabled but cached memory region accessed" . The callstack does not tell me anything (it doesn't dump much).

This is the culprit code (if I remove digitalWrite from timer ISR it no longer crashes, but that could be because the whole code gets optimized and doesn't execute).
  1. #pragma once
  2.  
  3. #include <Settings.h>
  4.  
  5. DRAM_ATTR volatile unsigned long long inctimer = 0;
  6. DRAM_ATTR volatile bool onlyLow = false;
  7. DRAM_ATTR volatile unsigned char g_state = 0;
  8. DRAM_ATTR volatile const unsigned long long divizor = 10;
  9. DRAM_ATTR volatile unsigned long  startZCMicros = 0;
  10. DRAM_ATTR volatile unsigned long long intervalZCMicros = 10000/divizor; // 50 hz
  11. DRAM_ATTR volatile unsigned long long pulseLengthMicros = 300/divizor;
  12. DRAM_ATTR volatile unsigned long long pulseBeginMicros  = LONG_MAX;
  13. DRAM_ATTR volatile unsigned long  long pulseOffsetZCMicros = LONG_MAX;
  14.  
  15. void IRAM_ATTR OnTimerHeater()
  16. {
  17.     if(onlyLow)
  18.     {
  19.         digitalWrite(CONTROL_PIN, LOW);
  20.         return;
  21.     }
  22.     volatile long currentMicros = micros()/divizor;
  23.     volatile long localPulseBeginMicros = pulseBeginMicros + pulseOffsetZCMicros;
  24.     volatile long localPulseEndMicros   = pulseBeginMicros + pulseOffsetZCMicros + pulseLengthMicros;
  25.    
  26.     if(currentMicros >= localPulseEndMicros)
  27.     {
  28.          digitalWrite(CONTROL_PIN, LOW);
  29.     }
  30.     else if(currentMicros  >= localPulseBeginMicros)
  31.     {
  32.          digitalWrite(CONTROL_PIN, HIGH);
  33.     }
  34.  
  35. }
  36.  
  37. void IRAM_ATTR OnZeroCrossHeater()
  38. {
  39.     volatile const long current_micros = micros()/divizor;
  40.     volatile int i = 0;
  41.     if(digitalRead(ZERO_CROSS_PIN) == LOW)
  42.     {
  43.         for (; i < 1000; ++i) {}
  44.         if(digitalRead(ZERO_CROSS_PIN) == HIGH)
  45.         {
  46.             return;
  47.         }
  48.     }
  49.     else
  50.     {
  51.         return;
  52.     }
  53.  
  54.     if(current_micros - startZCMicros < 100)
  55.     {
  56.         return;
  57.     }
  58.  
  59.  
  60.     switch(g_state)
  61.     {
  62.         case 0:
  63.             startZCMicros = current_micros;
  64.             break;
  65.         case 1:
  66.             intervalZCMicros = current_micros - startZCMicros;
  67.             break;    
  68.     }
  69.  
  70.     g_state++;
  71.     if(g_state > 1)
  72.     {
  73.         g_state = 0;
  74.     }
  75.  
  76.     if(intervalZCMicros != -1)
  77.     {
  78.         pulseBeginMicros = current_micros;
  79.     }
  80. }
  81.  
  82. class Heater
  83. {
  84.     double      m_prev_value  = 0.0;
  85.     hw_timer_t* m_timer  = nullptr;
  86.  
  87.     public:
  88.  
  89.     Heater()
  90.     {
  91.  
  92.     }
  93.  
  94.     void setup()
  95.     {
  96.         pinMode(CONTROL_PIN, OUTPUT);
  97.         pinMode(ZERO_CROSS_PIN, INPUT_PULLUP);
  98.  
  99.         digitalWrite(CONTROL_PIN, LOW);
  100.  
  101.         m_timer = timerBegin(0, 80 * divizor, true);
  102.         // per microsecond
  103.         timerAttachInterrupt(m_timer, &OnTimerHeater, true);
  104.         timerAlarmWrite(m_timer, 1, true);
  105.  
  106.         timerAlarmEnable(m_timer);
  107.  
  108.         attachInterrupt(ZERO_CROSS_PIN, OnZeroCrossHeater, RISING);
  109.     }
  110.    
  111.     void set(double value)
  112.     {
  113.         if(value > 50.0)
  114.         {
  115.             value = 50.0;
  116.         }
  117.         if(value < 0.0)
  118.         {
  119.             value = 0.0;
  120.         }
  121.        
  122.         unsigned long long localinterval = intervalZCMicros;
  123.      
  124.         if(m_prev_value == value)
  125.         {
  126.             return;
  127.         }
  128.      
  129.         unsigned long long localCalculation = 0;
  130.         if(abs(value) < 0.01 )
  131.         {
  132.             localCalculation = LONG_MAX;
  133.             onlyLow = true;
  134.         }
  135.         else
  136.         {
  137.             onlyLow = false;
  138.             localCalculation = (long long)((100.0 - value) * 0.01 * localinterval) - pulseLengthMicros;
  139.         }
  140.        
  141.         if(localCalculation < 0)
  142.         {
  143.             localCalculation = 0;
  144.         }
  145.  
  146.      
  147.         pulseOffsetZCMicros = localCalculation;
  148.        
  149.        
  150.         Serial.print("heating with ");
  151.         Serial.print(value);
  152.      
  153.         Serial.println("--");
  154.         m_prev_value = value;
  155.     }
  156.  
  157.     void loop()
  158.     {
  159.     }
  160. };
I researched the problem but I can't understand what is the cache that is accessed.. I made everything volatile and in DRAM... (I don't use SPI , only I2C)

Cheers,
Radu

raduangelescu
Posts: 2
Joined: Mon Jun 10, 2019 5:02 am

Re: Guru Meditation Error: Cache disabled but cached memory region accessed

Postby raduangelescu » Mon Jun 10, 2019 5:58 pm

As a memory "dump" I only get : Memory dump at 0x40161aec: bad00bad bad00bad bad00bad

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

Re: Guru Meditation Error: Cache disabled but cached memory region accessed

Postby ESP_Sprite » Tue Jun 11, 2019 12:53 am

This happens if you call a function that is not in IRAM (perhaps digitalWrite?) while the flash cache is disabled because the ESP32 needs to write to flash. However, normally ESP-IDF disables interrupts when it accesses flash unless you specifically tell it not to... I don't know if the Arduino code also does this, though.

ningappa BS
Posts: 51
Joined: Sat Mar 17, 2018 4:49 am

Re: Guru Meditation Error: Cache disabled but cached memory region accessed

Postby ningappa BS » Tue Oct 01, 2019 10:48 am

ESP_Sprite wrote:
Tue Jun 11, 2019 12:53 am
This happens if you call a function that is not in IRAM (perhaps digitalWrite?) while the flash cache is disabled because the ESP32 needs to write to flash. However, normally ESP-IDF disables interrupts when it accesses flash unless you specifically tell it not to... I don't know if the Arduino code also does this, though.
Hi ESP_Sprite,

I used GPIO.out_w1tc = (1 << 19) instred of gpio_set_level(GPIO_NUM_19, 0) but still I'm getting error Guru Meditation Error: Cache disabled but cached memory region accessed and I did not get SPI_MASTER_ISR_IN_IRAM in menuconfig and also in sdkconfig. Please help me to solve problem.

thanks

Who is online

Users browsing this forum: No registered users and 56 guests