Thread Priority C++

klaasdie
Posts: 2
Joined: Sun Feb 16, 2020 11:17 pm

Thread Priority C++

Postby klaasdie » Sun Feb 16, 2020 11:28 pm

Hi all,

I'm trying out using esp-idf with Cpp. Espcially I want to call a member function as threadCode. This is my testing code:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <esp_log.h>

extern "C" void start_HelloWorld(void* param);

class HelloWorld {
public:
    HelloWorld() : index(0) {
        ESP_LOGI("HW", "Constructed");
    }   

    void printHelloWorld() {
        printf("[%d] Hello world!\n", this->index);
        index++;
    }   

    void Run() {
        ESP_LOGI("HW", "RUN");
        while (true) {
            printHelloWorld();
            vTaskDelay(1000 / portTICK_PERIOD_MS);
        }   
    }   

private:
    int index;
};

extern "C" void app_main(void)
{
    TaskHandle_t taskHandle;
    
    xTaskCreate(start_HelloWorld, "HelloWorld", 1000, NULL, 5, &taskHandle);

    for(;;) {
        vTaskDelay(1000);
        printf("main");
    }   
}

void start_HelloWorld(void* param) {
    ESP_LOGI("HW", "start_HelloWorld called");
    HelloWorld hw; 
    hw.Run();
    ESP_LOGE("HW", "This point may never be reached");
}

Running this code gives me this:

Code: Select all

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:2
load:0x3fff0018,len:4
load:0x3fff001c,len:7060
load:0x40078000,len:14176
load:0x40080400,len:4480
entry 0x400806f0
I (72) boot: Chip Revision: 1
I (72) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF v4.1-dev-1086-g93a8603c5 2nd stage bootloader
I (39) boot: compile time 21:23:47
I (40) boot: Enabling RNG early entropy source...
I (46) boot: SPI Speed      : 40MHz
I (50) boot: SPI Mode       : DIO
I (54) boot: SPI Flash Size : 4MB
I (58) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (76) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (103) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05cec ( 23788) map
I (120) esp_image: segment 1: paddr=0x00015d14 vaddr=0x3ffb0000 size=0x020e8 (  8424) load
I (124) esp_image: segment 2: paddr=0x00017e04 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /opt/esp/idf/components/freertos/xtensa_vectors.S:1778

I (130) esp_image: segment 3: paddr=0x0001820c vaddr=0x40080400 size=0x07e0c ( 32268) load
I (152) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x1265c ( 75356) map
0x400d0020: _stext at ??:?

I (179) esp_image: segment 5: paddr=0x00032684 vaddr=0x4008820c size=0x0177c (  6012) load
0x4008820c: vTaskSwitchContext at /opt/esp/idf/components/freertos/tasks.c:2858 (discriminator 1)

I (188) boot: Loaded app from partition at offset 0x10000
I (189) boot: Disabling RNG early entropy source...
I (189) cpu_start: Pro cpu up.
I (193) cpu_start: Application information:
I (197) cpu_start: Project name:     app-template
I (203) cpu_start: App version:      7b946f2-dirty
I (208) cpu_start: Compile time:     Feb 16 2020 22:06:31
I (214) cpu_start: ELF file SHA256:  49f39f4ef0a5d15c...
I (220) cpu_start: ESP-IDF:          v4.1-dev-1086-g93a8603c5
I (227) cpu_start: Starting app cpu, entry point is 0x40080fdc
0x40080fdc: call_start_cpu1 at /opt/esp/idf/components/esp32/cpu_start.c:276

I (214) cpu_start: App cpu up.
I (237) heap_init: Initializing. RAM available for dynamic allocation:
I (244) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (250) heap_init: At 3FFB30E8 len 0002CF18 (179 KiB): DRAM
I (257) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (263) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (269) heap_init: At 40089988 len 00016678 (89 KiB): IRAM
I (276) cpu_start: Pro cpu start user code
I (294) spi_flash: detected chip: generic
I (294) spi_flash: flash io: dio
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (0) HW: start_HelloWorld called
I (0Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x40088ba0  PS      : 0x00060033  A0      : 0x800870c6  A1      : 0x3ffb0640
0x40088ba0: xTaskIncrementTick at /opt/esp/idf/components/freertos/tasks.c:2532

A2      : 0x00000000  A3      : 0x00000002  A4      : 0x3ffb10b4  A5      : 0x00000001
A6      : 0x00060020  A7      : 0x00000000  A8      : 0x80088aff  A9      : 0x3ffb0620
A10     : 0x00000001  A11     : 0x00000000  A12     : 0x00060720  A13     : 0x00000001
A14     : 0x00060720  A15     : 0x3ffb3ef8  SAR     : 0x00000011  EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000a  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000
Core 0 was running in ISR context:
EPC1    : 0x40088ba0  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x00000000
0x40088ba0: xTaskIncrementTick at /opt/esp/idf/components/freertos/tasks.c:2532


ELF file SHA256: 49f39f4ef0a5d15c23532a56544b2e4a0d17c91fea84c3f845a486b37316599f

Backtrace: 0x40088b9d:0x3ffb0640 0x400870c3:0x3ffb0660 0x400872b9:0x3ffb0680 0x4008249e:0x3ffb0690 0x400e266b:0x3ffb56b0 0x400d1caf:0x3ffb56d0 0x40088ac6:0x3ffb56f0 0x40086ff1:0x3ffb5710
0x40088b9d: xTaskIncrementTick at /opt/esp/idf/components/freertos/tasks.c:2531

0x400870c3: xPortSysTickHandler at /opt/esp/idf/components/freertos/port.c:289

0x400872b9: _frxt_timer_int at /opt/esp/idf/components/freertos/portasm.S:303

0x4008249e: _xt_lowint1 at /opt/esp/idf/components/freertos/xtensa_vectors.S:1153

0x400e266b: esp_pm_impl_waiti at /opt/esp/idf/components/esp32/pm_esp32.c:484

0x400d1caf: esp_vApplicationIdleHook at /opt/esp/idf/components/esp_common/src/freertos_hooks.c:63

0x40088ac6: prvIdleTask at /opt/esp/idf/components/freertos/tasks.c:3381 (discriminator 1)

0x40086ff1: vPortTaskWrapper at /opt/esp/idf/components/freertos/port.c:143


Rebooting...
I found out that this is corresponding with the task priority. Setting the priority to '0' runs like this:

Code: Select all

e
Executing "/opt/esp/python_env/idf4.1_py3.6_env/bin/python /opt/esp/idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- /project/AlarmNode/build/app-template.elf -m '/opt/esp/python_env/idf4.1_py3.6_env/bin/python' '/opt/esp/idf/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_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:2
load:0x3fff0018,len:4
load:0x3fff001c,len:7060
load:0x40078000,len:14176
load:0x40080400,len:4480
entry 0x400806f0
I (72) boot: Chip Revision: 1
I (72) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF v4.1-dev-1086-g93a8603c5 2nd stage bootloader
I (39) boot: compile time 21:23:47
I (40) boot: Enabling RNG early entropy source...
I (46) boot: SPI Speed      : 40MHz
I (50) boot: SPI Mode       : DIO
I (54) boot: SPI Flash Size : 4MB
I (58) boot: Partition Table:
I (61) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (76) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05cec ( 23788) map
I (120) esp_image: segment 1: paddr=0x00015d14 vaddr=0x3ffb0000 size=0x020e8 (  8424) load
I (124) esp_image: segment 2: paddr=0x00017e04 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /opt/esp/idf/components/freertos/xtensa_vectors.S:1778

I (130) esp_image: segment 3: paddr=0x0001820c vaddr=0x40080400 size=0x07e0c ( 32268) load
I (152) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x1265c ( 75356) map
0x400d0020: _stext at ??:?

I (179) esp_image: segment 5: paddr=0x00032684 vaddr=0x4008820c size=0x0177c (  6012) load
0x4008820c: vTaskSwitchContext at /opt/esp/idf/components/freertos/tasks.c:2858 (discriminator 1)

I (188) boot: Loaded app from partition at offset 0x10000
I (188) boot: Disabling RNG early entropy source...
I (189) cpu_start: Pro cpu up.
I (192) cpu_start: Application information:
I (197) cpu_start: Project name:     app-template
I (202) cpu_start: App version:      7b946f2-dirty
I (208) cpu_start: Compile time:     Feb 16 2020 22:06:31
I (214) cpu_start: ELF file SHA256:  834ae41d5889dddc...
I (220) cpu_start: ESP-IDF:          v4.1-dev-1086-g93a8603c5
I (226) cpu_start: Starting app cpu, entry point is 0x40080fdc
0x40080fdc: call_start_cpu1 at /opt/esp/idf/components/esp32/cpu_start.c:276

I (0) cpu_start: App cpu up.
I (237) heap_init: Initializing. RAM available for dynamic allocation:
I (244) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (250) heap_init: At 3FFB30E8 len 0002CF18 (179 KiB): DRAM
I (256) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (262) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (269) heap_init: At 40089988 len 00016678 (89 KiB): IRAM
I (275) cpu_start: Pro cpu start user code
I (293) spi_flash: detected chip: generic
I (294) spi_flash: flash io: dio
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (317) HW: start_HelloWorld called
I (317) HW: Constructed
I (317) HW: RUN
[0] Hello world!
[1] Hello world!
[2] Hello world!
[3] Hello world!
[4] Hello world!
E (5307) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (5307) task_wdt:  -  (CPU 0)
E (5307) task_wdt: Tasks currently running:
E (5307) task_wdt: CPU 0: IDLE0
E (5307) task_wdt: CPU 1: IDLE1
[5] Hello world!
[6] Hello world!
[7] Hello world!
[8] Hello world!
Can somebody please help me out. Why is this not working with a high priority? Why to I get the 'watchdog not triggered' error?
I know that there are better ways to embed the Object into the thread, but this should be my next step...

Thanks
Klaas

username
Posts: 156
Joined: Thu May 03, 2018 1:18 pm

Re: Thread Priority C++

Postby username » Mon Feb 17, 2020 4:13 am

My guess is that you did not allocate enough for that thread.
try
xTaskCreate(start_HelloWorld, "HelloWorld", 2048, NULL, 5, &taskHandle);

klaasdie
Posts: 2
Joined: Sun Feb 16, 2020 11:17 pm

Re: Thread Priority C++

Postby klaasdie » Mon Feb 17, 2020 7:37 pm

Hi, yes this solved it! Thanks a lot!

Who is online

Users browsing this forum: No registered users and 59 guests