Author Topic: Year 2038 on microcontrollers?  (Read 5151 times)

0 Members and 1 Guest are viewing this topic.

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Year 2038 on microcontrollers?
« 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?
 

Offline dimkasta

  • Regular Contributor
  • *
  • Posts: 185
  • Country: gr
Re: Year 2038 on microcontrollers?
« Reply #1 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
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Year 2038 on microcontrollers?
« Reply #2 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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4067
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Year 2038 on microcontrollers?
« Reply #3 on: May 30, 2017, 11:02:44 am »
Year 2106 to be precise.
Use int64_t, so does linux.
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Year 2038 on microcontrollers?
« Reply #4 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.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Year 2038 on microcontrollers?
« Reply #5 on: May 30, 2017, 11:27:39 am »
You'd have to read the RTC datasheets to see how long they can run.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Year 2038 on microcontrollers?
« Reply #6 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)
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8240
Re: Year 2038 on microcontrollers?
« Reply #7 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.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Year 2038 on microcontrollers?
« Reply #8 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)!
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4067
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Year 2038 on microcontrollers?
« Reply #9 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.
« Last Edit: May 30, 2017, 12:33:53 pm by Jeroen3 »
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Year 2038 on microcontrollers?
« Reply #10 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.
 

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7303
  • Country: nl
  • Current job: ATEX product design
Re: Year 2038 on microcontrollers?
« Reply #11 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.
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Year 2038 on microcontrollers?
« Reply #12 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:
 

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7303
  • Country: nl
  • Current job: ATEX product design
Re: Year 2038 on microcontrollers?
« Reply #13 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?
 

Offline Len

  • Frequent Contributor
  • **
  • Posts: 547
  • Country: ca
Re: Year 2038 on microcontrollers?
« Reply #14 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.
DIY Eurorack Synth: https://lenp.net/synth/
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26751
  • Country: nl
    • NCT Developments
Re: Year 2038 on microcontrollers?
« Reply #15 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
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Year 2038 on microcontrollers?
« Reply #16 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf