<?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>Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/126106/best-way-to-avoid-recursion-in-zephyr-when-enabling-logging-to-backend-with-littlefs-to-flash-memory</link><description>We are working on an nrf54l15dk board but want to log directly to the nrf flash memory (instead of the ext flash) - which we are doing successfully. In Zephyr we have logging to backend enabled working so any call to LOG_ERR, LOG_INF ...etc gets directly</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Dec 2025 15:35:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/126106/best-way-to-avoid-recursion-in-zephyr-when-enabling-logging-to-backend-with-littlefs-to-flash-memory" /><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/557248?ContentTypeID=1</link><pubDate>Wed, 17 Dec 2025 15:35:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdab192d-9cfb-4b10-bb1e-9a8d30df4efc</guid><dc:creator>Elfving</dc:creator><description>[quote user="jthmp"]&lt;p&gt;We used the samples as a starting point, but since we are using backend logging there is no example I could find that is addressing our use case:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Every time we use something like LOG_INF, or LOG_WRN it gets stored in a ext or internal flash memory. Looking at the zephyr code &amp;#39;log_backend_fs.c&amp;#39; it seems like there is no contingency for detecting a persistent fs_write error.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;As in there not being a sample that handles the issues with flash writes for logging? I do not know of any that handles this exact problem myself, though it seems as if a few customers have run into a similar issue previously.&amp;nbsp;I assume you are not for instance &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/101288/runtime-disable-log-backend-fs-in-nrf-connect-1-7-0/439973"&gt;running into the same situation as this guy here&lt;/a&gt;, who had this issue because he wanted to initialize LWM2M_CARRIER at the same time? Either way it might be a good idea to have a look at that thread.&lt;/p&gt;
&lt;p&gt;If you see this often happen on a DK, could you get me something minimal that reproduces this?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/557027?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2025 22:20:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:575028e6-741a-4838-9bf1-a0a1c1961ac0</guid><dc:creator>jthmp</dc:creator><description>&lt;p&gt;Hi Elfving,&lt;br /&gt;I&amp;#39;ve found an issue with our flash failure test. We&amp;#39;ve observed the following:&lt;br /&gt;1. if we prevent the little fs flash write from working only (read still works) then the system hangs&lt;br /&gt;2. if we prevent both the flash read and write from working the the backend logger code successfully disables itself and the system does not hang&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, in the event that only the flash write fails (indefinitely) the Zephyr sdk doesn&amp;#39;t seem to handle this well. In any case, it&amp;#39;s unlikely we will encounter only the flash write failing.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/557011?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2025 17:38:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9f1ebde-354b-4328-95e8-d9f83de1ae9a</guid><dc:creator>jthmp</dc:creator><description>&lt;p&gt;Hi Elfving,&lt;br /&gt;We used the samples as a starting point, but since we are using backend logging there is no example I could find that is addressing our use case:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Every time we use something like LOG_INF, or LOG_WRN it gets stored in a ext or internal flash memory. Looking at the zephyr code &amp;#39;log_backend_fs.c&amp;#39; it seems like there is no contingency for detecting a persistent fs_write error.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;Because of this the firmware seems to get stuck if the flash IC no longer responds. But we really need Zephyr to simply disable the backend logger if this happens so the firmware can continue to run and just not attempt logging to flash memory.&lt;br /&gt;&lt;br /&gt;I had to update the zephyr log_backend_fs.c code to detect continuous errors from the fs_write and then disable the backend logger. However, I would obviously rather use something that Zephyr put in place for such a case.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;If there isn&amp;#39;t anything that&amp;#39;s fine, I just wanted to make sure I wasn&amp;#39;t duplicating work.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/556964?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2025 13:01:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6da1bc5-75d1-43b0-b753-cc613fe0b8f2</guid><dc:creator>Elfving</dc:creator><description>[quote user="jthmp"]&lt;p&gt;Yes that&amp;#39;s a great idea. Is there example code for this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/subsys/logging/logger/README.html"&gt;Looks like there is some use of it in this sample that you can have a look at.&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
[quote user="jthmp"]Also, is there a correct way to handle if the flash driver / low level code fails and &amp;#39;fs_write&amp;#39; starts returning errors? Since it will lock up the firmware and we would like to catch this and disable the backend if that happens[/quote]
&lt;p&gt;I am bit uncertain about this, &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/subsys/fs/littlefs/README.html"&gt;but the samples for handling flash drivers would typically show a good workflow for handling the potential issues that comes with it as well.&lt;/a&gt; Have you had a look at the checks that are being done in the samples?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/556906?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2025 18:46:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57d02965-deb0-4d1e-bf0c-d8d5f349bf74</guid><dc:creator>jthmp</dc:creator><description>&lt;p&gt;Hi Elfving,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes that&amp;#39;s a great idea. Is there example code for this?&lt;/p&gt;
&lt;p&gt;Also, is there a correct way to handle if the flash driver / low level code fails and &amp;#39;fs_write&amp;#39; starts returning errors? Since it will lock up the firmware and we would like to catch this and disable the backend if that happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to avoid recursion in Zephyr when enabling logging to backend with littlefs to flash memory</title><link>https://devzone.nordicsemi.com/thread/556874?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2025 13:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:921176fe-9f63-47ca-ae02-b9170faf30b2</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hi Joshua,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So after a quick look it seems to me as if you could use two backends (&lt;span&gt;LOG_BACKEND_UART and&amp;nbsp;LOG_BACKEND_FS&lt;/span&gt;) and &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/logging/index.html#logging_backends"&gt;then filter for a certain module at a given backend.&lt;/a&gt;&amp;nbsp;Let me know if that works for you, otherwise I have to get back to you next week.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>