xCreateTask : Core 0 panic'ed (LoadProhibited) on SP32.

azz-zza wrote on Friday, September 13, 2019:

Hello,
the “blinky” works, until i try to implement it using tasks. BTW i’m running esp32doit-devkit-v1 with espressif32 framework.


#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "driver/gpio.h"
#include "nvs_flash.h"

#define BLINK_GPIO GPIO_NUM_2

portTickType c_1000ms = 1000 / portTICK_RATE_MS;

extern "C"
{
    void app_main(void);
}

void blinky(void *pvParameter)
{
    gpio_pad_select_gpio(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while (1)
    {
        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(c_1000ms * 2);

        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(c_1000ms);
    }
    vTaskDelete(NULL);
}

void app_main(void)
{
    vTaskDelay(c_1000ms * 2);
    printf("Hello world!\n");

    esp_err_t ret = nvs_flash_init();

    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    TaskHandle_t xHandle = NULL;
    BaseType_t xReturned;
    if (xReturned != pdPASS)
    {
        printf("Error in TaskCreate");
        esp_restart();
    }
    vTaskStartScheduler();
}

the output is :

␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
Hello world!
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x400d1b1f  PS      : 0x00060430  A0      : 0x800d1227  A1      : 0x3ffb1b00  
A2      : 0xa5a5a5a5  A3      : 0x000000ff  A4      : 0x00000042  A5      : 0x00000000  
A6      : 0x3ffb1c70  A7      : 0x3ffb1c50  A8      : 0x0000007e  A9      : 0xfffffffa  
A10     : 0x00000001  A11     : 0xffffff01  A12     : 0xffffff43  A13     : 0x00000000  
A14     : 0x00000000  A15     : 0x3ffb1bf0  SAR     : 0x00000006  EXCCAUSE: 0x0000001c  
EXCVADDR: 0xa5a5a5b1  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  

Backtrace: 0x400d1b1f:0x3ffb1b00 0x400d1224:0x3ffb1b60 0x400d14ad:0x3ffb1cb0 0x400d10c0:0x3ffb56e8

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee

i’ve been looking in FREERTOS guide and in “Internet of Things with SP32” example… clearly missing something essential.
Thank you.

rtel wrote on Friday, September 13, 2019:

app_main() looks very suspicious. You cannot call vTaskDelay() until the scheduler is running, but you don’t start the scheduler until later in the function. However the output does not seem to show it crashing there so maybe the scheduler is already running at that point (I’m not familiar with this dev environment)? If the scheduler is running then don’t call vTaskStartScheduler() again and be careful not to return from the task. What happens if you replace the call to vTaskStartScheduler() with a call to vTaskDelete( NULL)?

azz-zza wrote on Friday, September 13, 2019:

vTaskStartScheduler();
is not needed.
resolved …

azz-zza wrote on Friday, September 13, 2019:

Richard,
didn’t see your reply .
If i just replace the vTaskStartScheduler() with a call to vTaskDelete( NULL) - it happily blinks and prints onto the console.

Another obesrvation is in the hello_task and is dealing with printing “p” ( the parameter passed to the xTaskCreate):
`
void hello_task(void pvParameter)
{
char p;
p = (
(char *)pvParameter);
const char *pcTaskName = “Task 1 is running\r\n”;

for(;;)
{
    
    printf(pcTaskName);
    // printf("Task : %c : counting .. .  \n", p);
    vTaskDelay(1000 / portTICK_RATE_MS);
}
vTaskDelete(NULL);

}
`

if i un=comment the
printf(“Task : %c : counting … . \n”, p);
ill get the kernel panic. Eventhough the compiler has no warnings.