assert failed: xTaskDelayUntil tasks.c:1477 (( xTimeIncrement > 0U ))

msh911
Posts: 11
Joined: Wed May 10, 2023 5:21 am

assert failed: xTaskDelayUntil tasks.c:1477 (( xTimeIncrement > 0U ))

Postby msh911 » Thu Jun 15, 2023 4:05 am

Hi
I have a very generic cpp code in ESP IDF to be used for a multi rate task program on ESP32 S3.
The code has a base rate of 1 ms and rate1 of 10 ms.
The code builds with no error. However, the board keeps rebooting with the following error:
----------------------------------------------------------------------------------------------
assert failed: xTaskDelayUntil tasks.c:1477 (( xTimeIncrement > 0U ))


Backtrace: 0x40375c92:0x3fcee8f0 0x40379c2d:0x3fcee910 0x4037f0cd:0x3fcee930 0x4037bdde:0x3fceea50 0x42007ac3:0x3fceea70 0x4037c655:0x3fceeaa0
0x40375c92: panic_abort at C:/Espressif/frameworks/esp-idf-v5.0.1/components/esp_system/panic.c:423

0x40379c2d: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.0.1/components/esp_system/esp_system.c:153

0x4037f0cd: __assert_func at C:/Espressif/frameworks/esp-idf-v5.0.1/components/newlib/assert.c:78

0x4037bdde: xTaskDelayUntil at C:/Espressif/frameworks/esp-idf-v5.0.1/components/freertos/FreeRTOS-Kernel/tasks.c:1477 (discriminator 1)

0x42007ac3: tBaseRate(void*) at C:/Espressif/frameworks/esp-idf-v5.0.1/workspace/Test_TaskDelay/main/main.cpp:43

0x4037c655: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.0.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154





ELF file SHA256: f70501ea97913d03

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x403789f2
0x403789f2: esp_cpu_wait_for_intr at C:/Espressif/frameworks/esp-idf-v5.0.1/components/esp_hw_support/cpu.c:110
------------------------------------------------------------------------------------------------------------------------------------------


I also noticed if I change the base rate to 10 ms and rate1 also 10 ms, it runs with no issue. For some reason my board does not like 1 ms rate the way I have set up the tasking.
I know for a fact that this code has no issue even with 1 ms base rate if its flashed and built on the board properly. (I have a package that generates the same code code and flashes it into the board automatically ( I can not see the process of make and build) and the board works fine. So I am wondering if it is something about menuconfig or similar.

I really appreciate any help on this. Here is the full code:

Code: Select all

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/timers.h"

#ifndef STACK_SIZE
#define STACK_SIZE                     10240
#endif

TaskHandle_t FreeRTOSTIDs[2];
SemaphoreHandle_t rtTaskSemaphoreList[2];
void tRate1(void *pvParameters)
{
  while (1) {
    xSemaphoreTake(rtTaskSemaphoreList[1], portMAX_DELAY);

    /* Set model inputs associated to subrate here */

    /* Step the model for sample time for tid */


    /* Get model outputs here */

    /* Write model outputs associated to subrate here */
  }
}


void tBaseRate(void *pvParameters)
{
  const TickType_t vPeriodicTaskPreiod = 1/portTICK_PERIOD_MS;
  TickType_t xLastWakeTime;
  xLastWakeTime = xTaskGetTickCount();

  /* For debuging the base rate semaphore release. Ignore */
  static int taskCounter[2] = { 0, 0};

  int i;
  while (1) {
    /* Set model base rate here: */
    vTaskDelayUntil(&xLastWakeTime, vPeriodicTaskPreiod);
    for (i = 1; i < 2; i++) {
      if (taskCounter[i] == 0) {
        xSemaphoreGive(rtTaskSemaphoreList[i]);
      }
    }

    taskCounter[1]++;
    if (taskCounter[1] == 10) {
      taskCounter[1]= 0;
    }


    /* Set model inputs associated with base rate here */

    /* Step the model for base rate */


    /* Get model outputs here */
  }

  vSemaphoreDelete(rtTaskSemaphoreList[1]);
  vTaskDelete(FreeRTOSTIDs[1]);

  /* Disable rt_OneStep() here */

  /* Terminate model */

  /* Delete the base-rate task */
  vTaskDelete(FreeRTOSTIDs[0]);
}

extern "C" void app_main(void)
{
  /* Initialize model */


  /**
   * base_priority variable is used for assigning periodic task priority.
   * Note that, for periodic tasks, Priority property in Simulink blocks
   * has no effects on task execution order. Fastest rate blocks (smaller
   * block's sample time) always have higher priority.
   **/
  UBaseType_t BaseRateTaskPriority = 1;
  rtTaskSemaphoreList[1] = xSemaphoreCreateBinary();
  xTaskCreate(tRate1, "tRate1", STACK_SIZE, NULL, 0, &FreeRTOSTIDs[1]);
  xTaskCreate(tBaseRate, "tBaseRate", STACK_SIZE, NULL, BaseRateTaskPriority, &FreeRTOSTIDs[0]);
}




here

MicroController
Posts: 1709
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: assert failed: xTaskDelayUntil tasks.c:1477 (( xTimeIncrement > 0U ))

Postby MicroController » Thu Jun 15, 2023 4:12 pm

my board does not like 1 ms rate
In fact, it's FreeRTOS who doesn't "like" your time interval. Note that FreeRTOS, and its timers, operate on ticks.
With the default tick rate of 100Hz, 1 tick = 10ms = portTICK_PERIOD_MS. So const TickType_t vPeriodicTaskPreiod = 1/portTICK_PERIOD_MS; yields 0.

Solution: Use the High Resolution Timer (ESP timer) instead.

If you don't want to use the HR timer, you can alternatively change the FreeRTOS tick rate to 1000Hz via menuconfig. This is, however, likely to increase CPU load due to 10x more tick interrupts and potential task switching.

Who is online

Users browsing this forum: No registered users and 94 guests