Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Elizafox opened this issue Feb 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Elizafox
Copy link

Elizafox commented Feb 8, 2025

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() {}
@Elizafox Elizafox added the bug Something isn't working label Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant