<?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>Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114839/interruption-when-usb-is-connected</link><description>Hi. 
 Could you please tell me how to trigger an interrupt when changing the USBREGSTATUS register? 
 I can monitor the state of this register in polling mode, but I don&amp;#39;t know how to trigger an interrupt when it changes. Could you please provide a code</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 21 Sep 2024 14:40:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114839/interruption-when-usb-is-connected" /><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503332?ContentTypeID=1</link><pubDate>Sat, 21 Sep 2024 14:40:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbd2e8f8-5298-4b65-be5c-086dc89a798e</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;This ticket can be considered closed.&lt;/p&gt;
&lt;p&gt;I managed to implement USB detection function using NRFX_POWER library and AI Helper on the site)). This solution saved 5% Flash and 20% RAM memory.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you again, Hakon, for your help.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503282?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 13:25:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ebb9d784-893f-4491-8135-6a4253a298a7</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;That would be great.&lt;/p&gt;
&lt;p&gt;Can you please tell me if you have an example of such an implementation?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503281?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 13:23:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3214743-f078-457f-a9ee-c5043e18be51</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use NRFX_POWER for this purpose, this can give you the power events that you&amp;#39;re after with little overhead in terms of RAM/flash usage.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503278?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 13:19:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2036377-d45a-464c-9088-4fec6098be96</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Yeah, that helped. Thank you so much for your help.&lt;/p&gt;
&lt;p&gt;However, such a solution is memory resource intensive, in particular RAM memory (assuming I don&amp;#39;t need to transfer any data over USB, I just need to detect when the charger is connected to the board).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/5428.Memory.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Is it possible to solve this problem by directly accessing registers?&lt;/p&gt;
&lt;p&gt;Would such a solution be more economical in terms of RAM memory?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503268?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 12:42:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fd1bfca-d2c3-46b7-961b-24c599db535a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Try to add this to your board:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/boards/nordic/nrf52833dk/nrf52833dk_nrf52820.dts#L176-L179"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/boards/nordic/nrf52833dk/nrf52833dk_nrf52820.dts#L176-L179&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And remove the build folder and regenerate the project.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503260?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 12:22:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1817cf13-b072-4bfd-b305-c2e26d1535ae</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I am using a custom board based on the nRF52820. &lt;br /&gt;SDK v.2.7.0&lt;br /&gt;Toolchain v.2.7.0&lt;/p&gt;
&lt;p&gt;When building the HID project, I also see errors --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/my_5F00_hid1.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/my_5F00_hid2.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/my_5F00_hid3.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503254?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 11:58:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0dcd285f-01a8-440e-ae00-c24db1a3c71f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I added your prj.conf and src to hello_world, and compiled for board nrf52833dk_nrf52820 without seeing any compiler problems.&lt;/p&gt;
&lt;p&gt;Could you share more information about your build, ie. which board and ncs version that you are using?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you for instance build zephyr/samples/subsys/usb/hid without problems?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503197?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2024 06:09:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03e948da-1e2f-4e53-8a4a-e4298c57c79c</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi Hakon.&amp;nbsp;Thank you for your response with an example.&lt;/p&gt;
&lt;p&gt;But I am not yet able to implement this function in my application.&amp;nbsp;I&amp;#39;m getting errors that I can&amp;#39;t fix.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my code --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/usb/usb_device.h&amp;gt;

#include &amp;lt;zephyr/logging/log.h&amp;gt;
LOG_MODULE_REGISTER(v52820, LOG_LEVEL_DBG);

static void usbd_status(enum usb_dc_status_code cb_status, const uint8_t *param)
{
	switch (cb_status) {
	case USB_DC_CONNECTED:
		LOG_DBG(&amp;quot;USB_DC_CONNECTED&amp;quot;);
		break;
	case USB_DC_DISCONNECTED:
		LOG_DBG(&amp;quot;USB_DC_DISCONNECTED&amp;quot;);
		break;
	default:
		break;
	}
}

int main(void)
{
	int err;

	err = usb_enable(usbd_status);
	if (err) {
		LOG_ERR(&amp;quot;usb_enable: %d&amp;quot;, err);
		return false;
	}

	while (1){
	
		k_msleep(1000);			
	}

	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf file --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_LOG=y
CONFIG_USB_DEVICE_STACK=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here are the errors I see while building the project --&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/err_5F00_1.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/err_5F00_2.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Can you please tell me where I&amp;#39;m making a mistake?&lt;/p&gt;
&lt;p&gt;Does the prj.conf file need to include anything else besides CONFIG_USB_DEVICE_STACK?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interruption when USB is connected</title><link>https://devzone.nordicsemi.com/thread/503115?ContentTypeID=1</link><pubDate>Thu, 19 Sep 2024 11:57:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52dd6ae6-6794-4804-ac5d-9cf5ee818c02</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use the usb_enable function to provide a callback that gives such information:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/86298/nrf52820-usb-connection-detection/360967"&gt;RE: nRF52820 USB connection detection&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example implementation:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.7.0/applications/connectivity_bridge/src/modules/usb_cdc_handler.c#L239"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.7.0/applications/connectivity_bridge/src/modules/usb_cdc_handler.c#L239&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.7.0/applications/connectivity_bridge/src/modules/usb_cdc_handler.c#L148"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.7.0/applications/connectivity_bridge/src/modules/usb_cdc_handler.c#L148&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>