<?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>Low power management of external flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119913/low-power-management-of-external-flash</link><description>Hi, 
 my setup is the following: 
 - SDK 2.6.3 
 - nRF5340 
 - Low power management for external flash enabled 
 - Logging enabled (based on littleFS) 
 - external flash used to store continuously data 
 With this configuration i am observing an exponential</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 24 Mar 2025 13:57:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119913/low-power-management-of-external-flash" /><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/528641?ContentTypeID=1</link><pubDate>Mon, 24 Mar 2025 13:57:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc917b59-f14b-497b-b087-c7e3d39a424b</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi Riccardo,&lt;/p&gt;
&lt;p&gt;I see. The approach your going for seems right/possible to implement your own custom solution for power power management. I can&amp;#39;t quite see why it shouldn&amp;#39;t work given that you design the solution so that it handles the typical edge cases for your product.&lt;/p&gt;
&lt;p&gt;Let me know if your testing results in something different,&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/528366?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2025 09:56:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4c00c74-61d1-419e-8368-95482c163f3a</guid><dc:creator>Riccardo Gaiati</dc:creator><description>&lt;p&gt;Hi Andreas !&lt;/p&gt;
&lt;p&gt;thanks for the reply. I think i understand the approach of the PM APIs by giving to the user of a specific device the possibility to control the low power of the external flash. If i am not wrong, this pattern relies on the user to do the &amp;quot;right thing&amp;quot; according to its needs.&lt;/p&gt;
&lt;p&gt;My idea is simply to avoid spreading those apis between the users of the flash and relies only on the driver (spi_nor.c), which will create a single manager of the power management, instead of&amp;nbsp; as many as the users of it.&lt;/p&gt;
&lt;p&gt;Since the entry and exit time in low power are measured typically in microseconds, it is reasonable to convert them into ticks (eventually rounded them up) and use those values as input parameters for the delays. I have attached here the modifications i made in the spi_nor.c file. I did not change the wake up sequence, since i am not using (the modifications are pretty straightforward to do in case).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0334.spi_5F00_nor.c"&gt;devzone.nordicsemi.com/.../0334.spi_5F00_nor.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Riccardo&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/528008?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 12:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75e7569b-3b27-4aee-8dc4-70d5e6326e19</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hmm, maybe. I did some looking around because I remembered another case from roughly 1.5 years ago with NCS v2.4.1. At this point in time we had limited/experimental XIP over QSPI support and to showcase how to do a &amp;quot;low&amp;quot; power version of this a colleague of mine created a demo. You might be able to apply a similar application to the logging functionality and/or external flash as done below in the excerpt of main() within the attached xip sample.&lt;/p&gt;
&lt;p&gt;The interesting part in the snippet below that I&amp;#39;m referring to is related to&lt;/p&gt;
&lt;p&gt;&lt;em&gt; pm_device_action_run(uart_dev, PM_DEVICE_ACTION_RESUME);&lt;/em&gt;&lt;br /&gt;&lt;em&gt; pm_device_action_run(flash_dev, PM_DEVICE_ACTION_RESUME);&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
	int blink_status = 0;
	int err;
	
	const struct device *flash_dev = DEVICE_DT_GET(FLASH_NODE);
	const struct device *uart_dev = DEVICE_DT_GET(UART_NODE);

  printk(&amp;quot;XIP test sample\n&amp;quot;);
  k_sleep(K_SECONDS(1));

  for (;;) {
    printk(&amp;quot;Start test loop\n&amp;quot;);

#if CONFIG_NORDIC_QSPI_NOR_XIP
    nrf_qspi_nor_xip_enable(flash_dev, true);
    for(int i = 0; i &amp;lt; 10; i++){
      xip_test_write_ext_flash();
      k_sleep(K_MSEC(1));
      printk(&amp;quot;XIP external flash write %d\n&amp;quot;,i);
    }
#endif

    for(int i = 0; i &amp;lt; 10; i++){
      test_write_ext_flash();
      k_sleep(K_MSEC(1));
      printk(&amp;quot;External flash write %d\n&amp;quot;,i);
    }

    printk(&amp;quot;Disable test loop and sleep for 10 sec\n&amp;quot;);
    pm_device_action_run(uart_dev, PM_DEVICE_ACTION_SUSPEND);
    pm_device_action_run(flash_dev, PM_DEVICE_ACTION_SUSPEND);
#if CONFIG_NORDIC_QSPI_NOR_XIP
    xip_enabled = 0;
    nrf_qspi_nor_xip_enable(flash_dev, false);
#endif

    dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
    k_sleep(K_SECONDS(10));

    pm_device_action_run(uart_dev, PM_DEVICE_ACTION_RESUME);
    pm_device_action_run(flash_dev, PM_DEVICE_ACTION_RESUME);
    xip_enabled = 1;
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8156.xip_5F00_write_5F00_run_5F00_disable_5F00_feat_5F00_xip_5F00_thread-_2800_3_2900_.zip"&gt;devzone.nordicsemi.com/.../8156.xip_5F00_write_5F00_run_5F00_disable_5F00_feat_5F00_xip_5F00_thread-_2800_3_2900_.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I.e you can use PM API to suspend the flash_device when you&amp;#39;ve finished your activity with/on the external flash, but I&amp;#39;m not sure how well this translates to how to do this with the logging module. Let me know if you have any thoughts w.r.t how suspending the flash device is done in this sample&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/527975?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 09:34:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00c99a55-8113-4faf-85bd-2e988e1bd4ef</guid><dc:creator>Riccardo Gaiati</dc:creator><description>&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;The logging system is using the littlefs and the external flash. From your reply, i understand that this approach with the PM apis would not work in my case; unless i create a wrapper for the log functions where those PM apis are then invoked.&lt;/p&gt;
&lt;p&gt;At this point, i find easier to modify the actual implementation of spi_nor.c where the delays are now defined in TICKS, so that all the other modules that use it are not affected.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if DT_INST_NODE_HAS_PROP(0, t_enter_dpd)
#define T_DP_US (DT_INST_PROP(0, t_enter_dpd) / NSEC_PER_USEC)
#define T_DP_TICK (k_us_to_ticks_near32(T_DP_US))
#else /* T_ENTER_DPD */
#define T_DP_MS 0
#endif /* T_ENTER_DPD */
#if DT_INST_NODE_HAS_PROP(0, t_exit_dpd)
#define T_RES1_US (DT_INST_PROP(0, t_exit_dpd) / NSEC_PER_USEC)
#define T_RES1_TICK (k_us_to_ticks_near32(T_RES1_US))&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Honestly, i dont see why this approach cannot be considered in the future, instead of rounding up to 1 ms all the delays to enter and exit the low power of a flash. Is there an official place where a proposal like this can be done ?&lt;/p&gt;
&lt;p&gt;Thanks again for your support.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/527967?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 08:54:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09dfadc8-9e48-49c6-8ece-5aaf5c8a1ebf</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, if I understand your question correct. The logging system itself doesn&amp;#39;t automatically call PM functions, but if you&amp;#39;re for instance logging over UART you can use the PM API to suspend the UART device, somewhat similar to what&amp;#39;s shown below and thus disable/enable logging:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const struct device *uart0_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));  
pm_device_action_run(uart0_dev, PM_DEVICE_ACTION_SUSPEND);&lt;/pre&gt;&lt;/p&gt;
&lt;div&gt;From here you can resume the UART device when you need it to enable logging again. I believe this public case might still be relevant, allthough it is &amp;gt;2 years old. Do note that some API&amp;#39;s and configs may have changed from the relevant NCS version at that point in time and the latest and greatest now in 2025:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/95050/nrf52840-power-management-when-idle" rel="noopener noreferrer" target="_blank"&gt;Nordic Q&amp;amp;A: nRF52840 Power Management when idle&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Let me know if I understood your question properly and please clarify if I missed what you were referring to&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Kind regards,&lt;br /&gt;Andreas&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/527897?ContentTypeID=1</link><pubDate>Tue, 18 Mar 2025 16:21:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e4130af-a7dc-4457-8992-aa505f6b9ca7</guid><dc:creator>Riccardo Gaiati</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thanks for the reply.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding the PM APIs, i can control the entry ti and exit from low power of the flash through those functions. But what about the log system ? Would it call these function aswell ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Low power management of external flash</title><link>https://devzone.nordicsemi.com/thread/527855?ContentTypeID=1</link><pubDate>Tue, 18 Mar 2025 13:36:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6a48bfe-8c16-49fc-933a-1751b2049a6b</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]1. Why the need to convert in milliseconds those delays (in the specific case, causing an increase between 30 and 100 times) ?[/quote]
&lt;p&gt;In the API we&amp;#39;re using we&amp;#39;re rounding up to nearest ms. If your device are capable of running with those delays and your activity can handle it (and you can handle the extra current consumption that might come with this), you&amp;#39;re free to test out using 30 and 10 µs instead.&lt;/p&gt;
[quote user=""]2. For such kind of microseconds delay would not be better to use even a blocking delay like&amp;nbsp;&lt;span&gt;&lt;em&gt;NRFX_DELAY_US&lt;/em&gt; ? (I have modified the spi.nor file and seems to work properly)&lt;/span&gt;[/quote]
&lt;p&gt;If it works and you&amp;#39;ve tested it properly, then you should be able to use the nrfx_delay_us instead, but note that we&amp;#39;ve only tested with what is present in the SDK by default&lt;/p&gt;
[quote user=""]3. Is there a way - even i looked for but could not find it - to enable the power management for the external flash at runtime ? So in my case, it would be disabled at the boot up and once done, it gets enabled.[/quote]
&lt;p&gt;PM device API:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/pm/index.html"&gt;https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/pm/index.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]4. Eventually, could this change be considered in the future version of sdk ?[/quote]
&lt;p&gt;I&amp;#39;m not 100% sure this is relevant after you&amp;#39;ve seen through the PM device in item 3, but let me know if that change sanything&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>