nrf52840 RCT2 configuration and usage

Hello,

I'm trying to enable RTC2 for nrf52840 DK to use as a date time clock and set/get over SMP protocol. RTC0 is used for MPSL, RTC1 is used by the system.

I configured MCU MGR option:

CONFIG_MCUMGR_GRP_OS_DATETIME=y

I configured RTC:

CONFIG_COUNTER=y
CONFIG_NRFX_RTC2=y
CONFIG_RTC=y

DTS for RTC2:

aliases {
		rtc = &rtc2;
	};
	
&rtc2 {
    status = "okay";
};

The command to set date-time works and return empty result. But when try to get date-time I see strange result. For instance:

{
  "datetime": "39997-165-36T05:168:00"
}

And now matter how many times I get it I see the same.

For me it looks like the RTC2 is not initialized. But i check it readiness in main:

if (!device_is_ready(rtc)) {
		printk("Device RTC is not ready\n");
		return 0;
	}
 

Anything I forget to do to use RTC2 as a date-time source?

Parents
  • Hi

    Just to check, are you using the os_mgmt_datetime sample in <ncs version>\zephyr\tests\subsys\mgmt\mcumgr\os_mgmt_datetime for this? Where does this strange output print from exactly? Are you sure you have set the date time as reference somewhere in your project so the RTC has a reference point? 

    Can you show me the full log of your application running so we can get a better understanding of what exactly is returning this value?

    Best regards,

    Simon

  • Hi Simonr,

    In my original project I don't use this example. But I adopted the test you mentioned to reproduce this issue. I attached my project. I did a build for nrf52840dk board with RTC0 used and SDK 3.0.0 version. To test date-time set/get functionality I use AuTerm tool and analyzed the terminal traffic to see what is inside the packets.

    I did next command sequence:

    1. Get current time

    2. Set current time

    3. Get current time

    The traffic looks like the next:

    \06	AAsIAAABAAANBKBXIA==
    \06	ACkJAAAfAAANBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP88ig==
    
    \06	AC8KAAAlAAAOBKFoZGF0ZXRpbWV4GTIwMjUtMDUtMjBUMTQ6NTU6MTYrMDI6MDDQUw==
    \06	AAwLAAACAAAOBL//9T4=
    
    \06	AAsIAAABAAAPBKA5QA==
    \06	ACkJAAAfAAAPBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP83Ew==

    This is a Base64 packets and I decrypted them based on the SPM protocol specification and UART transport specification:

    Get
    \06	AAsIAAABAAANBKBXIA==
    000b 0800000100000d04 a0 5720
    {}
    \06	ACkJAAAfAAANBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP88ig==
    0029 0900001f00000d04 bf686461746574696d6573323934382d30312d30305430303a34353a3030ff 3c8a
    { "datetime": "2948-01-00T00:45:00"}
    
    Set
    \06	AC8KAAAlAAAOBKFoZGF0ZXRpbWV4GTIwMjUtMDUtMjBUMTQ6NTU6MTYrMDI6MDDQUw==
    002f 0a00002500000e04 a1686461746574696d657819323032352d30352d32305431343a35353a31362b30323a3030 d053
    {"datetime": "2025-05-20T14:55:16+02:00"}
    \06	AAwLAAACAAAOBL//9T4=
    000c 0b00000200000e04 bfff f53e
    {}
    
    Get
    \06	AAsIAAABAAAPBKA5QA==
    000b 0800000100000f04 a0 3940
    {}
    \06	ACkJAAAfAAAPBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP83Ew==
    0029 0900001f00000f04 bf686461746574696d6573323934382d30312d30305430303a34353a3030ff 3713
    {_ "datetime": "2948-01-00T00:45:00"}

    As you can see even if I set the proper date-time in the second command with positive response to this command

    {"datetime": "2025-05-20T14:55:16+02:00"}

    I can't get the proper date-time on the following read. What interesting this output is the same as a first read and doesn't change

    { "datetime": "2948-01-00T00:45:00"}

    os_mgmt_datetime.zip

Reply
  • Hi Simonr,

    In my original project I don't use this example. But I adopted the test you mentioned to reproduce this issue. I attached my project. I did a build for nrf52840dk board with RTC0 used and SDK 3.0.0 version. To test date-time set/get functionality I use AuTerm tool and analyzed the terminal traffic to see what is inside the packets.

    I did next command sequence:

    1. Get current time

    2. Set current time

    3. Get current time

    The traffic looks like the next:

    \06	AAsIAAABAAANBKBXIA==
    \06	ACkJAAAfAAANBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP88ig==
    
    \06	AC8KAAAlAAAOBKFoZGF0ZXRpbWV4GTIwMjUtMDUtMjBUMTQ6NTU6MTYrMDI6MDDQUw==
    \06	AAwLAAACAAAOBL//9T4=
    
    \06	AAsIAAABAAAPBKA5QA==
    \06	ACkJAAAfAAAPBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP83Ew==

    This is a Base64 packets and I decrypted them based on the SPM protocol specification and UART transport specification:

    Get
    \06	AAsIAAABAAANBKBXIA==
    000b 0800000100000d04 a0 5720
    {}
    \06	ACkJAAAfAAANBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP88ig==
    0029 0900001f00000d04 bf686461746574696d6573323934382d30312d30305430303a34353a3030ff 3c8a
    { "datetime": "2948-01-00T00:45:00"}
    
    Set
    \06	AC8KAAAlAAAOBKFoZGF0ZXRpbWV4GTIwMjUtMDUtMjBUMTQ6NTU6MTYrMDI6MDDQUw==
    002f 0a00002500000e04 a1686461746574696d657819323032352d30352d32305431343a35353a31362b30323a3030 d053
    {"datetime": "2025-05-20T14:55:16+02:00"}
    \06	AAwLAAACAAAOBL//9T4=
    000c 0b00000200000e04 bfff f53e
    {}
    
    Get
    \06	AAsIAAABAAAPBKA5QA==
    000b 0800000100000f04 a0 3940
    {}
    \06	ACkJAAAfAAAPBL9oZGF0ZXRpbWVzMjk0OC0wMS0wMFQwMDo0NTowMP83Ew==
    0029 0900001f00000f04 bf686461746574696d6573323934382d30312d30305430303a34353a3030ff 3713
    {_ "datetime": "2948-01-00T00:45:00"}

    As you can see even if I set the proper date-time in the second command with positive response to this command

    {"datetime": "2025-05-20T14:55:16+02:00"}

    I can't get the proper date-time on the following read. What interesting this output is the same as a first read and doesn't change

    { "datetime": "2948-01-00T00:45:00"}

    os_mgmt_datetime.zip

Children
No Data
Related