vTaskDelayUntil hangs

Dig Kleppe
Posts: 24
Joined: Wed Jun 28, 2017 5:03 pm

vTaskDelayUntil hangs

Postby Dig Kleppe » Sat Oct 21, 2017 10:47 am

With the latest esp-idf ( 14 oct downloaded from github) vTaskDelayUntil hangs.

Code: Select all

static void blink(void *pvParameters) {
	portTickType xLastWakeTime;
	const portTickType xPeriod = ( 500 / portTICK_RATE_MS );
	xLastWakeTime = xTaskGetTickCount();

	while (1) {
		vTaskDelayUntil( &xLastWakeTime, xPeriod );
		gpio_set_level(LED_BUILTIN, 1);
		vTaskDelayUntil( &xLastWakeTime, xPeriod );
		gpio_set_level(LED_BUILTIN, 0);
	}
}
vTaskDelayUntil has as advantage to vTaskDelay that the executiontime of the task code does not matter.

Dig

pataga
Posts: 73
Joined: Sat Aug 12, 2017 5:53 am

Re: vTaskDelayUntil hangs

Postby pataga » Sat Nov 18, 2017 5:41 am

I'm also having trouble with this function. I set the FreeRTOS tick rate to 250 in 'make menuconfig', and called vTaskDelayUntil with a period of 4mS. Resulted in a panic/reboot. vTaskDelay works, but it doesn't give me the uniform sampling period that i need.

This is with an esp-idf downloaded on Oct 27.

Code: Select all

void app_main() {
       // my code ...
	portTickType xLastWakeTime;
	const portTickType xPeriod = ( 4 / portTICK_RATE_MS );
	xLastWakeTime = xTaskGetTickCount();
	
	while (1) {
	           // my code ...
			vTaskDelayUntil( &xLastWakeTime, xPeriod );
			}
	}
I need to have a regular sampling period of 4mS for reading an IMU sensor. Is this the correct way to use the function, if so, is there any fix / workaround ?

Code: Select all

I (179) cpu_start: App cpu up.
I (200) heap_init: Initializing. RAM available for dynamic allocation:
I (206) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (212) heap_init: At 3FFB2908 len 0002D6F8 (181 KiB): DRAM
I (219) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (225) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (231) heap_init: At 400883CC len 00017C34 (95 KiB): IRAM
I (238) cpu_start: Pro cpu start user code
I (256) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (258) main: IMU-GPS logger compiled on Nov 18 2017 at 10:43:33
I (386) main: Winbond W25Q16BV ID [expected EF14] = EF14
I (398) max21100: device ID [expected B2] = B2
I (418) max21100: interrupt mask = 80
I (418) max21100: interrupt src sel = 20
Untested FreeRTOS function vTaskDelayUntil
D:/msys32/home/hari/esp-idf/components/freertos/tasks.c:1297 (vTaskDelayUntil)-
assert failed!
abort() was called at PC 0x40083c36 on core 0
0x40083c36: vTaskDelayUntil at D:/msys32/home/hari/esp-idf/components/freertos/t
asks.c:4482


Backtrace: 0x40086970:0x3ffb9120 0x40086a6f:0x3ffb9140 0x40083c36:0x3ffb9160 0x4
00d2077:0x3ffb9180 0x400d0843:0x3ffb91e0
0x40086970: invoke_abort at D:/msys32/home/hari/esp-idf/components/esp32/panic.c
:553

0x40086a6f: abort at D:/msys32/home/hari/esp-idf/components/esp32/panic.c:553

0x40083c36: vTaskDelayUntil at D:/msys32/home/hari/esp-idf/components/freertos/t
asks.c:4482

0x400d2077: app_main at D:/msys32/home/hari/imugpslogger/main/app_main.c:207

0x400d0843: main_task at D:/msys32/home/hari/esp-idf/components/esp32/cpu_start.
c:403


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

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: vTaskDelayUntil hangs

Postby Gfast2 » Sat Nov 18, 2017 10:50 am

;) Hi pataga,

I think you need to create a task and put your while loop in there. "main_app()" is not a task I believe.

Cheers

Gfast2

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: vTaskDelayUntil hangs

Postby ESP_Sprite » Sat Nov 18, 2017 1:12 pm

Actually, app_main does run in its own task; it's just one that gets created automatically, calls app_main and then deletes itself.

Pataga and/or Dig Kleppe: Can you make an issue on https://github.com/espressif/esp-idf/issues/ so we can track this problem?

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: vTaskDelayUntil hangs

Postby Gfast2 » Sat Nov 18, 2017 6:47 pm

Hi,

I did a quick demo to try out this issue, and created a gist for this.

I think I can not reproduce the issue (any more). My ESP-IDF commit is at: 7e8c2a9c00a6fb05cd5da306b62c4474a999b1a2

P.S.
I don't past the code here because my eye & hear need syntax highlighting desperately, which here a Feature still missing. 8-)
The following is the program log:

Code: Select all

MONITOR
--- 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)
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_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:5544
load:0x40078000,len:0
ho 12 tail 0 room 4
load:0x40078000,len:12524
entry 0x40078f7c
W (74) rtc_clk: Possibly invalid CONFIG_ESP32_XTAL_FREQ setting (40MHz). Detected 40 MHz.
I (39) boot: ESP-IDF v3.0-dev-1100-g80eb3b6d 2nd stage bootloader
I (39) boot: compile time 21:12:59
I (39) 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) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05a8c ( 23180) map
I (112) esp_image: segment 1: paddr=0x00015ab4 vaddr=0x3ffb0000 size=0x02134 (  8500) load
I (116) esp_image: segment 2: paddr=0x00017bf0 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _iram_start at /home/gfast2/esp/esp-idf/components/freertos/./xtensa_vectors.S:1685

I (122) esp_image: segment 3: paddr=0x00017ff8 vaddr=0x40080400 size=0x08018 ( 32792) load
I (144) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x100c4 ( 65732) map
0x400d0018: _stext at ??:?

I (167) esp_image: segment 5: paddr=0x000300e4 vaddr=0x40088418 size=0x00238 (   568) load
0x40088418: esp_rom_spiflash_read at /home/gfast2/esp/esp-idf/components/spi_flash/./spi_flash_rom_patch.c:544

I (168) esp_image: segment 6: paddr=0x00030324 vaddr=0x400c0000 size=0x00000 (     0) load
I (179) boot: Loaded app from partition at offset 0x10000
I (180) boot: Disabling RNG early entropy source...
I (186) cpu_start: Pro cpu up.
I (189) cpu_start: Starting app cpu, entry point is 0x40080df4
0x40080df4: call_start_cpu1 at /home/gfast2/esp/esp-idf/components/esp32/./cpu_start.c:222

I (0) cpu_start: App cpu up.
I (200) heap_init: Initializing. RAM available for dynamic allocation:
I (207) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (213) heap_init: At 3FFB2958 len 0002D6A8 (181 KiB): DRAM
I (219) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (225) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (232) heap_init: At 40088650 len 000179B0 (94 KiB): IRAM
I (238) cpu_start: Pro cpu start user code
I (256) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!
This is the second test.This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 0, 4MB external flash
Hi 0
Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
Hi 6
Hi 7
Hi 8
Hi 9
Hi 10
Hi 11
Hi 12
Hi 13
Hi 14
Hi 15
Hi 16
Hi 17
Hi 18
Hi 19
Hi 20
Hi 21
Hi 22
Hi 23
Hi 24
Hi 25

Cheers

Gfast2

pataga
Posts: 73
Joined: Sat Aug 12, 2017 5:53 am

Re: vTaskDelayUntil hangs

Postby pataga » Sun Nov 19, 2017 6:46 am

I built my code with the latest esp-idf (Nov 19) and the problem went away. Thanks Gfast2. Sorry for the false alarm.

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: vTaskDelayUntil hangs

Postby Gfast2 » Sun Nov 19, 2017 9:20 am

pataga wrote:I built my code with the latest esp-idf (Nov 19) and the problem went away. Thanks Gfast2. Sorry for the false alarm.
Hi ppataga,

cool! :P

Cheers

Gfast2

Dig Kleppe
Posts: 24
Joined: Wed Jun 28, 2017 5:03 pm

Re: vTaskDelayUntil hangs

Postby Dig Kleppe » Sun Nov 26, 2017 11:41 am

Hi
I can confirm that this is working now with the idf of nov 26
Thanks

Shalini
Posts: 3
Joined: Fri Dec 08, 2017 7:54 am

Re: vTaskDelayUntil hangs

Postby Shalini » Fri Dec 08, 2017 8:30 am

Hi,

I am facing issue with setting the loop time as 1ms.
I am using vtaskdelayUntil function. I have changed configTICK_RATE_HZ from 100 to 1000 to make the tick rate as 1000Hz. Also changed it on menuconfig. Still my task runs at 12ms loop.

Please help me understand the reason. And what can i do to make it 1ms periodic task.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: vTaskDelayUntil hangs

Postby ESP_Sprite » Sat Dec 09, 2017 3:59 am

Suggest you use the ESP32 hardware timers (ISR, perhaps combined with a task that gets unblocked in that ISR if you need to do complex stuff) for this kind of granularity; the FreeRTOS task system isn't really meant to do stuff like this, and setting the FreeRTOS tick to 1KHz will spend a lot of time in context switches.

Who is online

Users browsing this forum: Bing [Bot] and 110 guests