1.. zephyr:code-sample:: nrf_sync_rtc 2 :name: Synchronized RTC 3 4 Synchronize system and network core RTC clocks. 5 6Overview 7******** 8 9Sample is showing how RTC clocks used for system clock on application and network 10core are synchronized. The result of synchronization is an offset value on network 11core which can be applied to the system tick for logging timestamping. 12 13Sample is using IPM driver and IPC HAL to produce events which occur at same time on 14both cores. Application core periodically reads current system tick and stores it in 15the shared memory and triggers IPC task which results in the interrupt on the network 16core. In the context of the IPC interrupt handler, network core is logging timestamp 17from shared memory and local system tick updated by the offset. User can observe 18that before synchronization procedure is completed, timestamps differ significantly 19and once procedure is completed timestamps are synchronized. Network core timestamp 20may be slightly behind (usually 1 tick) due to latency introduced by the 21interrupt handling. 22 23For simplicity and low latency sample is not using more sophisticated IPM protocols. 24 25Building the application for nrf5340dk/nrf5340/cpuapp 26***************************************************** 27 28.. zephyr-app-commands:: 29 :zephyr-app: samples/boards/nordic/nrf53_sync_rtc 30 :board: nrf5340dk/nrf5340/cpuapp 31 :goals: flash 32 :flash-args: --hex-file build/nrf53_sync_rtc/zephyr/zephyr.hex 33 :west-args: --sysbuild 34 35Open a serial terminals (for example Minicom or PuTTY) and connect the board with the 36following settings: 37 38- Speed: 115200 39- Data: 8 bits 40- Parity: None 41- Stop bits: 1 42 43When you reset the development kit, the following messages (one for master and one for remote) will appear on the corresponding serial ports: 44 45.. code-block:: console 46 47 *** Booting Zephyr OS build v2.7.0-rc1-89-ge755863d66c9 *** 48 [00:00:00.306,915] <inf> main: IPC send at 10056 ticks 49 [00:00:00.356,903] <inf> main: IPC send at 11695 ticks 50 [00:00:00.406,921] <inf> main: IPC send at 13334 ticks 51 [00:00:00.456,939] <inf> main: IPC send at 14973 ticks 52 [00:00:00.506,958] <inf> main: IPC send at 16612 ticks 53 [00:00:00.556,976] <inf> main: IPC send at 18251 ticks 54 [00:00:00.606,994] <inf> main: IPC send at 19890 ticks 55 [00:00:00.657,012] <inf> main: IPC send at 21529 ticks 56 [00:00:00.707,031] <inf> main: IPC send at 23168 ticks 57 [00:00:00.757,049] <inf> main: IPC send at 24807 ticks 58 59 60.. code-block:: console 61 62 *** Booting Zephyr OS build v2.7.0-rc1-89-ge755863d66c9 *** 63 [00:00:00.054,534] <inf> main: Local timestamp: 1787, application core timestamp: 10056 64 [00:00:00.104,553] <inf> main: Local timestamp: 3426, application core timestamp: 11695 65 [00:00:00.154,571] <inf> main: Local timestamp: 5065, application core timestamp: 13334 66 [00:00:00.204,589] <inf> main: Local timestamp: 6704, application core timestamp: 14973 67 [00:00:00.254,608] <inf> main: Local timestamp: 8343, application core timestamp: 16612 68 [00:00:00.514,892] <inf> sync_rtc: Updated timestamp to synchronized RTC by 8270 ticks (252380us) 69 [00:00:00.557,006] <inf> main: Local timestamp: 18252, application core timestamp: 18251 70 [00:00:00.607,025] <inf> main: Local timestamp: 19891, application core timestamp: 19890 71 [00:00:00.657,043] <inf> main: Local timestamp: 21530, application core timestamp: 21529 72 [00:00:00.707,061] <inf> main: Local timestamp: 23169, application core timestamp: 23168 73 [00:00:00.757,080] <inf> main: Local timestamp: 24807, application core timestamp: 24807 74 75Observe that initially logging timestamps for the corresponding events on both cores 76do not match. Same with local and remote timestamps reported on network core. After 77RTC synchronization is completed they start to match. 78 79.. _nrf53_sync_rtc_sample_build_bsim: 80 81Building the application for the simulated nrf5340bsim 82****************************************************** 83 84.. zephyr-app-commands:: 85 :zephyr-app: samples/boards/nordic/nrf53_sync_rtc 86 :host-os: unix 87 :board: nrf5340bsim/nrf5340/cpuapp 88 :goals: build 89 :west-args: --sysbuild 90 91Then you can execute your application using: 92 93.. code-block:: console 94 95 $ ./build/zephyr/zephyr.exe -nosim 96 # Press Ctrl+C to exit 97 98You can expect a similar output as in the real HW in the invoking console. 99