ASSERTION FAIL Error Issue

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.

void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	int err;
	
	if(BIT(button.pin) & pins)
	{
		if(gpio_pin_get_dt(&button))
		{
			button_pressed_var = !button_pressed_var;
            if(button_pressed_var)
			{
				err = bt_disable();
				if (err) {
					LOG_ERR("Bluetooth init failed (err %d)", err);
					return -1;
				}

				"or"

				err = bt_le_adv_stop();
    			if (err) {
       				 printk("Failed to stop advertising (err %d)\n", err);
				}
				printk("device Off: \n");
			}
			else
			{
				 err = bt_enable(NULL);
				 if (err) {
			     	LOG_ERR("Bluetooth init failed (err %d)", err);
				 	return -1;
				 }				
				 printk("device On: \n");
			}

		}
	}
            /* Button changed its state to pressed */
 
	
}
/* STEP 5 - Define a variable of type static struct gpio_callback */
static struct gpio_callback button_cb_data;

I got below error.

ASSERTION FAIL [err == 0] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/hci_core.c:331
        command opcode 0x200a timeout with err -11
[00:00:06.575,561] <err> os: r0/a1:  0x00000003  r1/a2:  0x00000000  r2/a3:  0x00000002
[00:00:06.575,592] <err> os: r3/a4:  0x20001758 r12/ip:  0x00000010 r14/lr:  0x0001260d
[00:00:06.575,592] <err> os:  xpsr:  0x41000016
[00:00:06.575,592] <err> os: Faulting instruction address (r15/pc): 0x00012618
[00:00:06.575,653] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
[00:00:06.575,653] <err> os: Fault during interrupt handling

[00:00:06.575,683] <err> os: Current thread: 0x200027f8 (unknown)


How to disable BLE or stop the BLE advertising when i press the button and gain I press the button How to advertise BLE 

I am searched lot of dev tickets everything is related to nrfSDK.

Please help on this.

Thank you in advance.

Parents
  • Hello,

    Are you disabling the BLE again and again? I mean in the else condition?

    How about setting a flag in the button_pressed() and doing processing in the main based on that flag.

  • Are you disabling the BLE again and again? I mean in the else condition?

    No, only in if statement.

    button_pressed() function is a callback function for button interrupt.

  • I see in line 28 that you are calling bt-enable within that callback.

    Do you mind setting a flag in the callback and processing in the main.

    I can have a look if you let me know how to reproduce the issue you are facing (minimal code please). 

  • struct k_timer mytimer;
    /* timer call back function */
    static void my_timer(struct k_timer *dummy)
    {
        if(gpio_pin_get_dt(&button))
        {
                button_pressed_var = !button_pressed_var;
                if(button_pressed_var)
                {
                    printk("device Off: \n");
                    /* Here I want to Stop the advertising*/
                }
                else
                {
                   /* Here I want to Start the advertising*/
                    printk("device On: \n");
                }
                k_timer_stop(&mytimer);
        }
    
    }
    
    /*Button call back function */
    void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
        if(BIT(button.pin) & pins)
        {
            if(gpio_pin_get_dt(&button))
            {
                k_timer_start(&mytimer, K_SECONDS(2), K_NO_WAIT);
    
            }
        }
       
    }
    /*Define a variable of type static struct gpio_callback */
    static struct gpio_callback button_cb_data;
    
    void main()
    {
        /* Configure the interrupt on the button's pin */
        ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE );
    
        /* Initialize the static struct gpio_callback variable   */
        gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));  
       
        /* Add the callback function by calling gpio_add_callback()   */
        gpio_add_callback(button.port, &button_cb_data);
    
    }

    Minimal code

    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.

    In Off state I want to stop the Advertisement using bt_le_adv_stop() .
    In on state I want to start the advertisement again 

    If any suggestion to optimize the power its very helpful to me 

    Thank you in advance.
Reply
  • struct k_timer mytimer;
    /* timer call back function */
    static void my_timer(struct k_timer *dummy)
    {
        if(gpio_pin_get_dt(&button))
        {
                button_pressed_var = !button_pressed_var;
                if(button_pressed_var)
                {
                    printk("device Off: \n");
                    /* Here I want to Stop the advertising*/
                }
                else
                {
                   /* Here I want to Start the advertising*/
                    printk("device On: \n");
                }
                k_timer_stop(&mytimer);
        }
    
    }
    
    /*Button call back function */
    void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
        if(BIT(button.pin) & pins)
        {
            if(gpio_pin_get_dt(&button))
            {
                k_timer_start(&mytimer, K_SECONDS(2), K_NO_WAIT);
    
            }
        }
       
    }
    /*Define a variable of type static struct gpio_callback */
    static struct gpio_callback button_cb_data;
    
    void main()
    {
        /* Configure the interrupt on the button's pin */
        ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE );
    
        /* Initialize the static struct gpio_callback variable   */
        gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));  
       
        /* Add the callback function by calling gpio_add_callback()   */
        gpio_add_callback(button.port, &button_cb_data);
    
    }

    Minimal code

    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.

    In Off state I want to stop the Advertisement using bt_le_adv_stop() .
    In on state I want to start the advertisement again 

    If any suggestion to optimize the power its very helpful to me 

    Thank you in advance.
Children
No Data
Related