为什么 gmtime() 函数 returns NULL?

Why gmtime() function returns NULL?

我正在尝试使用 epoch 时间在 STM32L051T6 微控制器上设置 RTC 时间。下面是我的代码。

void Rtc_SetTime(uint32_t time_)
{
    struct tm* brokenTime;
    const time_t temp = 3600;

    brokenTime = gmtime(&temp);

    if (NULL == brokenTime)
    {
       printf("Error: Failed to convert time.\r\n");
    }
}

当我调用上面的函数时。它总是转到 if 语句并打印错误。我尝试将值 3600、1459841178 作为参数传递。全部失败。代码有什么问题?

我在这里找到了以下内容: http://support.raisonance.com/content/gmtime-and-localtime-broken-arm-gcc-lib

所以可能不会实现....

I think gmtime and localtime is broken in arm-gcc lib for STM32F10x.

I have try it in keil uVision and working fine there(localtime anyway, gmtime not implemented in keil). gmtime and localtime is searching for _sbrk when linking.

"sbrkr.c: (.text+0xc): undefined reference to `_sbrk'"

我使用了 localtime() 函数而不是 gmtime(),它很好地解决了我的问题。