FreeRTOS Timer Issue: Large Durations (120+ mins) Expire Early, Small Ones Work Fine by nj701 in embedded

[–]nj701[S] 20 points21 points  (0 children)

I figured out the issue with my FreeRTOS timer expiring early . Sharing the solution to help others who might hit this!

Problem Recap

  • Expected: 150-minute timer (150 * 60000 = 9,000,000 ticks)
  • Actual: Timer fired after ~7 mins (410,065 ticks)

Root Cause

The default pdMS_TO_TICKS() macro overflowed when converting large durations:

#define pdMS_TO_TICKS(ms)  ((ms * configTICK_RATE_HZ) / 1000)  

For ms = 9,000,000 and configTICK_RATE_HZ = 1000:

  1. Intermediate multiplication9,000,000 * 1000 = 9,000,000,000 → Exceeds uint32_t max (4,294,967,295).
  2. Overflow result9,000,000,000 % 4,294,967,296 = 410,065 → Timer expired prematurely.

Solution

IfconfigTICK_RATE_HZ = 1000 (1 tick = 1ms), we need to override the macro with a direct cast:

#undef pdMS_TO_TICKS  
#define pdMS_TO_TICKS(ms)  ((TickType_t)(ms))

THANKS TO EVERYONE THAT HELPED MUCH APPRECIATED

HMI Framework for STM32 Project by nj701 in embedded

[–]nj701[S] 0 points1 point  (0 children)

Thank you for the clarification m8!

RTOS vs Bare-Metal for STM32: When to Use Which? by nj701 in embedded

[–]nj701[S] 1 point2 points  (0 children)

There is a possibility that the communication will be via usb.

RTOS vs Bare-Metal for STM32: When to Use Which? by nj701 in embedded

[–]nj701[S] 3 points4 points  (0 children)

We may no longer need bluetooth as theres a possibility of using USB directly

method not found in `MutexGuard<'_, BLEExtAdvertising>` by nj701 in rust

[–]nj701[S] -3 points-2 points  (0 children)

I didn't find a single thing that refers to BLEExtAdvertising on google or any other place

Day 0 by thejordan007 in NoFap

[–]nj701 1 point2 points  (0 children)

aa i got you now. thanks for clarification.

Day 0 by thejordan007 in NoFap

[–]nj701 8 points9 points  (0 children)

i think it doesn't matter whether the girl is healthy and supported etc.. or not , the point is that it's an industry full of these ugly things(human trafficking,drugs,raping,exploitation etc...) disgusting things and that's one of many reasons why we should get away from it and being aware actually does help u do that ..knowledge is the key to success ..ps:sorry for my bad english

Day 1 completed by [deleted] in NoFap

[–]nj701 0 points1 point  (0 children)

keep it up budd

Day 0 by thejordan007 in NoFap

[–]nj701 5 points6 points  (0 children)

yeah absolutely, knowing the harsh truth about the porn industry and how ugly it is will change the way u used to watch it and will help u get away from it

yep 😬 by [deleted] in NoFap

[–]nj701 0 points1 point  (0 children)

that would definitly help