i am new to the ESP32 and I am using the espressif Framework (not Arduino) with Eclipse. I try to write code, so Task1 and Task2 synchronize each other with xTaskNotifyGive.
I dont know why, but my ESP32 keeps crashing. The Code is from an example of the official FreeRTOS site:
https://www.freertos.org/xTaskNotifyGive.html
This is my Code:
Code: Select all
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_attr.h"
#include "esp_deep_sleep.h"
#include "nvs_flash.h"
#include <cJSON.h>
#include "lwip/err.h"
#include "apps/sntp/sntp.h"
#include <curl/curl.h>
/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t wifi_event_group;
/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
to the AP with an IP? */
const int CONNECTED_BIT = BIT0;
static const char *TAG = "example";
/* Variable holding number of times ESP32 restarted since first boot.
* It is placed into RTC memory using RTC_DATA_ATTR and
* maintains its value when ESP32 wakes from deep sleep.
*/
RTC_DATA_ATTR static int boot_count = 0;
static void prvTask1( void *pvParameters );
static void prvTask2( void *pvParameters );
static TaskHandle_t xTask1 = NULL, xTask2 = NULL;
static void prvTask1( void *pvParameters )
{
for( ;; )
{
/* Send a notification to prvTask2(), bringing it out of the Blocked
state. */
ESP_LOGI(TAG, "I am Task1, I notify Task2");
xTaskNotifyGive( xTask2 );
/* Block to wait for prvTask2() to notify this task. */
ESP_LOGI(TAG, "I am Task2 and I wait for the notification of Task1");
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
}
}
/*-----------------------------------------------------------*/
static void prvTask2( void *pvParameters )
{
for( ;; )
{
/* Block to wait for prvTask1() to notify this task. */
ESP_LOGI(TAG, "I am Task2 and I wait for the notification of Task1");
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
/* Send a notification to prvTask1(), bringing it out of the Blocked
state. */
ESP_LOGI(TAG, "I am Task2, I notify Task1");
xTaskNotifyGive( xTask1 );
}
}
void app_main(){
if (boot_count == 0){
//-----------------Boot-------------------------
ESP_LOGI(TAG, "COLD START!");
ESP_LOGI(TAG, "Boot count: %d", boot_count);
boot_count++;
//-----------------Task_Creation----------------
xTaskCreate( prvTask1, "Task1", 200, NULL, tskIDLE_PRIORITY, &xTask1 );
xTaskCreate( prvTask2, "Task2", 200, NULL, tskIDLE_PRIORITY, &xTask2 );
vTaskStartScheduler();
//-----------------Deep_Sleep------------------
/*
const int deep_sleep_sec = 5;
ESP_LOGI(TAG, "Entering deep sleep for %d seconds", deep_sleep_sec);
esp_deep_sleep(1000000LL * deep_sleep_sec);
*/
}
//nach Sleep
if(boot_count >= 1){
ESP_LOGI(TAG, "I am awake after Deep_SLEEP!");
}
}
The Error i get is the following: Guru Meditation Error of type InstrFetchProhibited occurred on core 0. Exception was unhandled.
Code: Select all
Rebooting...
ets Jun 8 2016 00:22:57
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:0x3fff0010,len:4
load:0x3fff0014,len:5096
load:0x40078000,len:0
ho 12 tail 0 room 4
load:0x40078000,len:12664
entry 0x40078f50
I (34) boot: ESP-IDF v3.0-dev-203-gdce7fcb9-dirty 2nd stage bootloader
I (34) boot: compile time 14:29:56
I (139) boot: Enabling RNG early entropy source...
I (140) boot: SPI Speed : 80MHz
I (140) boot: SPI Mode : DIO
I (169) boot: SPI Flash Size : 4MB
I (207) boot: Partition Table:
I (241) boot: ## Label Usage Type ST Offset Length
I (309) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (379) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (449) boot: 2 factory factory app 00 00 00010000 00100000
I (519) boot: End of partition table
I (558) boot: Disabling RNG early entropy source...
I (609) boot: Loading app partition at offset 00010000
I (663) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x076dc ( 30428) map
I (783) esp_image: segment 1: paddr=0x00017704 vaddr=0x3ffb0000 size=0x02d88 ( 11656) load
I (843) esp_image: segment 2: paddr=0x0001a494 vaddr=0x40080000 size=0x00400 ( 1024) load
0x40080000: _iram_start at ??:?
I (911) esp_image: segment 3: paddr=0x0001a89c vaddr=0x40080400 size=0x05774 ( 22388) load
I (1025) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x26108 (155912) map
0x400d0018: _flash_cache_start at ??:?
I (1271) esp_image: segment 5: paddr=0x00046128 vaddr=0x40085b74 size=0x0d19c ( 53660) load
0x40085b74: prvProcessReceivedCommands at /Users/serhat/esp/esp-idf/components/freertos/./timers.c:660
I (1351) esp_image: segment 6: paddr=0x000532cc vaddr=0x400c0000 size=0x00000 ( 0) load
I (1352) esp_image: segment 7: paddr=0x000532d4 vaddr=0x50000000 size=0x00004 ( 4) load
I (1452) cpu_start: Pro cpu up.
I (1453) cpu_start: Starting app cpu, entry point is 0x40080e00
0x40080e00: call_start_cpu1 at /Users/serhat/esp/esp-idf/components/esp32/./cpu_start.c:192
I (1514) cpu_start: App cpu up.
I (1552) heap_init: Initializing. RAM available for dynamic allocation:
I (1616) heap_init: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM
I (1673) heap_init: At 3FFB66C8 len 00029938 (166 KiB): DRAM
I (1732) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (1791) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1851) heap_init: At 40092D10 len 0000D2F0 (52 KiB): IRAM
I (1909) cpu_start: Pro cpu start user code
I (2065) cpu_start: Starting scheduler on PRO CPU.
I (2068) cpu_start: Starting scheduler on APP CPU.
I (2068) example: COLD START!
I (2068) example: Boot count: 0
Guru Meditation Error of type InstrFetchProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 0x800e3a38 PS : 0x00050033 A0 : 0x800e3a38 A1 : 0x3ffb75c0
A2 : 0x3ffb4e64 A3 : 0x3f404f7c A4 : 0x50000000 A5 : 0x3ffb7610
A6 : 0x3ffb75f0 A7 : 0x0000000c A8 : 0x00000000 A9 : 0x800d07aa
A10 : 0x3ffb7630 A11 : 0x7fffffff A12 : 0x50000000 A13 : 0x00000001
A14 : 0x3ffb5230 A15 : 0x00000000 SAR : 0x00000000 EXCCAUSE: 0x00000014
EXCVADDR: 0x800e3a38 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x400e3a38:0x3ffb75c0 0x400e3a35:0x3ffb75f0
0x400e3a38: app_main at /Users/serhat/esp/esp-idf/examples/get-started/hello_world/main/./hello_world_main.c:107
0x400e3a35: app_main at /Users/serhat/esp/esp-idf/examples/get-started/hello_world/main/./hello_world_main.c:96 (discriminator 1)
Rebooting...