Skip to content

[bug] FreeRTOS configTICK_RATE_HZ being set to 1024 causes portTICK_PERIOD_MS to be 0 #114

Open
@Elizafox

Description

@Elizafox

Hardware

Arduino Nano Matter

Core version

2.2.0

Arduino IDE version

2.3.4

Operating system

macOS 15.1.1

Radio stack variant

Matter

OpenThread Border Router device (if using Matter)

No response

Issue description

configTICK_RATE_HZ is set by default in the config to 1024. This causes causes portTICK_PERIOD_MS to be 0.

portTICK_PERIOD_MS is defined as follows:

#define portTICK_PERIOD_MS    ( ( TickType_t ) 1000 / configTICK_RATE_HZ )

Using floor division, as is the default in C++, 1000 / 1024 = 0.

This breaks a lot of common FreeRTOS code that uses vTaskDelay and such.

Some boards provide a pdTICKS_TO_MS. This could also be a provided macro and encouraged. It's usually defined as:

#define pdTICKS_TO_MS( xTimeInTicks )    ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInTicks ) * ( uint64_t ) 1000U ) / ( uint64_t ) configTICK_RATE_HZ ) )

Serial output

14:09:15.232 -> configTICK_RATE_HZ: 1024
14:09:15.232 -> 
14:09:15.232 -> portTICK_PERIOD_MS: 0

RTT output (if using Matter)

No response

Minimal reproducer code

void setup() {
  Serial.begin(115200);
  while(!Serial);
  Serial.print("configTICK_RATE_HZ: ");
  Serial.println(configTICK_RATE_HZ);
  Serial.println();
  Serial.print("portTICK_PERIOD_MS: ");
  Serial.println(portTICK_PERIOD_MS);
}

void loop() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions