This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652R7: set RTC value

Part Number: CC2652R7

Tool/software:

I am currently working on my own project with BLE. My project is mostly a "multi-role" example from the SDK. But I am using FreeRTOS, not TI-rtos.
Everything works fine now.
My problem is that I want to change the values ​​of the SEC register in the RTC register during program execution.
But I can't do it correctly, because something changes the CH0COMP register in the RTC after I wrote to the SEC register. I don't understand the logic of the changes. At the same time, the device almost always does not go on air after this. But if I successfully maintain the SEC register, a more or less correct value is written to the CH0CMP register and I see the device on air.
When the device is on air, I see that the TimerP_SetThreeshold function is constantly called and the CH0COMP register is updated. If I set my own value in AON_RTC SEC, it may not be called anymore.
Most likely, this is due to the osal system and the osal_run_system function. I am sure that BLE somehow uses the RTC module for its purposes. But there is no exact understanding yet. Please help me how to update the RTC SEC register correctly. What other functions and where should I call so that the RF part continues to work correctly?

P.S. I have already asked a similar question, but I did not find an answer. I was advised to study the documentation, but there is nothing there that can help me. I was told that these registers are controlled by TI-RTOS and the user should not touch it, but I need to. I am sure that it is possible to somehow forcibly update the RTC registers correctly, or I need to find proof that this is impossible.
Thanks for any help.

  • Hi,

    Thank you for reaching out. I apologize that you were unable to resolve your question in the previous thread. Based on your description, my guess is that the BLE5-Stack is levering the RTC peripheral and modifying it unexpectedly may be causing unintended behavior. Taking a step back, could you describe what you are attempting to implement on your side? It may be possible to do it using the clock drivers or timer drivers which leverage the RTC in the backend.

    Best Regards,

    Jan

  • As I understand it, the RTC module does not save its value after power is turned off, so when it is turned on, it starts counting from 0. When starting the entire system, I want to change the value of the SEC register so that it points to my current real time in UNIX. Therefore, I am trying to write the required value to this register.

  • Hi Nick,

    Got it. Thank you for the explanation. Can you share how you are trying to perform the register write? A code snippet would be helpful. I can use it to discuss with R&D how we should try to modify this register during runtime properly.

    Best Regards,

    Jan

  • It happens as simply as possible
    I have a task with the RF part that broadcasts the device (GapAdvEnable) and there is a task for the console (shell), through which commands entered from the keyboard are processed. When I enter the time change command, the second task simply calls writing directly to the RTC register.

    HWREG(AON_RTC_BASE + AON_RTC_O_SEC) = sec; 

    I have tried to perform various combinations of code invocation

    for example, like this

    AONRTCDisable();
    HWREG(AON_RTC_BASE + AON_RTC_O_SEC) = sec;
    AONRTCEnable();

    HWREG(AON_RTC_BASE + AON_RTC_O_SEC) = sec;
    HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP) = ((sec+5)&0xFFFF)<<16;

    I tried to call one of these functions from osal after changing RTC_SEC, since obviously something from the rf part changes the CH0CMP registers, but I don't understand the logic yet and how to do it correctly

    osalAdjustTimer(1);
    osalTimeUpdate();
    osalTimerUpdate( sec +1 );
    osal_timer_refTimeUpdate();
    osal_next_timeout();                
    TimerP_dynamicStub(0);

  • One of the reasons why I need RTC is that I need a mechanism that will count time even in deep sleep mode of the device. Judging by TRM it can only be RTC, that GPTimer will also sleep in this mode and will not work. I read that as an alternative you can use utc_block.c file, but the point is that inside there is just some offset stored in a static variable, which is added to the current RTC value and we get the correct current time. This would be a normal solution, but I am not happy with the clock cycles spent on math operations when calculating time. That's why I want to use RTC register change so much, because reading this register takes quite a long time. Anyway, it seems to me that I can change RTC time at the beginning of my code, and after that initialize the RF part and start FreeRTOS. Ideally, I would like to understand how I can reliably change the RTC with the RF part active (even if it is ugly and bad) In the average case, if I believe that without the RF part working I can safely change the RTC registers, I need to understand how I can completely stop the RF task and after changing it, start it again from the beginning. In the worst case, I need hard facts that when working with the RF part active I am not allowed to touch the RTC register in any way
    Отправить отзыв
    Есть результаты с переводом 
  • Hi,

    Got it. Thank you for the additional details. I have reached out to R&D and I hope to hear back from them early next week. Have you had a chance to test the alternative mention you are mentioning and verified it works?

    Best Regards,

    Jan

  • Hi

    I tried to run the clock via utc_block.c and it seems to work fine.
    But I haven't investigated enough how this module calculates the time after sleep mode. I'll try to clarify it in the same way next week.
    But I think it's still a priority for me to change the RTC register directly

  • Hi Nick,

    Understood, I have already reached out to the R&D experts and I am awaiting their response. I hope to hear back from them early in the week. In the meantime, if you have any additional findings, then please share them in this thread and I will take a look & share them with R&D if it may be helpful.

    Best Regards,

    Jan

  • Okay, thanks
    I will be waiting for a response from your experts.

  • Hi,

    I have heard back from R&D and if modifying the RTC peripheral directly is necessary then they have suggested implementing logic by this:

    Suggested pseudo-code:

    1. Disable RTC (it will stop ticking)
    2. Calculate the diff to next timeout
    3. Set new RTC value
    4. Set new compare value to RTC + diff
    5. Enable RTC

    However, modifying the RTC while it is being accessed by other tasks (such as the BLE5-Stack) will likely lead to issues. If possible, they also suggest using a local offset value that is used to record the current RTC time instead of modifying the RTC directly.

    Best Regards,

    Jan

  • Hi,

    Okay, I tried to do something like this

    __STATIC_INLINE void hal_rtc_sec_set_2(unsigned int sec)
    {
        AONRTCDisable();
        uint32_t diff = HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP) - HWREG(AON_RTC_BASE + AON_RTC_O_TIME);
        HWREG(AON_RTC_BASE + AON_RTC_O_SEC) = sec;
        HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP) = diff + (uint32_t)((sec&0xFFFF)<<16);
        AONRTCEnable();
    }

    Unfortunately, this changes the registers as expected, but it still negatively affects the operation of the BLE stack.
    When changing the RTC registers, I still observe that something inside the RF breaks. I think there are some counters in the variables inside that give the wrong result due to the fact that I changed the RTC register and the reality does not meet expectations

    I think one of the possible reasons lies inside the ClockP_workFuncDynamic function.

    there is a variable "distance" where the result of the function ClockP_walkQueueDynamic is written.
    Due to the change of values ​​in RTC, I think that incorrect mathematical calculations are performed inside this function and because of this, incorrect timings are set. As a result, the entire BLE stack stops working correctly.
    I still haven't figured out how exactly this can be bypassed, even if it is a magic trick.
    Do your experts have any advice? Can they repeat the experiment when the device is working and broadcasting on the air, and at that moment we change the RTC value?

  • Hi,

    Got it. I got some information from our BLE R&D specifically and it is not recommended to set or reset the RTC while RF stacks are active as they heavily rely on the RTC. They recommend using a reference variable instead.

    Best Regards,

    Jan

  • Hi,

    Can your team give advice on how to suspend the Rf stack, change the RTC register and then restart the RF stack so that it recalculates the time intervals and works correctly?
    Or do you confirm that everything inside the RF stack is directly related to the RTC values and any impact directly on the RTC can lead to incorrect operation?

  • Hi,

    To suspend the RF stack when using BLE, you will need to cease all connections and stop all scanning & advertising. Afterwards, it may be possible for it to modify the RTC register as mentioned in the pseudocode. However, doing so while any RF operation is ongoing will likely lead to incorrect behavior as you have seen.

    Best Regards,

    Jan

  • Hi
    OK, thanks for the help.
    I have no questions at the moment, thanks for the help.