RTC example not working on GIGA

Hi! I'm trying to get the real time clock to work on my Giga. I have only found one example (original Arduino example):

#include "mbed.h"
#include <mbed_mktime.h>

constexpr unsigned long printInterval { 1000 };
unsigned long printNow {};

void setup() {
  Serial.begin(9600);
  RTCset();
}

void loop() {
      if (millis() > printNow) {
        Serial.print("System Clock:          ");
        Serial.println(getLocaltime());
        printNow = millis() + printInterval;
    }
}

void RTCset()  // Set cpu RTC
{    
  tm t;
            t.tm_sec = (0);       // 0-59
            t.tm_min = (52);        // 0-59
            t.tm_hour = (14);         // 0-23
            t.tm_mday = (18);   // 1-31
            t.tm_mon = (11);       // 0-11  "0" = Jan, -1 
            t.tm_year = ((22)+100);   // year since 1900,  current year + 100 + 1900 = correct year
            set_time(mktime(&t));       // set RTC clock                                 
}

String getLocaltime()
{
    char buffer[32];
    tm t;
    _rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT);
    strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
    return String(buffer);
}

and this leads to a crashing of the Mbed OS - notice that nothing is connected, I just wanted to try it before connecting a battery and other stuff... Double tapping it and loading a different script works fine... Can anyone provide some help?

Hi @henatu.

Does it crash immediately? I just tried running that program on my GIGA R1 WiFi board and it worked as expected for me; no crash.

Did you have "Main Core" selected from the Tools > Target core menu in Arduino IDE when you uploaded the sketch to your GIGA R1 WiFi board

1 Like

Thank you for the response. I tried a different GIGA and there it is working. So I guess that it was a faulty board.
Regarding your questions: Yes it is crashing immediately and the sketch is uploaded to the main core.

Thank you for taking the time to post an update! Unfortunate about the faulty board, but it is great progress to determine that the problem is specific to a certain board, rather than being something general caused by the sketch code.

Regards, Per