Page 1 of 1

Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Tue Jan 31, 2023 12:53 pm
by dr.modi
Hello everyone. I'm using the wiegand connection example from this repository.
I edited the "task" function so that initialization depends on the arguments passed.

Code: Select all

    wiegand_data_t data = *(wiegand_data_t *)arg;
    printf("D0 = %d, D1 = %d\n", data.d0, data.d1);
    // Initialize reader
    ESP_ERROR_CHECK(wiegand_reader_init(&reader, data.d0, data.d1, true, CONFIG_EXAMPLE_BUF_SIZE, reader_callback,
        WIEGAND_MSB_FIRST, WIEGAND_LSB_FIRST));
I added a structure of the following form, and pass it as an argument:

Code: Select all

typedef struct wiegand_t
{
    gpio_num_t d0, d1;
} wiegand_data_t;
Everything works fine when I create one task, but when I add a second one, I get a number of errors that I can't quite understand. By doing this:

Code: Select all

void app_main()
{
    xTaskCreate(task, TAG, configMINIMAL_STACK_SIZE * 4, &data1, 5, NULL);
    xTaskCreate(task, TAG_2, configMINIMAL_STACK_SIZE * 4, &data2, 5, NULL);
...I get the following errors:

Code: Select all

D (654) intr_alloc: Connected src 24 to int 9 (cpu 0)
I (659) cpu_start: Starting scheduler on PRO CPU.
D (0) intr_alloc: Connected src 25 to int 2 (cpu 1)
I (0) cpu_start: Starting scheduler on APP CPU.
D (684) heap_init: New heap initialised at 0x3ffe0440
D (684) heap_init: New heap initialised at 0x3ffe4350
D (694) intr_alloc: Connected src 16 to int 12 (cpu 0)
D0 = 16, D1 = 17
D0 = 5, D1 = 18
E (694) gpio: gpio_install_isr_service(465): GPIO isr service already installed
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400e658b  PS      : 0x00060c33  A0      : 0x800d647a  A1      : 0x3ffb7630
0x400e658b: esp_intr_get_cpu at C:/Work/Programs/Espressif/frameworks/esp-idf-v5.0/components/esp_hw_support/intr_alloc.c:771

A2      : 0x00000000  A3      : 0x3ffb293c  A4      : 0x00060c20  A5      : 0x00060c23  
A6      : 0x3f403b0c  A7      : 0x0000abab  A8      : 0x800d618c  A9      : 0x3ffb75f0
A10     : 0x00010000  A11     : 0x00000010  A12     : 0x00000000  A13     : 0x00060c23
A14     : 0x3ffb7610  A15     : 0x0000abab  SAR     : 0x00000010  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000
The documentation says:
The address which has been written/read is found in the EXCVADDR register in the register dump. If this address is zero, it usually means that the application has attempted to dereference a NULL pointer
But I can't figure out at what point this is happening. It seemed to me that the "GPIOisr service already installed" error shouldn't affect, but now I'm not sure...

Re: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Wed Feb 01, 2023 9:53 am
by dr.modi
I'll answer myself. I removed this line from the "task" function:

Code: Select all

printf ("Pin D0 = %d, pin D1 = %d\n", data.d0, data.d1);
...and the error disappeared, but now my code does not perform reading, as it did with one task. Apparently, the problem is how I organize tasks in FreeRTOS

Re: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Wed Feb 01, 2023 1:27 pm
by mbratch
Can you show the source for `task`? If it's not re-entrant, then it's a problem to call `xTaskCreate` twice with that same task.

Re: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Wed Feb 01, 2023 1:55 pm
by dr.modi
mbratch wrote:
Wed Feb 01, 2023 1:27 pm
Can you show the source for `task`?..

Yes, the code looks like this:

Code: Select all

static void task(void *arg)
{
    // Create queue
    queue = xQueueCreate(5, sizeof(data_packet_t));
    if (!queue)
    {
        ESP_LOGE(TAG, "Error creating queue");
        ESP_ERROR_CHECK(ESP_ERR_NO_MEM);
    }

    wiegand_data_t data = *(wiegand_data_t *)arg;
    // printf ("Pin D0 = %d, pin D1 = %d\n", data.d0, data.d1);
    // Initialize reader
    ESP_ERROR_CHECK(wiegand_reader_init(&reader, data.d0, data.d1, true, CONFIG_EXAMPLE_BUF_SIZE, reader_callback,
        WIEGAND_MSB_FIRST, WIEGAND_LSB_FIRST));

    data_packet_t p;
    while (1)
    {
        ESP_LOGI(TAG, "Waiting for Wiegand data...");
        xQueueReceive(queue, &p, portMAX_DELAY);

        // dump received data
        printf("==========================================\n");
        printf("Bits received: %d\n", p.bits);
        printf("Received data:");
        int bytes = p.bits / 8;
        int tail = p.bits % 8;
        for (size_t i = 0; i < bytes + (tail ? 1 : 0); i++)
            printf(" 0x%02x", p.data[i]);
        printf("\n==========================================\n");
    }
}
If I call "xTaskCreate" once, then I get the desired output when I bring the card to the reader:

Code: Select all

D (694) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (694) intr_alloc: Connected src 22 to int 3 (cpu 1)
D (704) wiegand: Reader initialized on D0=16, D1=17
I (704) wiegand: Waiting for Wiegand data...
D (17294) wiegand: Got 34 bits of data
D (17294) wiegand: Reader on D0=16, D1=17 disabled
RAW data: 0xdd 0xa0 0x12 0x21 0x40
==========================================
D (17294) wiegand: Reader on D0=16, D1=17 enabled
Bits received: 32
Received data: 0xbb 0x40 0x24 0x42
==========================================
I (17314) wiegand: Waiting for Wiegand data...
On a double call, I don't get any reaction:

Code: Select all

D (654) intr_alloc: Connected src 24 to int 9 (cpu 0)
I (659) cpu_start: Starting scheduler on PRO CPU.
D (0) intr_alloc: Connected src 25 to int 2 (cpu 1)
I (0) cpu_start: Starting scheduler on APP CPU.
D (684) heap_init: New heap initialised at 0x3ffe0440
D (684) heap_init: New heap initialised at 0x3ffe4350
D (694) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (694) intr_alloc: Connected src 22 to int 3 (cpu 1)
[0;31mE (694) gpio: gpio_install_isr_service(465): GPIO isr service already installed
D (704) wiegand: Reader initialized on D0=16, D1=17
D (714) wiegand: Reader initialized on D0=5, D1=18
I (714) wiegand: Waiting for Wiegand data...
I (724) wiegand: Waiting for Wiegand data...

Re: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Thu Feb 02, 2023 3:01 am
by mbratch
Your tasks calls `wiegand_reader_init`. If you create the task twice, it gets called twice with all the same arguments. Is that expected or desirable? And is that function re-entrant?

Re: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) when using two xTaskCreate

Posted: Tue Feb 07, 2023 10:28 am
by dr.modi
Thank you for your questions. And I apologize for not answering for so long. I decided to follow the path suggested by the developer of the library I use, so my case can be considered solved.
If someone is interested, I will leave a link to the solution specifically for my case