<?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>ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112757/assertion-fail-error-issue</link><description>Hello! I am working on nrf52840 NCS 2.6.0v I Configured the button to generate an interrupt every time it is pressed. Then, inside the interrupt handler (callback function) of the button I wrote below function. 
 
 I got below error. 
 How to disable</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 26 Jul 2024 08:44:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112757/assertion-fail-error-issue" /><item><title>RE: ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/thread/495768?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 08:44:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1b962b9-122a-4114-81cd-ac06d62bd005</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Basam,&lt;/p&gt;
&lt;p&gt;Apologies for the delayed response due to high work load these days.&lt;/p&gt;
&lt;p&gt;Nonetheless, I suggest you not to enable and disable the advertising directly in the button handler, but rather set a flag and submit a work-item, and based on the state of flag the work-handler should enable or disable the advertising. This is so that the button handler should return immediately and any time consuming work is off-loaded to the work-queue. You can do something like this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	buttonflag = !buttonflag;
	printk(&amp;quot;Button pressed at %&amp;quot; PRIu32 &amp;quot;\n&amp;quot;, k_cycle_get_32());
	k_work_submit(&amp;amp;mywork);
}
//===========================================================
/* Work handler function */
void work_handler(struct k_work *work) {
    int err;
	if (buttonflag == 1 )
	{
		printk(&amp;quot;Button Pressed to start advertising\n&amp;quot;);
		err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),sd, ARRAY_SIZE(sd));
		if (err) {printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);return;}
	}
	else
	{
		printk(&amp;quot;Button Pressed to stop advertising\n&amp;quot;);
		err = bt_le_adv_stop();
		if (err) {printk(&amp;quot;Advertising failed to stop (err %d)\n&amp;quot;, err);return;}
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;where work_handler function will be invoked when a work is submitted to mywork struct.&lt;/p&gt;
&lt;p&gt;you may find&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/kernel/services/threads/workqueue.html"&gt;WorkQueues&lt;/a&gt;&amp;nbsp;also useful while doing this.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/thread/493798?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 05:42:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8a0b78a-534d-4e48-a218-6784645e06e1</guid><dc:creator>Madhu Mohan Reddy</dc:creator><description>&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;struct k_timer mytimer;
/* timer call back function */
static void my_timer(struct k_timer *dummy)
{
&amp;#160; &amp;#160; if(gpio_pin_get_dt(&amp;amp;button))
&amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; button_pressed_var = !button_pressed_var;
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; if(button_pressed_var)
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;device Off: \n&amp;quot;);
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; /* Here I want to Stop the advertising*/
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; }
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; else
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; {
&amp;#160;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; /* Here I want to Start the advertising*/
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;device On: \n&amp;quot;);
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; }
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; k_timer_stop(&amp;amp;mytimer);
&amp;#160; &amp;#160; }

}

/*Button call back function */
void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
&amp;#160; &amp;#160; if(BIT(button.pin) &amp;amp; pins)
&amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; if(gpio_pin_get_dt(&amp;amp;button))
&amp;#160; &amp;#160; &amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; k_timer_start(&amp;amp;mytimer, K_SECONDS(2), K_NO_WAIT);

&amp;#160; &amp;#160; &amp;#160; &amp;#160; }
&amp;#160; &amp;#160; }
&amp;#160; &amp;#160;
}
/*Define a variable of type static struct gpio_callback */
static struct gpio_callback button_cb_data;

void main()
{
&amp;#160; &amp;#160; /* Configure the interrupt on the button&amp;#39;s pin */
&amp;#160; &amp;#160; ret = gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_EDGE_TO_ACTIVE );

&amp;#160; &amp;#160; /* Initialize the static struct gpio_callback variable &amp;#160; */
&amp;#160; &amp;#160; gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin)); &amp;#160;
&amp;#160; &amp;#160;
&amp;#160; &amp;#160; /* Add the callback function by calling gpio_add_callback() &amp;#160; */
&amp;#160; &amp;#160; gpio_add_callback(button.port, &amp;amp;button_cb_data);

}&lt;/pre&gt;&lt;br /&gt;Minimal code&lt;br /&gt;&lt;br /&gt;Above code is Power Button Implementation when i pressed one time the device is off and when i pressed again the device is switched on.&lt;br /&gt;&lt;br /&gt;In Off state I want to stop the Advertisement using&amp;nbsp;bt_le_adv_stop() .&lt;br /&gt;In on state I want to start the advertisement again&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If any suggestion to optimize the power its very helpful to me&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thank you in advance.&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/thread/493521?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 20:31:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0e4c925-c3fc-44a8-968b-4f64ec4e2bf4</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;I see in line 28 that you are calling bt-enable within that callback.&lt;/p&gt;
&lt;p&gt;Do you mind setting a flag in the callback and processing in the main.&lt;/p&gt;
&lt;p&gt;I can have a look if you let me know how to reproduce the issue you are facing (minimal code please).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/thread/492875?ContentTypeID=1</link><pubDate>Tue, 09 Jul 2024 07:03:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df2a2689-349c-4be8-98f4-69d1d9219cdd</guid><dc:creator>Madhu Mohan Reddy</dc:creator><description>[quote userid="119245" url="~/f/nordic-q-a/112757/assertion-fail-error-issue/492701"]Are you disabling the BLE again and again? I mean in the else condition?[/quote]
&lt;p&gt;No, only in if statement.&lt;br /&gt;&lt;br /&gt;button_pressed() function is a callback function for button interrupt.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ASSERTION FAIL Error Issue</title><link>https://devzone.nordicsemi.com/thread/492701?ContentTypeID=1</link><pubDate>Mon, 08 Jul 2024 12:35:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d759bc32-bcff-477c-b8cd-4d986deb520e</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Are you disabling the BLE again and again? I mean in the else condition?&lt;/p&gt;
&lt;p&gt;How about setting a flag in the button_pressed() and doing processing in the main based on that flag.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>