<?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>When adding button interrupt to &amp;quot;chat&amp;quot; exmaple, the system crashed.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105773/when-adding-button-interrupt-to-chat-exmaple-the-system-crashed</link><description>Toolchain : nRF Connect SDK V2.3.0 
 Board : PCA10056 
 IC : nRF52840 
 
 We copy a &amp;quot;chat&amp;quot; example from nrf/samples/bluetooth/mesh/chat 
 
 After building and flashing it into PCA10056, we can use android app &amp;quot;Nordic nRF Mesh&amp;quot; to provision PCA10056 into</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 20 Nov 2023 02:59:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105773/when-adding-button-interrupt-to-chat-exmaple-the-system-crashed" /><item><title>RE: When adding button interrupt to "chat" exmaple, the system crashed.</title><link>https://devzone.nordicsemi.com/thread/456304?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 02:59:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c184a765-21b3-4056-8185-b028518321cf</guid><dc:creator>Zhong Tom</dc:creator><description>&lt;p&gt;Hi Hung,&lt;br /&gt;&lt;br /&gt;I upgrade ncs version from 2.3.0 to 2.5.0.&lt;br /&gt;The issue fixed, thanks for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When adding button interrupt to "chat" exmaple, the system crashed.</title><link>https://devzone.nordicsemi.com/thread/456189?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 14:15:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbbf999a-7743-4ca3-ac58-c89f3ae11dcf</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zhong,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see a problem with that. As long as you don&amp;#39;t call any Bluetooth API in the interrupt handler.&amp;nbsp;&lt;br /&gt;I did a quick test here with the chat sample (NCS v2.5.0) and I didn&amp;#39;t see any problem.&amp;nbsp;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1700230444982v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;main.c :&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Nordic Mesh light sample
 */
#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/mesh/models.h&amp;gt;
#include &amp;lt;bluetooth/mesh/dk_prov.h&amp;gt;
#include &amp;lt;dk_buttons_and_leds.h&amp;gt;
#include &amp;quot;model_handler.h&amp;quot;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/sys/util.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
LOG_MODULE_REGISTER(chat, CONFIG_LOG_DEFAULT_LEVEL);
#define SW0_NODE    DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
#error &amp;quot;Unsupported board: sw0 devicetree alias is not defined&amp;quot;
#endif

static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0});
static struct gpio_callback button_cb_data;

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());
}

static void bt_ready(int err)
{
	if (err) {
		printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
		return;
	}

	printk(&amp;quot;Bluetooth initialized\n&amp;quot;);

	dk_leds_init();
	dk_buttons_init(NULL);

	err = bt_mesh_init(bt_mesh_dk_prov_init(), model_handler_init());
	if (err) {
		printk(&amp;quot;Initializing mesh failed (err %d)\n&amp;quot;, err);
		return;
	}

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	/* This will be a no-op if settings_load() loaded provisioning info */
	bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT);

	printk(&amp;quot;Mesh initialized\n&amp;quot;);
}

int main(void)
{
	int err;
  	int ret;
	printk(&amp;quot;Initializing...\n&amp;quot;);
	err = bt_enable(bt_ready);
	if (err) {
		printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
	}
   	if (!gpio_is_ready_dt(&amp;amp;button)) {
        printk(&amp;quot;Error: button device %s is not ready\n&amp;quot;,
               button.port-&amp;gt;name);
        return 0;
    }

    ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
    if (ret != 0) {
        printk(&amp;quot;Error %d: failed to configure %s pin %d\n&amp;quot;,
               ret, button.port-&amp;gt;name, button.pin);
        return 0;
    }
 
    ret = gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_EDGE_TO_ACTIVE);
   
    if (ret != 0) {
        printk(&amp;quot;Error %d: failed to configure interrupt on %s pin %d\n&amp;quot;,
            ret, button.port-&amp;gt;name, button.pin);
        return 0;
    }

    gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin));
    gpio_add_callback(button.port, &amp;amp;button_cb_data);


	

	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Could you please test ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you plan to call BLE function inside a the handler, you would need to use work queue instead. Or you can use the dk_buttons library like in our peripheral_lbs sample.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>