<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/120566/rtc-source-for-log-module-timestamp</link><description>Hi all, 
 I&amp;#39;m doing some tests with the nRF5340 DK to log with a custom timestamp source. I took the logging exercise 2 example and verified that the log messages are correctly printed with the timestamp associated with the internal clock. However, for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Apr 2025 01:17:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/120566/rtc-source-for-log-module-timestamp" /><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/533285?ContentTypeID=1</link><pubDate>Tue, 29 Apr 2025 01:17:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13933860-d7d8-4d92-839b-f9bb81276b65</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Valentine,&lt;/p&gt;
&lt;p&gt;Did you build with&amp;nbsp;CONFIG_ASSERT set?&lt;/p&gt;
&lt;p&gt;I ran a test and without CONFIG_ASSERT, everything works normally if no timestamp formatter is set yet, except logs don&amp;#39;t have timestamps.&lt;/p&gt;
&lt;p&gt;You can also consider using &lt;a href="https://docs.nordicsemi.com/bundle/zephyr-apis-3.0.0/page/group_sys_init.html"&gt;the System Initialization API&lt;/a&gt;. I found this seems to work after some tests:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if defined(CONFIG_LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP)

int test_timestamp_formatter(const struct log_output *output,
	const log_timestamp_t timestamp,
	const log_timestamp_printer_t printer)
{
	return printer(output, &amp;quot;%04d-test&amp;quot;, timestamp);
}

void test_set_custom_timestamp_formatter(void)
{
	/* Set the custom timestamp formatter. */
	log_custom_timestamp_set(test_timestamp_formatter);
}

SYS_INIT(test_set_custom_timestamp_formatter, APPLICATION, 32);

#endif /* CONFIG_LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you need even earlier logging working, you can set other value for the &amp;quot;level&amp;quot; parameter of SYS_INIT,&amp;nbsp;referring to the linked documentation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/532665?ContentTypeID=1</link><pubDate>Wed, 23 Apr 2025 17:50:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a0533be-1c2f-40b5-aa33-967c9b354865</guid><dc:creator>Valentin Otte</dc:creator><description>&lt;p&gt;Hi Hieu, I have another question regarding the custom timestamp logging. I added the&amp;nbsp;&lt;em&gt;log_output_custom.h&lt;/em&gt; library and defined a formatter function like this:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt; UNIX&lt;/span&gt;&lt;span&gt;_timestamp_formatter&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;log_output&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;output&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;log_timestamp_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;timestamp&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;log_timestamp_printer_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;printer&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;time_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;raw_time&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;time_t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;timestamp&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;tm&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Convert to UTC time */&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;gmtime_r&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;raw_time&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Format: yyyy-mm-ddThh:mm:ssZ */&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;printer&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;output&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;%04d&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;%02d&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;%02d&lt;/span&gt;&lt;span&gt;T&lt;/span&gt;&lt;span&gt;%02d&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;%02d&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;%02d&lt;/span&gt;&lt;span&gt;Z&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_year&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;1900&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_mon&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_mday&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_hour&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_min&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;tm_info&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;tm_sec&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;And use the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;em&gt;log_custom_timestamp_set&lt;/em&gt; function to associate my custom formatter. The thing is that if I dont do this before any log that uses the timestamp, my code crashes because no formatter is associated.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Is there a way to use the default timestamp formatting like &lt;em&gt;[hh:mm:ss.ms,package_number]&lt;/em&gt;, and once I know everything is configured correctly, use the UNIX_timestamp_formatter?&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/532448?ContentTypeID=1</link><pubDate>Tue, 22 Apr 2025 20:32:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b81f868-11cc-4124-a26b-66b9ba50d0c1</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Valentine,&lt;/p&gt;
&lt;p&gt;No problem. I am glad my answers help. Please feel free to follow-up if you have any further questions on the same topic.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/532442?ContentTypeID=1</link><pubDate>Tue, 22 Apr 2025 20:23:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8263d8b-7fb8-4112-87c4-d6eea0e7cc23</guid><dc:creator>Valentin Otte</dc:creator><description>&lt;p&gt;Hi Hieu, I closed it since the original issue was resolved, and, in the tests I made, minor changes to the timestamp format were necessary. This answer is still helpful, since I now want to format UNIX time to a human-readable format. From what I understand, I should define a log_custom_timesamp_print function, but I&amp;#39;m still a bit confused about the printer and the formatters, and if I should define some custom ones.&lt;br /&gt;I&amp;#39;ll do some further investigation and check if there&amp;#39;s an example code on how to integrate it.&lt;br /&gt;Thank you again for your time and answers!&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/531904?ContentTypeID=1</link><pubDate>Tue, 15 Apr 2025 20:24:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d68d043a-50e3-4be3-aed8-78858e29ac14</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Valentin,&lt;/p&gt;
&lt;p&gt;I see you have closed the case, so I am not sure if you still need the answers to your follow-up question. However, for custom timestamp formatting, you want to look into these:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/zephyr-apis-2.9.1/page/log_output_custom_8h.html#a2b09917a2f801d90109b46afaa445d22"&gt;log_custom_timestamp_print()&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/kconfig/index.html#CONFIG_LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP"&gt;CONFIG_LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/531742?ContentTypeID=1</link><pubDate>Mon, 14 Apr 2025 16:51:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c958edd-9cc9-47eb-b2f2-7a513d999135</guid><dc:creator>Valentin Otte</dc:creator><description>&lt;p&gt;Hi Hieu, thank you for your quick response. I tested your suggestions in my DK, and they are working as expected. As a quick fix regarding the timestamp formatting, I disabled the&amp;nbsp;&lt;em&gt;CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP&lt;/em&gt; flag so it can show the UNIX time I configured. If I wanted to transform the UNIX timestamp to something more human-readable, like&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;span&gt;&lt;em&gt;2025-04-02T11:41:05Z&lt;/em&gt;, is there a way to do so with the current logging modules?&lt;br /&gt;Thanks again for your help!&lt;br /&gt;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1744649299557v2.png" alt=" " /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC source for log module timestamp</title><link>https://devzone.nordicsemi.com/thread/531253?ContentTypeID=1</link><pubDate>Wed, 09 Apr 2025 22:52:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4bd7ee6-de10-47b9-adae-ce9adea106b3</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hello Valentin,&lt;/p&gt;
&lt;p&gt;There might be a misunderstanding with the terms Real-time Clock and RTC here.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;internal&lt;/em&gt; RTC in the nRF5340 is a &amp;quot;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf5340/page/rtc.html"&gt;Real-time &lt;em&gt;Counter&lt;/em&gt;&lt;/a&gt;&amp;quot; that can be used for timekeeping.&lt;br /&gt;Meanwhile, I believe that when the lesson mentions &amp;quot;external Real-time Clock,&amp;quot; it likely refers to external IC that provides time. Note that the original text in the lesson points to this Wikipedia page:&amp;nbsp;&lt;a href="https://en.wikipedia.org/wiki/Real-time_clock"&gt;Real-time clock - Wikipedia&lt;/a&gt;&lt;/p&gt;
[quote user=""]Do I have any limitations on what RTC I can use? This is a test, but I&amp;#39;ll be using BLE in my real application, and I read that some issues might limit what RTCs are available.&amp;nbsp;[/quote]
&lt;p&gt;Yes,&amp;nbsp;in a typical setup, there are some limitation.&lt;/p&gt;
&lt;p&gt;On the application core, where your main application will run, the Zephyr kernel runs off of RTC1. You only have free use of RTC0.&lt;br /&gt;On the network core, the kernel also runs off of RTC1, but there is additionally the Multi-protocol Service Layer (MPSL) that reserves RTC0. There is no RTC for free use on the network core.&lt;/p&gt;
&lt;p&gt;Ref:&amp;nbsp;&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/nrfxlib/mpsl/doc/mpsl.html"&gt;https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/nrfxlib/mpsl/doc/mpsl.html&lt;br /&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.7.99-ncs2-1/drivers/timer/nrf_rtc_timer.c&lt;br /&gt;https://docs.nordicsemi.com/bundle/ps_nrf5340/page/chapters/soc_overview/doc/instantiation.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can still access the counter registers of the reserved RTCs to get the current values&amp;nbsp;but controlling and configuring these RTCs are not allowed.&lt;/p&gt;
[quote user=""]Are there any updated examples of configuring an RTC as a log timestamp source? I&amp;#39;m not able to find any related examples or examples that are not outdated since I&amp;#39;m using the Nordic SDK 2.6.0.[/quote]
&lt;p&gt;I think what the DevAcademy lesson is talking about using &lt;a href="https://docs.nordicsemi.com/bundle/zephyr-apis-2.9.1/page/group_log_ctrl.html#gaea92150610f900ab1258cbce65662ae6"&gt;log_set_timestamp_func()&lt;/a&gt;&amp;nbsp;to set a custom timestamp provider for the Zephyr Logging module.&lt;/p&gt;
&lt;p&gt;The Zephyr Logger sample shows how to do that:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.7.99-ncs2-1/samples/subsys/logging/logger/src/main.c#L294-L299"&gt;sdk-zephyr/samples/subsys/logging/logger/src/main.c at v3.7.99-ncs2-1 · nrfconnect/sdk-zephyr&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As&amp;nbsp;we are discussing providing timestamp for logging, it is ideal&amp;nbsp;that the function returns quickly. Therefore,&amp;nbsp;if an external RTC is&amp;nbsp;involved, I think it should only be used to sync time for the entire system periodically, and the timestamp provider function would at most only do some simple addition/subtraction math to get the current time. Polling an external chip&amp;nbsp;is going to be too long.&lt;/p&gt;
&lt;p&gt;On that note, the&amp;nbsp;timestamp provider function can get time from any source, so you can also get timestamp from the internal RTC counter, but then there isn&amp;#39;t really any benefit from the default behavior.&lt;/p&gt;
[quote user=""]Will I be able to use the Message formatting options included in the&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.4.99-ncs1-2/include/zephyr/logging/log_output.h" rel="noopener noreferrer" target="_blank"&gt;include/zephyr/logging/log_output&lt;/a&gt;.&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.4.99-ncs1-2/include/zephyr/logging/log_output.h"&gt;h&lt;/a&gt;&amp;nbsp;to format this custom timestamp?[/quote]
&lt;p&gt;Yes. Please refer to &lt;a href="https://docs.nordicsemi.com/bundle/ncs-2.9.1/page/zephyr/services/logging/index.html"&gt;the Zephyr Logging module documentation&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>