This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble_advertising_evt_handler_t doesn't get called

After flashing softdevice, the ble_advertising_evt_handler_t doesn't get called, only after flashing the program for the 4th time.

/**@brief Function for initializing advertising module.
 */
static void ble_advertise_init(void) {
	ble_advdata_t advdata;
	ble_adv_modes_config_t options;

	// Build advertising data struct to pass into @ref ble_advertising_init.
	memset(&advdata, 0, sizeof(advdata));

	advdata.name_type = BLE_ADVDATA_FULL_NAME;
	advdata.include_appearance = true;
	advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

	memset(&options, 0, sizeof(options));
	options.ble_adv_fast_enabled = true;
	options.ble_adv_fast_interval = APP_ADV_INTERVAL;
	options.ble_adv_fast_timeout = 0;

	APP_ERROR_CHECK(ble_advertising_init(&advdata, NULL, &options, ble_on_advertising_evt, NULL));
}

/**@brief Function for starting the advertising.
 */
static void ble_advertise_start(void) {
	ret_code_t err_code;
	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
	if(err_code != NRF_SUCCESS){
		APP_ERROR_CHECK(err_code);
	}
}

Does anyone had this problem, or have any idea how to solve it?

Parents
  • I had the same problem and solved it.

    As stated in the comments, you were using the FDS module, as were I.

    As seen in the Infocenter, the FDS/Fstorage rely in the SoftDevice system callbacks to ensure that a read/write ended.

    In my code, I was calling the fds_init() before initializing the SD so no system callback was passed to fstorage. When initializing the FDS right after a new erase/flash, it has to install a new filesystem so it queues some operations in fstorage that are never marked as executed since the module is waiting for a callback that never comes... But the flash is written anyway.

    Flashing lots of times/resets will execute all operations in each run until the FDS marks the filesystem as ok and doesn't queue operations in fstorage.

    The ble_advertising uses fs_queued_op_count_get() to check for flash operation. This function checks the queue size of fstorage so this leads to a deadlock due to the previously queued operations.

    So make sure you init FDS after the SoftDevice to ensure proper operation of all modules.

    Check too that, in you SoftDevice system handler, you propagate the event to the fstorage first. If you change the order, this too can lead to a deadlock:

    /**@brief Callback for the System events
    */
    static void ble_on_sys_evt(uint32_t sys_evt){
        fs_sys_event_handler(sys_evt);          //Propagate event to Flash Storage Library
        ble_advertising_on_sys_evt(sys_evt);	//Propagate event to Advertising module
    }
    

    Cheers,

    João

Reply
  • I had the same problem and solved it.

    As stated in the comments, you were using the FDS module, as were I.

    As seen in the Infocenter, the FDS/Fstorage rely in the SoftDevice system callbacks to ensure that a read/write ended.

    In my code, I was calling the fds_init() before initializing the SD so no system callback was passed to fstorage. When initializing the FDS right after a new erase/flash, it has to install a new filesystem so it queues some operations in fstorage that are never marked as executed since the module is waiting for a callback that never comes... But the flash is written anyway.

    Flashing lots of times/resets will execute all operations in each run until the FDS marks the filesystem as ok and doesn't queue operations in fstorage.

    The ble_advertising uses fs_queued_op_count_get() to check for flash operation. This function checks the queue size of fstorage so this leads to a deadlock due to the previously queued operations.

    So make sure you init FDS after the SoftDevice to ensure proper operation of all modules.

    Check too that, in you SoftDevice system handler, you propagate the event to the fstorage first. If you change the order, this too can lead to a deadlock:

    /**@brief Callback for the System events
    */
    static void ble_on_sys_evt(uint32_t sys_evt){
        fs_sys_event_handler(sys_evt);          //Propagate event to Flash Storage Library
        ble_advertising_on_sys_evt(sys_evt);	//Propagate event to Advertising module
    }
    

    Cheers,

    João

Children
No Data
Related