Zephyr bluetooth central sample fails with error -EAGAIN

BT central sample has the following code

bt_enable(NULL);
bt_le_scan_start(SCAN_PASSIVE, device_found);    
I ran the sample on my custom board based on nRF52840 and it always returns -EAGAIN even if I put the bt_le_scan_start in a loop and wait 1000 ms between attempts
I looked in the bt_le_scan_start function in scan.c
It returns -EAGAIN if BT_DEV_READY flag is not set:
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
        return -EAGAIN;
    }
Any ideas why this flag is never set? bt_enable does not return an error and is called synchronously
Project settings
-------------------------
CONFIG_BT=y
CONFIG_BT_CENTRAL=y

CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y

CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_SUBNET_COUNT=1
CONFIG_BT_MESH_APP_KEY_COUNT=1
CONFIG_BT_MESH_MODEL_GROUP_COUNT=2
CONFIG_BT_MESH_ADV_BUF_COUNT=10
CONFIG_BT_MESH_LABEL_COUNT=0
CONFIG_BT_MESH_PB_ADV=n
CONFIG_BT_MESH_CFG_CLI=y
CONFIG_BT_MESH_LOOPBACK_BUFS=8

CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
--------------------------------------------------------
Thank you
Andy
Parents
  • Update

    1. Calling bt_enable from a thread crashes the program - is this expected?

    2.Enabled logging, called from main thread, see this  message after bt_enable

    [00:01:03.757,263] <inf> sdc_hci_driver: SoftDevice Controller build revision:
    0e e7 c5 66 67 18 3c ac b3 d2 cc 81 a3 dc f1 c0 |...fg.<. ........
    c0 36 02 22 |.6."
    [00:01:03.763,702] <inf> bt_hci_core: No ID address. App must call settings_load()

    Perhaps this is a clue.

    Any ideas?

    Thanks

  • Thread was defined as follows

    K_THREAD_DEFINE(comm_task, 1024, comm_task_run, NULL, NULL, NULL,    7, 0, 0);
    I have another thread running that is defined as above and it works fine
    But when I a second thread  I get a crash
    I tried to reduce  the size to 256 but that did not help - same error
    Perhaps that's not the right way - K_THREAD_DEFINE resolves to 
    K_KERNEL_STACK_DEFINE - I'm not sure that I need a supervisor thread in this case. The goal of this task to handle mesh. What's your recommendation ?
Reply
  • Thread was defined as follows

    K_THREAD_DEFINE(comm_task, 1024, comm_task_run, NULL, NULL, NULL,    7, 0, 0);
    I have another thread running that is defined as above and it works fine
    But when I a second thread  I get a crash
    I tried to reduce  the size to 256 but that did not help - same error
    Perhaps that's not the right way - K_THREAD_DEFINE resolves to 
    K_KERNEL_STACK_DEFINE - I'm not sure that I need a supervisor thread in this case. The goal of this task to handle mesh. What's your recommendation ?
Children
  • Hi Andy, 


    Could you provide a simplified example that we can test here ? 
    I tried with the ble_peripheral_lbs_coex and didn't see the issue. 
    I replaced main() function with this: 


    #define STACKSIZE 1024
    void ble_write_thread(void)
    {	int err;
    
    	printk("Thread..\n");
    
    	err = bt_enable(bt_ready);
    	if (err) {
    		printk("Bluetooth init failed (err %d)\n", err);
    	}
    
    }
    void blink_LED(void)
    {	
    
    	for (;;) {
    		printk("LED\n");
    		k_sleep(K_MSEC(1000));
    	}
    
    
    }
    K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
    		NULL, 7, 0, 0);
    K_THREAD_DEFINE(blink_LED_id, STACKSIZE, blink_LED, NULL, NULL,
    		NULL, 7, 0, 0);

Related