<?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>Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113498/shoud-i-set-pm_device_action_suspend-on-i2c0-before-sys_poweroff</link><description>Dear Sir : 
 We are now developing on nrf52840, with ncs v2.6.1 and zephyr. 
 We want to put I2C0 to PM_DEVICE_ACTION_SUSPEND before sys_poweroff(). 
 Our code is below : 
 const struct device *const i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0)); 
 int</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Oct 2024 05:44:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113498/shoud-i-set-pm_device_action_suspend-on-i2c0-before-sys_poweroff" /><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/505093?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2024 05:44:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52f47180-850e-4c21-8178-ad8369f3f42e</guid><dc:creator>JY wu</dc:creator><description>&lt;p&gt;Hi, sorry for replying late.&lt;/p&gt;
&lt;p&gt;My work around is :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;remove&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE and&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As you said, this work around has trade off is to give up&amp;nbsp;&amp;quot;automatic power management&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But, at this time, we have no better solutions.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/505085?ContentTypeID=1</link><pubDate>Mon, 07 Oct 2024 03:51:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46d654e1-ff30-4ac8-afb1-b994a899ca69</guid><dc:creator>jeffryoliver</dc:creator><description>&lt;p&gt;@ &lt;a href="https://basketrandom.com"&gt;basket random&lt;/a&gt;: I agree with you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/499081?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2024 14:23:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5dc4b43d-39b7-46a6-b54c-04348fbe3c9e</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;So, your problem is solved in this way?&lt;/p&gt;
&lt;p&gt;Usually&amp;nbsp;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME should be enabled when you use I2C device.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If both&amp;nbsp;&lt;code dir="ltr"&gt;CONFIG_PM_DEVICE_RUNTIME&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code dir="ltr"&gt;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE&lt;/code&gt;&amp;nbsp;are off, it means that the automatic power management handled by these configurations is not active. I think because of your application type this would work.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/497706?ContentTypeID=1</link><pubDate>Sun, 11 Aug 2024 19:56:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1d63bb9-953b-4e78-b508-45c9b6f4f39c</guid><dc:creator>JY wu</dc:creator><description>&lt;p&gt;Hi~&lt;/p&gt;
&lt;p&gt;Thanks for your efforts.&lt;/p&gt;
&lt;p&gt;I tried to set&amp;nbsp;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n when&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME=y.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But still get &amp;quot;&amp;quot;Could not suspend I2C (-120)&amp;quot; when set I2C to PM_DEVICE_STATE_SUSPEND.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So I have to turn off&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After set&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME=n , I get a yellow under line warning on&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It says CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE is associated with&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finally, I remove&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n and&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME=n .&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now I can put I2C to&amp;nbsp;PM_DEVICE_STATE_SUSPEND after remove&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE and&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/497662?ContentTypeID=1</link><pubDate>Fri, 09 Aug 2024 15:10:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07e796e3-4190-4f25-985a-2f3224852fbe</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;#39;&amp;#39;&lt;span&gt;But I still don&amp;#39;t know remove CONFIG&lt;/span&gt;&lt;span&gt;_PM_DEVICE_RUNTIME has any portential disadvantage?&amp;#39;&amp;#39;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This could potentially lead to conflicts if not managed properly.&lt;/p&gt;
&lt;p&gt;If you want to use&amp;nbsp;&lt;span&gt;PM_DEVICE_ACTION_SUSPEND, you have to set&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE as &amp;#39;&amp;#39;n&amp;#39;&amp;#39;. It is enabled by default when CONFIG_PM_DEVICE_RUNTIME is enabled. You have disabled&amp;nbsp;CONFIG_PM_DEVICE_RUNTIME. So, I think it&amp;#39;s ok.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;you can read&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/pm/device_runtime.html#design_principles"&gt;Device Runtime Power Management (nordicsemi.com)&lt;/a&gt;&amp;nbsp;this documentation.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/496438?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 14:29:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a375115-5263-4661-9449-8558a1606dbc</guid><dc:creator>JY wu</dc:creator><description>&lt;p&gt;Hi~&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, I had add CONFIG_PM_DEVICE=y in prj.conf,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;At first, I add these lines:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;CONFIG_PM_DEVICE=y&lt;/p&gt;
&lt;p&gt;CONFIG_PM_DEVICE_RUNTIME=y&lt;/p&gt;
&lt;p&gt;CONFIG_POWEROFF=y&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Since &amp;quot;CONFIG_PM_DEVICE_RUNTIME=y&amp;quot; conflicts with PM_DEVICE_ACTION_SUSPEND, I remove it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are two relative setting left now:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;CONFIG_PM_DEVICE=y&lt;/p&gt;
&lt;p&gt;CONFIG_POWEROFF=y&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;After remove &amp;quot;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME&lt;/span&gt;&amp;quot;, I2c can be.SUSPEND successfully.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But I still don&amp;#39;t know&amp;nbsp;remove&amp;nbsp;&amp;nbsp;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME has any portential disadvantage?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/496434?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 13:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:266a8fb0-f513-4e1d-aa58-cca8b7b0d958</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It is recommended to suspend the I2C device before calling&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;sys_poweroff().&amp;nbsp;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;code dir="ltr"&gt;Did you add&amp;nbsp;CONFIG_PM_DEVICE=y in prj.conf file?&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;TWI shares registers and other resources with other peripherals that have the same ID as TWI.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Therefore, you must disable all peripherals that have the same ID as TWI before TWI can be configured and used. Disabling a peripheral that has the same ID as TWI will not reset any of the registers that are shared with TWI. It is therefore important to configure all relevant TWI registers explicitly to secure that it operates correctly.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can check if SDA and SCL pins of I2C are not used for other peripherals.&lt;/p&gt;
&lt;p&gt;&lt;code dir="ltr"&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/496336?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 07:06:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2bd47552-a2df-45a4-84ef-7e1bc50292c7</guid><dc:creator>JY wu</dc:creator><description>&lt;p&gt;Hi!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your suggestion.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We copy paste your code , but build failed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Error Message : undefined reference to `pm_device_state_set&amp;#39;&lt;/p&gt;
&lt;p&gt;Mabye we need another include file, so we add&lt;/p&gt;
&lt;p&gt;#include &amp;lt;zephyr/pm/pm.h&amp;gt;&lt;/p&gt;
&lt;p&gt;but not works, still get error message&amp;nbsp;&lt;span&gt;undefined reference to `pm_device_state_set&amp;#39; when build code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;VS code IDE intellisense list all functions starts with &amp;quot;pm_device_state&amp;quot;, but only &amp;quot;pm_device_state_get&amp;quot; found, no &amp;quot;pm_device_state_set&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;And we find out that, set&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;makes rc always return -120 in the following code.&lt;/p&gt;
&lt;p&gt;int rc = pm_device_action_run(i2c_dev, PM_DEVICE_ACTION_SUSPEND);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;After change &amp;quot;&lt;span&gt;CONFIG_PM_DEVICE_RUNTIME&lt;/span&gt;&lt;span&gt;=n &amp;quot; to &amp;quot;n&amp;quot;,&amp;nbsp;then&amp;nbsp;return value rc become 0, and&amp;nbsp;PM_DEVICE_ACTION_SUSPEND successed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does set &amp;quot;CONFIG_PM_DEVICE_RUNTIME&amp;quot;&amp;nbsp;to &amp;quot;n&amp;quot; has any disadvantage ?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?</title><link>https://devzone.nordicsemi.com/thread/496312?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 03:28:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a345d629-d864-47e3-9a7f-d8fbcba0ef00</guid><dc:creator>jeffryoliver</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&amp;nbsp;I think the error code -120 you are receiving when trying to suspend the I2C device indicates that the suspend action failed. This might be due to various reasons such as incorrect configuration or conflicts with other operations.&lt;br /&gt;While some peripherals might be automatically handled during system shutdown, it&amp;#39;s still recommended to properly manage the power state of peripherals like I2C to ensure data integrity and proper power management.&lt;/p&gt;
&lt;p&gt;I think you should&amp;nbsp;test both scenarios - with and without explicitly suspending I2C - to see if there are any differences in power consumption or behavior during system shutdown.&lt;br /&gt;Code Modification:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;c
const struct device *const i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

int rc = pm_device_state_set(i2c_dev, PM_DEVICE_STATE_SUSPEND);

if (rc &amp;lt; 0) {
printf(&amp;quot;Could not suspend I2C (%d)\n&amp;quot;, rc);
return 0;
}

sys_poweroff();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;By explicitly suspending the I2C device before calling sys_poweroff(), you ensure that the I2C peripheral is properly handled before system shutdown. This aligns with best practices for power management and can help avoid potential issues related to data integrity or power consumption.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>