<?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>Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/111683/subscribing-to-power-manager-events</link><description>Hi! 
 I am trying to subscribe to the power management events that correspond to the following log lines (which I can clearly see in the log): 
 I have been trying with this code: 
 
 I have extended prj.conf with: 
 Results: 
 
 - &amp;quot;Power Init&amp;quot; is getting</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 08 Jun 2024 21:54:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/111683/subscribing-to-power-manager-events" /><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/487986?ContentTypeID=1</link><pubDate>Sat, 08 Jun 2024 21:54:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ae0f76a-c509-4564-a9eb-1899d88b61e6</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;In case anyone comes across this, our usb expert has discovered following solution:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if ((NRF_POWER-&amp;gt;USBREGSTATUS &amp;amp; POWER_USBREGSTATUS_VBUSDETECT_Msk) == POWER_USBREGSTATUS_VBUSDETECT_VbusPresent) {
    printk(&amp;quot;USB power available\n&amp;quot;);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Source: 5.3.7.5 of &lt;a href="https://infocenter.nordicsemi.com/pdf/nRF52840_PS_v1.0.pdf"&gt;infocenter.nordicsemi.com/.../nRF52840_PS_v1.0.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s not perfect, since we would like to also have a callback that notifies us of changes... but so far seems to work reliably.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/487073?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2024 10:25:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a406c7f-dd56-480e-a826-8c9d221a6514</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;Acually, we collaborate with c2usb&amp;#39;s creator, so as to its modifications, we should be fairly flexible. (I just didn&amp;#39;t realize at first that this is a usb driver/stack issue.) (In this respect, feel free to give just a few pointers and tell me to delegate it to him...)&lt;/p&gt;
&lt;p&gt;In the meanwhile, I have tested Benedek&amp;#39;s amend of c2usb, which forwards on some kind of power-related usb events. Maybe the code below tells you more (if not, no worries). Unfortunatelly, it often reports states that are irrelevant to the actual power state.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    usb_manager()
    {
        device_.set_power_event_delegate([](usb::df::device &amp;amp;dev, usb::df::device::event ev) {
            using event = enum usb::df::device::event;
            switch (ev) {
            case event::CONFIGURATION_CHANGE:
                printk(&amp;quot;USB configured: %u, granted current: %uuA\n&amp;quot;, dev.configured(), dev.granted_bus_current_uA()); 
                break;
            case event::POWER_STATE_CHANGE:
                printk(&amp;quot;USB power state: L%u, granted current: %uuA\n&amp;quot;, 3 - static_cast&amp;lt;uint8_t&amp;gt;(dev.power_state()), dev.granted_bus_current_uA());
                break;
            }
        });
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Which further points to &lt;a href="https://github.com/IntergatedCircuits/c2usb/blob/f66b167da9a35be83ad32a16b0a8bc77f52b8e86/c2usb/i2c/hid/device.hpp#L63"&gt;github.com/.../device.hpp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unlike above benedek&amp;#39;s code, the POWER events in the log seem fairly reliable, except...&lt;/p&gt;
&lt;p&gt;When the board is restarted, we get no callback from Benedek&amp;#39;s code, neither the POWER event ready event shows up in the log.&lt;/p&gt;
&lt;p&gt;So what we need is to also figure a way to explicitly inquire for the power state...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/487071?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2024 10:05:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f3c6bc8-40a8-4e74-8af3-2d1fb0ccfbb9</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;My bad.&amp;nbsp;I didn&amp;#39;t realize that the said function is not available in the current release as I was looking at the latest documentation. Also, I confused the USB device stack API with the USB device controller driver APIs. As far as I can tell, the c2usb library is only using the latter. Either way, I have not found anyone who are familiar with the&amp;nbsp;&lt;span&gt;c2usb library internally, so I&amp;#39;m not sure if there is any easy way to get it to propagate USB state events to the application.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The nRF Connect SDK includes this fork of Zephyr: &lt;a href="https://github.com/nrfconnect/sdk-zephyr"&gt;https://github.com/nrfconnect/sdk-zephyr&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/dev_model_and_contributions/code_base.html#dm-code-base"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/dev_model_and_contributions/code_base.html#dm-code-base&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486957?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 18:15:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6269225d-3fd3-4fee-a5d0-463213fcad97</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;Well, sorry, I am confused, especially as to the anatomy of the zephyr ecosystem and its .release cycle&lt;/p&gt;
&lt;p&gt;Where exactly am I supposed to obtain `usbd_msg_register_cb`?&lt;/p&gt;
&lt;p&gt;Clearly, usbd_msg_register_cb is defined in the `sdk-zephyr` repository master branch, however is not part of the sdk-zephyr repository that I have installed via nrfutil. It seems to be part of some *future* release. I am not sure if it is possible for me to get development version - I have certainly not found instructions on how to anywhere. Just checking out main branch in the repository leads to a large number of kconfig errors...&lt;/p&gt;
&lt;p&gt;Part of what I am confused about is that zephyr sdk is said to not be part of nrf connect sdk, and has listed separate installation instructions. Yet sdk-zephyr is installed during the nrf connect sdk toolchain installation process. Is sdk-zephyr not zephyr sdk? The fact that installation guide points to &lt;a href="https://github.com/zephyrproject-rtos/sdk-ng"&gt;github.com/.../sdk-ng&lt;/a&gt; rather than &lt;a id="" href="https://github.com/nrfconnect/sdk-zephyr"&gt;https://github.com/nrfconnect/sdk-zephyr&lt;/a&gt; suggests that too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486943?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 14:35:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73506951-1d16-4217-baef-363c4ea1932c</guid><dc:creator>Vidar Berg</dc:creator><description>[quote userid="131124" url="~/f/nordic-q-a/111683/subscribing-to-power-manager-events/486941"](I assume you mean when some version that compiles is released.)[/quote]
&lt;p&gt;Sorry, I&amp;#39;m not sure I follow. Are you talking about an internal release on your end?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486941?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 14:30:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a243687f-48a5-4f0b-a87e-4010ee96a2f4</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;(I assume you mean when some version that compiles is released.)&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486915?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 12:57:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:485c4221-21c7-455d-b9f1-4fa2068348cf</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;In that case, it looks like you should be using this function:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/connectivity/usb/device_next/api/usbd.html#c.usbd_msg_register_cb"&gt;https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/connectivity/usb/device_next/api/usbd.html#c.usbd_msg_register_cb&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486913?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 12:55:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:313e8212-1945-4249-9d68-ed44d09a32e5</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;I see. &lt;br /&gt;&lt;br /&gt;Our project uses c2usb to handle USB, that in turn uses zephyr&amp;#39;s udc. As a result, using usb_enable directly is not possible (it results in multiple registrations for irq 39). I guess I shall delegate this on our usb expert.&lt;br /&gt;&lt;br /&gt;If you have any further comments, they are welcome, otherwise I consider this solved.&lt;br /&gt;&lt;br /&gt;Thanks for help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486891?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 11:58:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3faf74ca-a5a1-44b2-ab30-96e7480c0483</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;It&amp;#39;s probably from the USB stack here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/1fa31bbc30a3e501a3d6dfce978128a03e61b1e3/drivers/usb/udc/udc_nrf.c#L383"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/1fa31bbc30a3e501a3d6dfce978128a03e61b1e3/drivers/usb/udc/udc_nrf.c#L383&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can pass a callback function to the usb_enable() function if you want to monitor USB events in your app.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/connectivity/usb/device/api/usb_device.html#c.usb_enable"&gt;https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/connectivity/usb/device/api/usb_device.html#c.usb_enable&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486887?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 11:50:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c3a6320-0aee-42ab-aa09-0ade2eced3ed</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;I see.&lt;/p&gt;
&lt;p&gt;So where do the mentioned POWER log lines come from?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;I: POWER event ready
I: POWER event removed&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486877?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 11:16:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:448f9b4d-68f1-4d7a-b033-0357837ca7bd</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for the clarification. pm_notifier_register(), which isn&amp;#39;t supported for the nRF series,&amp;nbsp; is used to register callbacks for when the chip is entering and exiting sleep. It doesn&amp;#39;t tell you if the chip is battery or mains powered.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486851?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 10:02:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c37686c-2623-4b1a-b61e-0e6392950a52</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;&amp;gt; However, I assumed you had reverted the changes from the commit&lt;/p&gt;
&lt;p&gt;No.&lt;/p&gt;
&lt;p&gt;&amp;gt; Could you say a bit more about what you are trying to acheive?&lt;/p&gt;
&lt;p&gt;I would like to know whether the device is running on battery, so that I can adjust power-consumption-related features. E.g., decrease intensity of led lights, or turning them off after some timeout.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486849?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 09:56:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fd998a7-d09f-4752-852e-df59248fda7e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The warning indicates that CONFIG_PM can&amp;#39;t be enabled due to missing dependencies (HAS_PM), which is expected since we have removed PM support. However, I assumed you had reverted the changes from the commit since the pm_notifier_register() function definition was included in your build (pm.c, which implements this function, should only be included if CONFIG_PM is selected).&lt;/p&gt;
&lt;p&gt;Since PM is not supported, I would&amp;nbsp;recommend that you look at other alternatives to acheive what you want. Could you say a bit more about what you are trying to acheive? From the thread analyzer you can see that your application is spending 72% of the time in sleep (SYSTEM ON).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486847?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 09:45:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ff7196c-0b4c-4a7d-9b7f-878808d30977</guid><dc:creator>kat829</dc:creator><description>&lt;p&gt;Well, as for warnings, I am getting this, but to tell the truth I find it rather unintelligible and the &amp;quot;see ...&amp;quot; section is not very helpful:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;warning: PM (defined at soc/arm/silabs_exx32/efr32bg22/Kconfig.defconfig.series:18,
soc/arm/silabs_exx32/efr32bg27/Kconfig.defconfig.series:18,
soc/arm/silabs_exx32/efr32mg24/Kconfig.defconfig.series:19,
soc/arm/st_stm32/stm32f4/Kconfig.defconfig.series:20, subsys/pm/Kconfig:13) was assigned the value
&amp;#39;y&amp;#39; but got the value &amp;#39;n&amp;#39;. Check these unsatisfied dependencies: ((SOC_SERIES_EFR32BG22 &amp;amp;&amp;amp;
SOC_FAMILY_EXX32) || (SOC_SERIES_EFR32BG27 &amp;amp;&amp;amp; SOC_FAMILY_EXX32) || (SOC_SERIES_EFR32MG24 &amp;amp;&amp;amp;
SOC_FAMILY_EXX32) || SOC_SERIES_STM32F4X || (SYS_CLOCK_EXISTS &amp;amp;&amp;amp; HAS_PM)) (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_PM and/or look up PM in the
menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
and Kconfig - Tips and Best Practices sections of the manual might be helpful too.&lt;/pre&gt;&lt;br /&gt;The relevant excerpt from `kernel threads` and thread analyzer logs (after adding some `CONFIG_THREAD_ANALYZER` options) is:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;$kernel threads 

...

 0x2000cfc0 idle
        options: 0x1, priority: 15 timeout: 0
        state: , entry: 0x5e245
        Total execution cycles: 999756 (72 %)
        stack size 320, unused 272, usage 48 / 320 (15 %)

 0x2000d098 main
        options: 0x1, priority: 0 timeout: 17
        state: suspended, entry: 0x5d731
        Total execution cycles: 193498 (14 %)
        stack size 2048, unused 1128, usage 920 / 2048 (44 %)

...

Thread analyze:
 idle                : STACK: unused 272 usage 48 / 320 (15 %); CPU: 73 %
      : Total CPU cycles used: 1442089
 main                : STACK: unused 1128 usage 920 / 2048 (44 %); CPU: 13 %
      : Total CPU cycles used: 271937
 ISR0                : STACK: unused 904 usage 1144 / 2048 (55 %)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Based on this I would say that yes it is allowed to run.&lt;/p&gt;
&lt;p&gt;(I have removed other threads since they are a potentially sensitive information.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to power manager events.</title><link>https://devzone.nordicsemi.com/thread/486810?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 08:11:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79469d1f-fc6d-4c18-96e2-38d679af164a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Support for the PM subsystem (CONFIG_PM, not CONFIG_PM_DEVICE) was removed in SDK v2.5.0 by this commit:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/commit/96b38273138f05dd06cf7a58fa361f401e773e5e"&gt;https://github.com/nrfconnect/sdk-zephyr/commit/96b38273138f05dd06cf7a58fa361f401e773e5e&lt;/a&gt;. So, unless you have reverted this change, you should&amp;nbsp;be getting&amp;nbsp;a Kconfig warning in your build output stating that&amp;nbsp;the&amp;nbsp;&lt;span&gt;CONFIG_PM symbol&lt;/span&gt; did not end up being selected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Does&amp;nbsp;this application&amp;nbsp;allow&amp;nbsp;the idle thread to be run?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>