Guru Meditation Error: Core 0 panic'ed (LoadProhibited),(Interrupt wdt timeout on CPU1)

0

I was trying to record light intensity values for a Li-Fi project.

This is my code:

#include <soc/sens_reg.h>
#include <soc/sens_struct.h>
#include <driver/adc.h>
#include <SD.h>

#define ADC1_GPIO36_CHANNEL  ADC1_CHANNEL_0

#include <adc_channel.h>

const char filename1[] = "/part1.dat";
const char filename2[] = "/part2.dat";
File file1, file2;

int local_adc1_read(int channel) {
    uint16_t adc_value;
    SENS.sar_meas_start1.sar1_en_pad = (1 << channel); // Only one channel is selected
    while (SENS.sar_slave_addr1.meas_status != 0)
        ;

    SENS.sar_meas_start1.meas1_start_sar = 0;
    SENS.sar_meas_start1.meas1_start_sar = 1;
    while (SENS.sar_meas_start1.meas1_done_sar == 0)
        ;

    adc_value = SENS.sar_meas_start1.meas1_data_sar;
    return adc_value;
}

#define ADC_SAMPLES_COUNT 1000

int16_t abuf[ADC_SAMPLES_COUNT];
int16_t abufPos = 0;
portMUX_TYPE DRAM_ATTR timerMux = portMUX_INITIALIZER_UNLOCKED;
TaskHandle_t complexHandlerTask;
hw_timer_t * adcTimer = NULL; // Our timer

void complexHandler(void *param) {
    timerAlarmDisable(adcTimer);
    timerDetachInterrupt(adcTimer);
    timerEnd(adcTimer);
    adcTimer = NULL;
    file1 = SD.open(filename1, FILE_WRITE);
    file2 = SD.open(filename2, FILE_WRITE);
    file1.write((const byte*)abuf, abufPos);
    file2.write((const byte*)abuf, abufPos);
    file1.close();
    file2.close();
}

int counter;

void IRAM_ATTR onTimer() {
    portENTER_CRITICAL_ISR(&timerMux);

    abuf[abufPos++] = local_adc1_read(ADC1_CHANNEL_0);
    //abuf[abufPos++] = adc1_get_raw(ADC1_CHANNEL_0);

    if (abufPos >= 8) {
        if (abuf[abufPos-7] ==
            abuf[abufPos-6] ==
            abuf[abufPos-5] ==
            abuf[abufPos-4] ==
            abuf[abufPos-3] ==
            abuf[abufPos-2] ==
            abuf[abufPos-1] ==
            abuf[abufPos])
        {
            // Notify adcTask that the buffer is full.
            BaseType_t xHigherPriorityTaskWoken = pdFALSE;
            vTaskNotifyGiveFromISR(complexHandlerTask, &xHigherPriorityTaskWoken);
            if (xHigherPriorityTaskWoken) {
                portYIELD_FROM_ISR();
            }
        }
        portEXIT_CRITICAL_ISR(&timerMux);
    }
}

void setup() {
    setCpuFrequencyMhz(240);
    xTaskCreate(complexHandler, "Handler Task", 8192, NULL, 1, &complexHandlerTask);
    adcTimer = timerBegin(3, 80, true); // 80 MHz / 80 = 1 MHz hardware clock for easy figuring
    timerAttachInterrupt(adcTimer, &onTimer, true); // Attaches the handler function to the timer
    timerAlarmWrite(adcTimer, 100, true); // Interrupts when counter == 45, i.e. 22.222 times a second
    timerAlarmEnable(adcTimer);

    Serial.begin(115200);
    pinMode(2, OUTPUT);
    //pinMode(36, INPUT);
    if (!SD.begin())
        Serial.println("SD begin failed");

    while(!SD.begin()) {
        Serial.print(".");
        //delay(500);
        SD.remove(filename1);
        SD.remove(filename2);
    }
}

void loop() {
}

I got this error:

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

rst:0xc (SW_CPU_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:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10900
load:0x40080400,len:6388
entry 0x400806b4
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x400f095f  PS      : 0x00060030  A0      : 0x800d1019  A1      : 0x3ffb3f80
A2      : 0x00000000  A3      : 0x3ffb2080  A4      : 0x00000020  A5      : 0x80000020
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000005  A9      : 0x00000020
A10     : 0x00000020  A11     : 0x3ffbc0d0  A12     : 0x80087259  A13     : 0x3ffbc0d0
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x400f095f:0x3ffb3f80 0x400d1016:0x3ffb3fa0 0x40088269:0x3ffb3fe0

I tried decreasing the interrupt frequency, using a huge app (3 MB), increasing the CPU clock to 240 Hz, but nothing changed.

By outcommenting

vTaskNotifyGiveFromISR(complexHandlerTask, &xHigherPriorityTaskWoken);

and

xTaskCreate(complexHandler, "Handler Task", 8192, NULL, 1, &complexHandlerTask);

now the error is

Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)

And some register dumps of core 1 and core 0. There isn't any change doing something in the loop.

interrupt
esp32
arduino-ide
adc
asked on Stack Overflow Nov 8, 2020 by LEELA KRISHNA • edited Dec 10, 2020 by Peter Mortensen

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0