Soft Device Scan Parms not being set correctly from struct

I set my scan params in the following init code.

 

/**@brief Function for initializing the scanning and setting the filters.
 */
static void scan_init(void)
{   
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;
    ble_gap_scan_params_t const m_scan_param =
    {
      .active        = 0x01,
      .interval      = NRF_BLE_SCAN_SCAN_INTERVAL,
      .window        = NRF_BLE_SCAN_SCAN_WINDOW,
      .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL, //BLE_GAP_SCAN_FP_WHITELIST,
      .timeout       = 0,
      .scan_phys     = BLE_GAP_PHY_1MBPS,
    };

    memset(&init_scan, 0, sizeof(init_scan));
    /**< Scan parameters requested for scanning and connection. */
    init_scan.p_scan_param     = &m_scan_param;
    init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

}

The interval and scan window are both set to 100. However, when I watch the variables in debug mode, the variables are as follows. 

Any idea how they are being set so wrong? No other references to these variables in the code anywhere except here and when I start scanning following the advertising period ending (60 seconds).

Parents Reply Children
  •   I made this change to nrf_ble_scan.h line 289 - 306 by adding __attribute__((packed))

    /**@brief Scan module instance. Options for the different scanning modes.
    *
    * @details This structure stores all module settings. It is used to enable or disable scanning modes
    * and to configure filters.
    */
    typedef struct
    {
    #if (NRF_BLE_SCAN_FILTER_ENABLE == 1)
    nrf_ble_scan_filters_t scan_filters; /**< Filter data. */
    #endif
    bool connect_if_match; /**< If set to true, the module automatically connects after a filter match or successful identification of a device from the whitelist. */
    ble_gap_conn_params_t conn_params; /**< Connection parameters. */
    uint8_t conn_cfg_tag; /**< Variable to keep track of what connection settings will be used if a filer match or a whitelist match results in a connection. */
    ble_gap_scan_params_t scan_params; /**< GAP scanning parameters. */
    nrf_ble_scan_evt_handler_t evt_handler; /**< Handler for the scanning events. Can be initialized as NULL if no handling is implemented in the main application. */
    uint8_t scan_buffer_data[NRF_BLE_SCAN_BUFFER]; /**< Buffer where advertising reports will be stored by the SoftDevice. */
    ble_data_t scan_buffer; /**< Structure-stored pointer to the buffer where advertising reports will be stored by the SoftDevice. */
    } __attribute__((__packed__)) nrf_ble_scan_t;

    This allowed the parameters to be set correctly. Now when I call  my scan start function

    err_code = nrf_ble_scan_start(&my_scanner);
    APP_ERROR_CHECK(err_code); 

    The program stops running at an unknown function at 0x00004AAA (which I assume lies somewhere in the Soft Device binary, hence why it is unknown). 

  •  And now it is working. I was able to set the parameters correctly by using the attribute packed onto the struct. I then removed it and was not running into the breakpoint in the soft device anymore. Thanks for the help!

  • Hi,

    Sorry for revisiting this so close to x-mas, but when you write "I then removed it", what do you refer to as "it"? It sounds like you added the packed attribute, built the project, removed the packed attribute and then built the project again, and this time it worked?

    Regards,
    Terje

Related