Skip to content

NRF52832: time stops after 35 minutes (or am I going mad again?) #8155

@RobMeades

Description

@RobMeades

Description

On the NRF52832 platform time(NULL) produces the correct answer for 35 minutes and, afterwards, returns zero or, if set_time() has been called, the time it was set to, forever and never moves again. Here's a simple test program:

#include "mbed.h"

int main()
{
    int wakeUpCount = 0;
    time_t waitStartTime = time(NULL);
    time_t now;
    int x;

    printf("Starting up.\n");
    //set_time(1);
    //waitStartTime = time(NULL);
    
    while (1) {
        now = time(NULL);
        x = now - waitStartTime;

        wakeUpCount++;
        printf("%d: started wait at %d, time now %d, difference %d.\n",
               wakeUpCount, waitStartTime, now, x);
        waitStartTime = time(NULL);
        wait_ms(10000);
    }
}

mbed compile it and run it on an NRF52832 platform (I'm using a UBLOX_EVK_NINA_B1 module) and you'll see that time(NULL) reports 0 forever after the 215th iteration:

212: started wait at 2112, time now 2122, difference 10.
213: started wait at 2122, time now 2132, difference 10.
214: started wait at 2132, time now 2142, difference 10.
215: started wait at 2142, time now 0, difference -2142.
216: started wait at 0, time now 0, difference 0.
217: started wait at 0, time now 0, difference 0.
218: started wait at 0, time now 0, difference 0.

Uncomment the two commented lines and you'll see that time(NULL) reports 1 forever after the 215th iteration instead:

212: started wait at 2113, time now 2123, difference 10.
213: started wait at 2123, time now 2133, difference 10.
214: started wait at 2133, time now 2143, difference 10.
215: started wait at 2143, time now 1, difference -2142.
216: started wait at 1, time now 1, difference 0.
217: started wait at 1, time now 1, difference 0.
218: started wait at 1, time now 1, difference 0.

FYI, 35 minutes is suspiciously close to going half way around a 32-bit microsecond timer. C'mon guys, this is not on, I've just wasted several days looking for a bug in my code; time() has to work, it is a complete show-stopper for me if it doesn't, I need a fix/workaround quickly please!!!

Issue request type

[ ] Question
[ ] Enhancement
[x] Serious Bug
[ ] I'm going mad

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions