Calling sd_ble_gap_tx_power_set() errors out with 0x3004, NRF_ERROR_NO_MEM

Hello,

I've been trying to figure why calling sd_ble_gap_tx_power_set() continues to return the error NRF_ERROR_NO_MEM. I'm using SDK 17.0.2 with S113, v7.2.0 on the NRF52840.

I've seen previous posted regarding other Softdevice function calls failing with NRF_ERROR_NO_MEM, but all attempts to limit MTU and GAP_LENGTH in sdk_config.h failed.

I even tried rebuilding the project with S140, but still, my application code errors out with NRF_ERROR_NO_MEM.

  ret_code_t err_code = NRF_SUCCESS;
    
 
    ble_advertising_init_t bleAdvInitData;

    // Initialize to zero.
    memset( &bleAdvInitData, 0, sizeof( bleAdvInitData ) );

    // Set the Tx power before we begin advertisement. Radio transmit power in
    // dBm (accepted values are ONLY -40, -20, -16, -12, -8, -4, 0, and 4 dBm).
    // Note: Testing with the base station found that TX_POWER_HIGH_SECURITY set
    // the transmit strength too low for consistent log transfers.
    txPower_t calaTxPower = TX_POWER_MEDIUM_SECURITY;

    ble_uuid_t adv_uuids[] = { { BTS_UUID_SERVICE, m_bts.uuid_type } }; // BTS


    // Build advertising data struct to pass into @ref ble_advertising_init.
    bleAdvInitData.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    bleAdvInitData.advdata.include_appearance = true;
    bleAdvInitData.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    memset( &bleAdvInitData.srdata, 0, sizeof( bleAdvInitData.srdata ) );
    bleAdvInitData.srdata.uuids_complete.uuid_cnt = sizeof( adv_uuids ) / sizeof( adv_uuids[0] );
    bleAdvInitData.srdata.uuids_complete.p_uuids = adv_uuids;

    bleAdvInitData.config.ble_adv_fast_enabled  = true;
    bleAdvInitData.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    bleAdvInitData.config.ble_adv_fast_timeout  = APP_ADV_NEVER_TIMEOUT;
    bleAdvInitData.evt_handler                  = on_adv_evt;

    // Set the Tx power (rely on compiler type promotion to int8_t here):
    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_connHandle, calaTxPower);
    if ( err_code != NRF_SUCCESS )
    {
        NRF_LOG_INFO( "sd_ble_gap_tx_power_set() failed, err_code: 0x%X\n", err_code );
    }

Parents
  • Hi,

    The error code 0x3004 is BLE_ERROR_INVALID_ADV_HANDLE (not NRF_ERROR_NO_MEM). Looking at the API documentation for sd_ble_gap_tx_power_set() you see that it is returned if you provided an invalid connection handle. I do not see from your code snippet what the value of m_connHandle is, but it is clearly not valid. You get this value from when you initialize advertising (see for instance <SDK 17.x.x>\examples\ble_peripheral\ble_app_proximity\main.c).

    For future reference, I highly recommend making use of the APP_ERROR_CHECK() function in combination with having DEBUG defined in your preprocessor defines, like shown in the included image:

    This will make your logger output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK, which makes debugging much easier. It would be very useful to see the error message output by the logger in this case, if you insert an APP_ERROR_CHECK on the error code returned by sd_ble_gap_tx_power_set.

Reply
  • Hi,

    The error code 0x3004 is BLE_ERROR_INVALID_ADV_HANDLE (not NRF_ERROR_NO_MEM). Looking at the API documentation for sd_ble_gap_tx_power_set() you see that it is returned if you provided an invalid connection handle. I do not see from your code snippet what the value of m_connHandle is, but it is clearly not valid. You get this value from when you initialize advertising (see for instance <SDK 17.x.x>\examples\ble_peripheral\ble_app_proximity\main.c).

    For future reference, I highly recommend making use of the APP_ERROR_CHECK() function in combination with having DEBUG defined in your preprocessor defines, like shown in the included image:

    This will make your logger output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK, which makes debugging much easier. It would be very useful to see the error message output by the logger in this case, if you insert an APP_ERROR_CHECK on the error code returned by sd_ble_gap_tx_power_set.

Children
No Data
Related