EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: technix on May 30, 2017, 10:27:43 am

Title: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 10:27:43 am
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?
Title: Re: Year 2038 on microcontrollers?
Post by: dimkasta on May 30, 2017, 10:42:20 am
Did you have a look at the usual suspects?
https://en.wikipedia.org/wiki/Year_2038_problem
Title: Re: Year 2038 on microcontrollers?
Post by: nctnico on May 30, 2017, 10:58:37 am
Use uint32_t instead of a 32 bit integer and the problem will be one of your grandchildren.
Title: Re: Year 2038 on microcontrollers?
Post by: Jeroen3 on May 30, 2017, 11:02:44 am
Year 2106 (https://en.wikipedia.org/wiki/Time_formatting_and_storage_bugs) to be precise.
Use int64_t, so does linux.
Title: Re: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 11:14:01 am
For my unternal code maybe I can
Code: [Select]
typedef uint32_t time_t;or
Code: [Select]
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.
Title: Re: Year 2038 on microcontrollers?
Post by: nctnico on May 30, 2017, 11:27:39 am
You'd have to read the RTC datasheets to see how long they can run.
Title: Re: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 11:53:19 am
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
Title: Re: Year 2038 on microcontrollers?
Post by: amyk on May 30, 2017, 12:01:40 pm
Use a later epoch. I have an "MP4" player whose RTC starts counting at 2007-01-01.
Title: Re: Year 2038 on microcontrollers?
Post by: nctnico on May 30, 2017, 12:06:48 pm
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
If 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)!
Title: Re: Year 2038 on microcontrollers?
Post by: Jeroen3 on May 30, 2017, 12:30:42 pm
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
That 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?

If 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)!
That might be true. But you have to promote it to int64 anyway when you're doing calculations.
Title: Re: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 12:42:18 pm
The C library is newlib which should be able to handle 64-bit time_t is I force it with
Code: [Select]
typedef int64_t time_t;in build time.
Title: Re: Year 2038 on microcontrollers?
Post by: tszaboo on May 30, 2017, 03:14:40 pm
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
If 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)!

No, 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.
Title: Re: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 03:34:40 pm
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
If 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)!

No, 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.
It would beme working on it - 24 now, 45 when the bug is triggered.  :scared: :scared: :scared: :scared: :scared:
Title: Re: Year 2038 on microcontrollers?
Post by: tszaboo on May 30, 2017, 03:39:59 pm
No, 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.
It would beme working on it - 24 now, 45 when the bug is triggered.  :scared: :scared: :scared: :scared: :scared:
At the same company?
Title: Re: Year 2038 on microcontrollers?
Post by: Len on May 30, 2017, 03:52:49 pm
No, 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.

If your job is to make a product that will still be working in 20 years, it is your problem.

If the product lifetime is less than that and it won't be supported in 20 years, you can ignore it.
Title: Re: Year 2038 on microcontrollers?
Post by: nctnico on May 30, 2017, 04:18:02 pm
So here is the first challenge: make the internal RTC of STM32F1 year 2038 ready. Reference chip is STM32F103CBT6. (small package, very cheap)
If 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)!
No, 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.
You 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
Title: Re: Year 2038 on microcontrollers?
Post by: technix on May 30, 2017, 11:38:53 pm
No, 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.
It would beme working on it - 24 now, 45 when the bug is triggered.  :scared: :scared: :scared: :scared: :scared:
At the same company?
Probably not, but I will have to pick up the mess.