Year 2038 on microcontrollers? - Page 1
Forum section: electronics / general

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 10:27:43 am
content: In my IoTv6 post someone mentioned the Year 2038 problem should be fixed alongside adding IPv6 capability to IoT systems. How do I investigate this?

author: dimkasta
author_rank: Regular Contributor
timestamp: May 30, 2017, 10:42:20 am
content: Did you have a look at the usual suspects?https://en.wikipedia.org/wiki/Year_2038_problem

author: nctnico
author_rank: Super Contributor
timestamp: May 30, 2017, 10:58:37 am
content: Use uint32_t instead of a 32 bit integer and the problem will be one of your grandchildren.

author: Jeroen3
author_rank: Super Contributor
timestamp: May 30, 2017, 11:02:44 am
content: Year 2106to be precise.Useint64_t, so does linux.

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 11:14:01 am
content: For my unternal code maybe I canCode:typedef uint32_t time_t;orCode:typedef int64_t time_t;but what about the RTC hardware? The RTC hardware on STM32F1 is a 32-bit counter. While RTC on STM32F4 is implemented using a calendar.

author: nctnico
author_rank: Super Contributor
timestamp: May 30, 2017, 11:27:39 am
content: You'd have to read the RTC datasheets to see how long they can run.

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 11:53:19 am
content: So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)

author: amyk
author_rank: Super Contributor
timestamp: May 30, 2017, 12:01:40 pm
content: Use a later epoch. I have an "MP4" player whose RTC starts counting at 2007-01-01.

author: nctnico
author_rank: Super Contributor
timestamp: May 30, 2017, 12:06:48 pm
content: Quote from: technix on May 30, 2017, 11:53:19 amIf it is a 32 bit counter then it is already 2038 ready. 2038 is only a problem if you use 31 bits (like in using an integer as a timestamp)!

author: Jeroen3
author_rank: Super Contributor
timestamp: May 30, 2017, 12:30:42 pm
content: Quote from: technix on May 30, 2017, 11:53:19 amThat is not a challenge. Just offset the timer.The challenge is converting the 64 bit unix timestamps beyond 2038-01-19T03:14:07 into human readable form.You C library can't do int64, right?Quote from: nctnico on May 30, 2017, 12:06:48 pmThat might be true. But you have to promote it to int64 anyway when you're doing calculations.

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 12:42:18 pm
content: The C library is newlib which should be able to handle 64-bit time_t is I force it withCode:typedef int64_t time_t;in build time.

author: tszaboo
author_rank: Super Contributor
timestamp: May 30, 2017, 03:14:40 pm
content: Quote from: nctnico on May 30, 2017, 12:06:48 pmNo, it is 20 years from now, so it is someone else's problem. While I probably dont die in 20 years, I certanly hope I will not be working here.

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 03:34:40 pm
content: Quote from: NANDBlog on May 30, 2017, 03:14:40 pmIt would beme working on it - 24 now, 45 when the bug is triggered.

author: tszaboo
author_rank: Super Contributor
timestamp: May 30, 2017, 03:39:59 pm
content: Quote from: technix on May 30, 2017, 03:34:40 pmAt the same company?

author: Len
author_rank: Frequent Contributor
timestamp: May 30, 2017, 03:52:49 pm
content: Quote from: NANDBlog on May 30, 2017, 03:14:40 pmIf your job is to make a product that will still be working in 20 years, itisyour problem.If the product lifetime is less than that and it won't be supported in 20 years, you can ignore it.

author: nctnico
author_rank: Super Contributor
timestamp: May 30, 2017, 04:18:02 pm
content: Quote from: NANDBlog on May 30, 2017, 03:14:40 pmYou are wrong. 2^32-1=4294967295 seconds. Divide that by 31557600 seconds in a year (with 365.25 days per year to account for a leap day every 4 years) and you get 136 years. 1970+136=2106

author: technix
author_rank: Super Contributor
timestamp: May 30, 2017, 11:38:53 pm
content: Quote from: NANDBlog on May 30, 2017, 03:39:59 pmProbably not, but I will have to pick up the mess.