How to use the internal RTC on nRF52833 SoC to keep system time across reboots

Hello,

I need your help on how to use the internal RTC on nRF52833 SoC to keep the system time under zypher.

I need the RTC to keep its time after,

1- Reboots

2- Sleep using k_sleep( Duration ) 

3- System Off mode, although this use case may not be necessary but still interested if it is possible.

Finally, looking at the nRF52833 RTC registers I could not find a way of setting the time. Is there one?

Kind regards

Mohamed

Parents
  • Thank you.

    I would appreciate it a great deal if you could point me to an example showing how to the persistent registers.

    Also, what does the first line in red mean?

    This information applies to the following SoftDevices: S130, S132, S332

    Note, I am using,

    - nRF52833 SoC

    - SEGGER Embedded Studio for ARM
      Release 5.60  Build 2021081102.47262
      Nordic Edition
      Windows x64

    - Zephyr OS build v2.6.99-ncs1

    - NCS v1.7.0

    Kind regards

    Mohamed

  • Thank you.

    Are you advocating I use the CUSTOMER  area in the UICR to store the time?

    I did think about it but I think it is more of a hack. RTC would be a neater solution. Plus, correct me if I am wrong, I seem to recall that it is not possible for the application firmware to write to the UICR area. Am I right?

    I still would like to know why I cannot use the nRF52833 internal RTC?

    Kind regards

    Mohamed

  • You can only write once to the UICR registers and need to erase the whole UICR if you want any entirely different data to be stored in these registers. So I do not recommend writing to UICR if you need to update this over period of time. Best is to use Settings in Zephyr to write something to the reserved flash page before shutting the core and read from the stored value when waking up. You can still use the read value to add on top of the RTC value to get an essence of tracking the time from the start.

  • Hi Susheel,

    Thank you for the tips on using the UICR. 

    Let's go back a step to my original question. I wanted to use the RTC to keep system time and you came back with three different suggestions but you never explained why the RTC cannot be used in this use case. 

    1- Persistent registers

    Please answer my question on persistent registers above. Also, If you do a search for '?' you will find all my questions. Please answer them if you can. Thank you.

    2- UICR

    You can only write once to the UICR registers and need to erase the whole UICR if you want any entirely different data to be stored in these registers. So I do not recommend writing to UICR if you need to update this over period of time.

    So, UICR is out of the running.

    3- Settings

    Best is to use Settings in Zephyr to write something to the reserved flash page before shutting the core and read from the stored value when waking up. You can still use the read value to add on top of the RTC value to get an essence of tracking the time from the start.

    I will have a look at the 'Settings' route but before I do I would like to understand why I can't use the RTC on its own to keep system time?

    Thank you.

    Kind regards

    Mohamed

  • Learner said:
    Please answer my question on persistent registers above. Also, If you do a search for '?

    This is what I found when I found searched for "?"

    Finally, looking at the nRF52833 RTC registers I could not find a way of setting the time. Is there one?

    None of the RTC's peripheral on embedded devices I know tells you time but tell you number of ticks. The frequency of tick increment depends on your configuration on PRESCALER: For actual time you either need to rely on the higher level libraries or utilities from the RTOS.

    Learner said:
    So, UICR is out of the running.

    If you want to update it more than once, then yes, UICR is not a solution for you.

    Learner said:
    I will have a look at the 'Settings' route but before I do I would like to understand why I can't use the RTC on its own to keep system time?

    Using RTC on its own to keep system time is not an issue here. That is very simple and can be used directly by accessing RTC register and converting the ticks read into any time unit you want. But I assumed that your main issue is to keep track of time between reboots. That is the trickiest part and that is where you need to access persistent storage. 

    I think we are mixing up two of your requriements.

    1. Keeping track of time can be done very easily using Zephyr utitities or other kernel timing API. You do not need to access RTC registers directly for this.
    2. Retaining time between reboots. This needs special handling from your application to save the previous time before reboot persistently and accessing again after new reboot to restore older value. You cannot restore old value into RTC register but you need to have your own application memory (static variable) or similar to remember the old offsets of time before reboot.

     

  • did you try code what I have wrote?

    You can use RTC and save this time into NRF_UICR_Type anf after reset you will get actual time

Reply Children
  • Hi qwertynoon,

    Apologies for not responding to your question earlier. It got lost in the long trail of messages and missed it. Thank you for your suggestion. However, I think use of the UICR works only if you are writing to that location once and then read back from it. If, like in my use case, I need to store the time a multitude number of times then UICR is not a good option.

    Kind regards

    Mohamed

Related