Skip to content

delay() with small values (e.g. delay(5)) does not delay if system HZ (CONFIG_FREERTOS_HZ) <1000 #6946

Closed
@egnor

Description

@egnor

Board

OLIMEX ESP32-POE (but will happen anywhere I think)

Device Description

Stock OLIMEX ESP32-POE, but I believe this will happen on any board

Hardware Configuration

Nothing attached

Version

latest development Release Candidate (RC-X)

IDE Name

PlatformIO

Operating System

Ubuntu 22.04

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

The Arduino delay() function is implemented as follows:

vTaskDelay(ms / portTICK_PERIOD_MS);

If portTICK_PERIOD_MS > 1 (i.e. CONFIG_FREERTOS_HZ < 1000), then small values will round down to 0, and no delay will happen. I'm not super familiar with the delay facilities in FreeRTOS / ESP-IDF but there has to be some way to do a shorter delay (busy-wait, if nothing else)?

See also: platformio/platform-espressif32#846

Sketch

// Run me with CONFIG_FREERTOS_HZ=100 to see the problem

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.printf("BEFORE msec=%lu\n", millis());
  for (int i = 0; i < 20; ++i) delay(5);
  Serial.printf("AFTER msec=%lu\n\n", millis());
}

Debug Message

(none)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions