<?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>nrf5340 zephyr blink not waking from sleep</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81993/nrf5340-zephyr-blink-not-waking-from-sleep</link><description>Hello, 
 I am currently trying to get a slightly modified version of the blink example from zephyr to work on the nrf5340. 
 As you can see below, I am starting two threads, one for the input button and one for the LED, and as soon as the LED thread is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 23 Nov 2021 05:11:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81993/nrf5340-zephyr-blink-not-waking-from-sleep" /><item><title>RE: nrf5340 zephyr blink not waking from sleep</title><link>https://devzone.nordicsemi.com/thread/340221?ContentTypeID=1</link><pubDate>Tue, 23 Nov 2021 05:11:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9def90d7-c9b2-4463-b36f-dfc7e4ad9fc7</guid><dc:creator>GatCode</dc:creator><description>&lt;p&gt;Aaah thank you very much! This makes sense!&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve adjusted the sample program now and it works as expected.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;sys/__assert.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

/* size of stack area used by each thread */
#define STACKSIZE 1024

/* scheduling priority used by each thread */
#define PRIORITY 7

#define LED_NODE DT_ALIAS(led0)
#define BUTTON_NODE DT_ALIAS(sw0)

struct led {
	struct gpio_dt_spec spec;
	const char *gpio_pin_name;
};

struct button {
	struct gpio_dt_spec spec;
	struct gpio_callback cb_data;
	const char *gpio_pin_name;
};

static struct led led = {
	.spec = GPIO_DT_SPEC_GET_OR(LED_NODE, gpios, {0}),
	.gpio_pin_name = DT_PROP_OR(LED_NODE, label, &amp;quot;&amp;quot;),
};

static struct button button = {
	.spec = GPIO_DT_SPEC_GET_OR(BUTTON_NODE, gpios, {0}),
	.gpio_pin_name = DT_PROP_OR(BUTTON_NODE, label, &amp;quot;&amp;quot;),
};

void blink(const struct led *led, uint32_t sleep_ms, uint32_t id)
{
	gpio_pin_configure_dt(&amp;amp;led-&amp;gt;spec, GPIO_OUTPUT);

	while (1) {
		gpio_pin_set_dt(&amp;amp;led-&amp;gt;spec, 1);
		k_msleep(sleep_ms);
		
		gpio_pin_set_dt(&amp;amp;led-&amp;gt;spec, 0);
		k_msleep(sleep_ms);
	}
}

void blinkThread(void)
{
	blink(&amp;amp;led, 100, 0);
}

void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	printk(&amp;quot;Button pressed at %&amp;quot; PRIu32 &amp;quot;\n&amp;quot;, k_cycle_get_32());
}

void inputThread(void)
{
	gpio_pin_configure_dt(&amp;amp;button.spec, GPIO_INPUT);
	gpio_pin_interrupt_configure_dt(&amp;amp;button.spec, GPIO_INT_EDGE_TO_ACTIVE);

	gpio_init_callback(&amp;amp;button.cb_data, button_pressed, BIT(button.spec.pin));
	gpio_add_callback(button.spec.port, &amp;amp;button.cb_data);
}

K_THREAD_DEFINE(blinkThread_id, STACKSIZE, blinkThread, NULL, NULL, NULL,
		PRIORITY, 0, 0);
K_THREAD_DEFINE(inputThread_id, STACKSIZE, inputThread, NULL, NULL, NULL,
		PRIORITY, 0, 0);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 zephyr blink not waking from sleep</title><link>https://devzone.nordicsemi.com/thread/340204?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 22:11:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b6ae8d2-65a6-4931-b51c-4f6b0178b1aa</guid><dc:creator>smackenzie</dc:creator><description>&lt;p&gt;`inputThread` is infinitely calling a blocking function (gpio_pin_get), so no other events can be processed. Use button interupts f if you want to detect when a button is pressed without blocking.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;samples\basic\button has an example on how to do this with `gpio_init_callback`.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>