<?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>nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29103/nrf_log-fixes-in-sdk14-1-0</link><description>I&amp;#39;ve noticed following line in SDK14.1 release notes: 
 ` 
 
 Fixed a bug where nrf_log could crash when heavily loaded.
` 
 
 I&amp;#39;m using SDK13.1 in my current project and I&amp;#39;m experiencing nrf_log related crashes under load as described here . </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 05 May 2018 23:57:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29103/nrf_log-fixes-in-sdk14-1-0" /><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/131089?ContentTypeID=1</link><pubDate>Sat, 05 May 2018 23:57:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4560e752-716c-436f-9c29-ef5a6b273ce9</guid><dc:creator>Mark Leavitt</dc:creator><description>&lt;p&gt;Austin, you are a hero and genius!&lt;/p&gt;
&lt;p&gt;My SDK 14.2 app was crashing after 5-15 minutes, first symptom being log messages that were garbled (they looked like recycled earlier messages -- corrupted pointer?), then a hard lockup soon after. After replacing the standard nrf_log_frontend.c with your code 7522 above, my app has been running for hours now without a glitch.&lt;/p&gt;
&lt;p&gt;In SDK 15.0 notes, it looks like the logger *backend* has new features, but there&amp;#39;s no mention of bug fixes to the *frontend*.&amp;nbsp; So I&amp;#39;m sticking to 14.2 + AustinFix until I hear otherwise. Thank you!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/123303?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 16:32:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fce2a7f5-a230-4dc9-8eb7-8cee425f33aa</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;if I remember correctly I&amp;#39;ve placed link to this topic in comment section under the list, but maybe this was for SDK13.x. Feel free to add it if needed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/123298?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 15:54:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:787220ac-3d07-48fc-9c57-c4a652621c6d</guid><dc:creator>John C</dc:creator><description>&lt;p&gt;If I read that list correctly it looks like all log-related bugs are marked as Fixed in SDK 14.1.&lt;/p&gt;
&lt;p&gt;This bug, or similar, has evidently persisted into 14.2 - Do we need to make a new entry in the list?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/123293?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 15:40:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c02f112-b412-4059-a3bb-766bf8610116</guid><dc:creator>John C</dc:creator><description>&lt;p&gt;Thanks for the reference.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/123235?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 12:14:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2220c73-7274-4fc5-b00c-8606637ef22c</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;there are lists such as this one:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29796/what-are-sdk-14-x-0-known-issues"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/29796/what-are-sdk-14-x-0-known-issues&lt;/a&gt;&amp;nbsp;for every major SDK version&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/123221?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2018 11:42:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbc484c2-1e85-4273-be58-f450648eafca</guid><dc:creator>John C</dc:creator><description>&lt;p&gt;@Nordic:&amp;nbsp;Are&amp;nbsp;bugs like this being tracked against SDK releases somewhere that we can see?&lt;/p&gt;
&lt;p&gt;It would be reassuring to see an triaged list of known bugs and each releases&amp;#39; ongoing support status. This would avoid peeps&amp;nbsp;spending&amp;nbsp;time re-discovering known bugs and enable them to judge whether to patch, wait for a fix or just avoid. This particular bug was not a great introduction to NRF52&amp;nbsp;as the symptoms&amp;nbsp;varied with the text I was logging! This module is clearly labelled as experimental, so&amp;nbsp;having bugs is no shame at all, but I would still give the fix a reasonably high priority because I think it quite likely to bite and discourage other peeps evaluating your products.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115507?ContentTypeID=1</link><pubDate>Mon, 22 Jan 2018 13:45:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e2d63d4-22bd-403d-a0fa-2d9f5e44189c</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;@Krzsztof after a period of testing I can confirm that problem is resolved. Thanks for providing the patches!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115511?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 05:15:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab28c074-4c3d-495d-81c6-bc06dbb5249b</guid><dc:creator>Austin</dc:creator><description>&lt;p&gt;There are number of issues with logging, even with SDK 14.2.0. The change in Krzysztof&amp;#39;s answer goes a long way to fixing issues related to buffer overflow in normal operating conditions. This change fixes issues when using NRF_LOG_PUSH which could incorrectly return a pointer to non-contiguous memory and result in memory overwrites outside of the log buffer.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attempted to address some additional issues with the nrf log front end including the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add consistent handling of log buffer allocations by always setting the allocated log buffer type as INAVLID.&lt;/li&gt;
&lt;li&gt;Ensuring that buffer full can be distinguished from buffer empty condition.&lt;/li&gt;
&lt;li&gt;Better handling of errors when there is no log buffer space remaining.&lt;/li&gt;
&lt;li&gt;Added notes which indicate additional design issues with the logging system which could be addressed in future.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See the attached &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nrf_5F00_log_5F00_frontend.c"&gt;nrf_log_frontend.c&lt;/a&gt;. This file is based on SDK 14.2.0 and addresses some of the issues listed above. All &amp;#39;// NOTE:&amp;#39; comment lines indcate changes from SDK 14.2.0 with reasons for the change.&lt;/p&gt;
&lt;p&gt;Updated 22 Feb 2018: Fixed additional bug in nrf_log_frontend.c related to buffering of hex data and rewrote buffering used by nrf_log_push.&amp;nbsp; See new attachment&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/7522.nrf_5F00_log_5F00_frontend.c"&gt;devzone.nordicsemi.com/.../7522.nrf_5F00_log_5F00_frontend.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115503?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 11:26:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:076c2cda-9b43-48e3-baf5-8248900bb634</guid><dc:creator>Austin</dc:creator><description>&lt;p&gt;@Krzsztof Thanks for the update, I was developing my own fix for this today but will take your change instead.  There are quite a number of other issues with data races and edge conditions in this module.  I&amp;#39;m hoping to propose some changes early next week as another answer to this question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115504?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 10:45:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c4b3844-670b-4940-98dc-8c4ed81b1a87</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;yes, it is 1 word.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115506?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 10:42:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:177f52ce-c03b-4b8f-9eaf-4959128a4d01</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;SDK 13.1 nrf_log implementation  has no definition of &lt;code&gt;PUSHED_HEADER_SIZE&lt;/code&gt;. Can I assume that it&amp;#39;s equal to 1 word as per comment on line 438 of &lt;code&gt;nrf_log_internal.h&lt;/code&gt; in SDK14.2?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115505?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 21:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdaa5753-91eb-48b1-8857-b4de9923fd29</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;could you please provide either whole body of &lt;code&gt;cont_buf_prealloc()&lt;/code&gt; or git patch? I&amp;#39;m not sure what to do with the rest of the critical section.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115510?ContentTypeID=1</link><pubDate>Wed, 20 Dec 2017 10:31:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e5d826e-cbee-457e-8aa0-83cb35b0dbda</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;Since Nordic provided the &amp;#39;fixed&amp;#39; snippet at the top of this post I was hoping that someone who knows how this is supposed to work may come up with correct available_words estimate equation. Original doesn&amp;#39;t handle overflows correctly, your proposed fix doesn&amp;#39;t handle no overflow situations. Please at least advise is there situation where they both fail? I&amp;#39;m not that familiar with nrf_log internals to be able to judge that.&lt;/p&gt;
&lt;p&gt;As for migrating to more recent SDK/backporting parts of SDK14 this is exactly what I&amp;#39;m trying to avoid. The product I&amp;#39;m currently developing is near release so we cannot afford any significant changes.&lt;/p&gt;
&lt;p&gt;BTW it may be a good idea to consider having long term support version of the SDK with focus on no bugs and stability every once in a while. IMHO some developers (including me) would really appreciate codebase that maybe is not feature complete but is thoroughly tested both by Nordic and by the community and it&amp;#39;s known to contain (almost) no bugs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115509?ContentTypeID=1</link><pubDate>Wed, 20 Dec 2017 08:12:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d71ce15-482d-49cc-a988-68d72320620b</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;we have made significant changes in nrf_log in SDK 14.0 and then bunch of stability fixes in SDK 14.1 It is hard to provide the patch for them. You can try to port latest nrf_log to SDK 13. Here is  &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/migration.html?cp=4_0_2_1_7_4_1#migration_libs_nrf_log"&gt;the migration guide&lt;/a&gt; which might be helpful:&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115508?ContentTypeID=1</link><pubDate>Tue, 19 Dec 2017 15:59:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e95a1bc-edfc-4ad5-89dd-2cf10ff48715</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;It seems that fix posted above is only valid when NRF_LOG_DEFERRED_BUFSIZE is smaller than logged data amount. For large NRF_LOG_DEFERRED_BUFSIZE patch above leads to a hardfault while original buffer size estimate works.&lt;/p&gt;
&lt;p&gt;I know that Nordic devs are busy preparing SDK15 release but for all users like me who are stuck with SDK13 I&amp;#39;d really appreciate that someone who knows internals of nrf_log module takes a look if this approach is correct.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;diff --git a/components/libraries/log/src/nrf_log_frontend.c b/components/libraries/log/src/nrf_log_frontend.c
index e8f80c10..e6f5dfd7 100644
--- a/components/libraries/log/src/nrf_log_frontend.c
+++ b/components/libraries/log/src/nrf_log_frontend.c
@@ -379,8 +379,25 @@ static inline uint32_t * cont_buf_prealloc(uint32_t len32,

     CRITICAL_REGION_ENTER();
     *p_wr_idx = m_log_data.wr_idx;
+
     uint32_t available_words = (m_log_data.mask + 1) -
                                (m_log_data.wr_idx &amp;amp; m_log_data.mask);
+
+       /*
+               This is more robust attempt of fixing NRF_LOG_DEFFERED=1 hardfault.
+               Nordic posted fix here: &lt;a href="https://devzone.nordicsemi.com/question/174119/nrf_log-fixes-in-sdk1410/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;
+               The change works only when NRF_LOG_DEFERRED_BUFSIZE isn&amp;#39;t large enough to fit all log data before log processing happens.
+               When NRF_LOG_DEFERRED_BUFSIZE is large i.e. 4096 words proposed fix leads to hardfault by overflowing subtraction result
+
+               This is an attempt of more robust fix which assumes that smaller free space estimate is correct.
+       */
+
+       //this is how Nordic proposes to fix it
+       uint32_t available_words_alt=(m_log_data.mask + 1) - (m_log_data.wr_idx - m_log_data.rd_idx);
+
+       //assume that smaller value is correct
+       if(available_words_alt&amp;lt;available_words) available_words=available_words_alt;
+
     if (len32 &amp;lt;= available_words)
     {
         // buffer will fit as is
--
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115502?ContentTypeID=1</link><pubDate>Tue, 19 Dec 2017 10:56:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f636f45f-6137-4572-a0c6-60b435fd6bdf</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;Any updates on this? I have a project where I have to use deffered logging due to timing constraints and NRF_LOG hardfaults every time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115501?ContentTypeID=1</link><pubDate>Thu, 19 Oct 2017 14:58:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b07d7ef5-8753-4236-82c7-a18d28b2ba0a</guid><dc:creator>Keton</dc:creator><description>&lt;p&gt;thanks, it solved the problem for test case I&amp;#39;ve linked but still I&amp;#39;m able to crash MCU by doing bunch of: &lt;code&gt;NRF_LOG_RAW_DEBUG(&amp;quot;%s\r\n&amp;quot;,nrf_log_push(str));&lt;/code&gt; where &lt;code&gt;str&lt;/code&gt; is: &lt;code&gt;char str[150]&lt;/code&gt;. When I&amp;#39;m using &lt;code&gt;SEGGER_RTT_Write&lt;/code&gt; instead of nrf_log it doesn&amp;#39;t crash so it&amp;#39;s most likely another memory access issue in nrf_log.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_log fixes in SDK14.1.0</title><link>https://devzone.nordicsemi.com/thread/115500?ContentTypeID=1</link><pubDate>Thu, 19 Oct 2017 11:11:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9c933d6-52bd-4bda-9dd8-bdbcd8f6ab06</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;you can try to find function cont_buf_prealloc in nrf_log_frontend.c and update following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t available_words = (m_log_data.mask + 1) -
                           (m_log_data.wr_idx &amp;amp; m_log_data.mask);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;should be changed to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t available_words = (m_log_data.mask + 1) -
                            (m_log_data.wr_idx - m_log_data.rd_idx);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That should help.&lt;/p&gt;
&lt;p&gt;UPDATE
Actually, the fix provided was not good and there was still a bug in SDK 14.2.0 in that function. Here is the updated version the function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static inline uint32_t * cont_buf_prealloc(uint32_t len32,
                                       uint32_t * p_offset,
                                       uint32_t * p_wr_idx){
uint32_t * p_buf = NULL;

len32 += PUSHED_HEADER_SIZE; // Increment because 32bit header is needed to be stored.

CRITICAL_REGION_ENTER();
*p_wr_idx = m_log_data.wr_idx;
uint32_t available_words = (m_log_data.mask + 1) -
                            (m_log_data.wr_idx - m_log_data.rd_idx);
uint32_t cont_words =  (m_log_data.mask + 1) - (m_log_data.wr_idx &amp;amp; m_log_data.mask);

//available space is continuous
uint32_t curr_pos_available = (available_words &amp;lt;= cont_words) ? available_words : cont_words;
uint32_t start_pos_available = (available_words &amp;lt;= cont_words) ? 0 : (available_words - cont_words);
if (len32 &amp;lt;= curr_pos_available)
{
    // buffer will fit as is
    p_buf              = &amp;amp;m_log_data.buffer[(m_log_data.wr_idx + 1) &amp;amp; m_log_data.mask];
    m_log_data.wr_idx += len32;
    *p_offset          = 0;
}
else if (len32 &amp;lt;= start_pos_available)
{
    // wraping to the begining of the buffer
    m_log_data.wr_idx += (len32 + cont_words);
    *p_offset          = cont_words;
    p_buf              = m_log_data.buffer;
}

CRITICAL_REGION_EXIT();

return p_buf;}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>