Get current time on RT1170-EVK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get current time on RT1170-EVK

Jump to solution
1,811 Views
D_TTSA
Contributor V

Good day

I would like to get the current time since the standard Epoch (00:00 01-01-1970) on my RT1170-EVK.

In other words, I want to have the functionality of the time() function from time.h on my board.

This function just returns zero, so I tried other avenues (like the SNVS_HP & SNVS_LP drivers), but nothing could give me the CURRENT time from the Real-Time Clock.

With the SNVS drivers, I can only set a time and calculate differences in time.

Kind regards

0 Kudos
1 Solution
1,810 Views
D_TTSA
Contributor V

For any other newbies with a similar question:

I realised the solution is to just set the time to the current time using the SNVS_HP/LP driver, as in the example evkmimxrt1170_snvs_lp_srtc_cm4.

As long as the processor is powered, this will give you the 'current' time.

Most final implementations have a small battery to power the LP registers to keep the RTC value ticking.

Kind regards

View solution in original post

0 Kudos
8 Replies
1,417 Views
Suijunqiang
Contributor II

@D_TTSA  your evkmimxrt1170_snvs_lp_srtc_cm4 example works well on my devices, but when I merge your code into my project get nothing 

"Current datetime: hd-hd-hd hd:hd:hd", I have checked my code several times, but still not sure the reason, so would please give some comments?
 
Thanks & Best Regards
Sui

 

0 Kudos
1,396 Views
D_TTSA
Contributor V

Hi @Suijunqiang 

I need more information to be able to help you.

  1. What do you mean by "merge your code into my project"? Did you import the correct drivers?
  2. What do you mean by "get nothing"? What values are printed?
  3. Do you want to hold the value when your device is switched off, and restore the clock value after a reboot? If not, please describe your desired functionality.
0 Kudos
1,380 Views
Suijunqiang
Contributor II

Hi, @D_TTSA 

Thanks for your comments, and my answer as below in green.

Thanks & Best Regards

Sui

 

Hi @Suijunqiang 

I need more information to be able to help you.

  1. What do you mean by "merge your code into my project"? Did you import the correct drivers?

       >>>I am using the example of "evkmimxrt1170_sd_jpeg_cm7" for the board of MIMXRT1170-EVK, and try to merge all your code as well as drivers(I try merge every thing), into the example.
By the way, the two projects work well independent.

  1. What do you mean by "get nothing"? What values are printed?

>>>when PRINTF("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
rtcDate.hour, rtcDate.minute, rtcDate.second);

we get "Current datetime: hd-hd-hd hd:hd:hd"

  1. Do you want to hold the value when your device is switched off, and restore the clock value after a reboot? If not, please describe your desired functionality.
    >>>No, at this moment we only need current time to verify how much time in different code operation;
0 Kudos
1,371 Views
D_TTSA
Contributor V

Hi @Suijunqiang 

Well, when you imported the code and drivers, did you remember to import the clock configuration settings too?

For example, I looked at the snvs_hp_rtc_cm7 SDK example, and it shows a dependence on kCLOCK_SnvsHp.

If this clock is not configured (with the correct settings) in your merged project, then this could cause your problem, I think.

Let me know,

D_TTSA

0 Kudos
1,360 Views
Suijunqiang
Contributor II

@D_TTSA 
How to set "kCLOCK_SnvsHp" dependence in my project?
I have merged all your MACROs in to my code, also I searched "kCLOCK_SnvsHp" in your code.

sui@CNSHA1JTS517LP:/mnt/c/Users/3502594/src/nxp/evkmimxrt1170_snvs_hp_rtc_cm7$ find . -type f | xargs grep -i "kCLOCK_SnvsHp"
Binary file ./Debug/evkmimxrt1170_snvs_hp_rtc_cm7.axf matches
Binary file ./Debug/source/snvs_hp_rtc.o matches
grep: ./evkmimxrt1170_snvs_hp_rtc_cm7: No such file or directory
grep: LinkServer: No such file or directory
grep: Debug.launch: No such file or directory
./source/snvs_hp_rtc.c:#define kCLOCK_SnvsHp0 kCLOCK_SnvsHp

0.png

0 Kudos
1,357 Views
D_TTSA
Contributor V

Hi @Suijunqiang 

I don't know why you are referring to the CM4 example as "my" code - it is NXP's code.

I have looked into it again, and yes, you are correct - it's rather strange that the SDK example defines this macro, but does not use it (and kCLOCK_SnvsHp is not defined, but it doesn't give an error?).

Anyway, since you have copied the source code and drivers across from the SDK example into your code, there are two potential causes of the difference between the example project and your project. They are:

  1. Project properties -> C/C++ General -> Paths and Symbols -> Symbols
  2. The configuration file (.mex) that defines the pinmux and clock routing

I see that the SDK examples do not have a .mex file by default. However, I think that it is most likely a pin problem, since, as mentioned above, the RTC does not seem to be dependent on a specific clock. 

Try to find all symbol, clock and pin differences between the two project. I'm quite certain that you will find your problem there.

D_TTSA

0 Kudos
1,347 Views
Suijunqiang
Contributor II

@D_TTSA 

ohaaaaaaaaa.....

Dear, D_TTSA,

It works fine now, the issue cause by the function of PRINTF formate .

 

Thanks & Best Regards

Sui

1,811 Views
D_TTSA
Contributor V

For any other newbies with a similar question:

I realised the solution is to just set the time to the current time using the SNVS_HP/LP driver, as in the example evkmimxrt1170_snvs_lp_srtc_cm4.

As long as the processor is powered, this will give you the 'current' time.

Most final implementations have a small battery to power the LP registers to keep the RTC value ticking.

Kind regards

0 Kudos