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

Add new service with one characteristic result in 0xDEADBEEF error in 0x343 line of src\ll_lm.s0.c

hi guys, I add a temperature service with one characteristic to notify the IC temperature in hrs example. But when enable hrs notify, SoftDevice crashed every time. That is the 0xDEADBEEF error in 0x343 line of src\ll_lm.s0.c file. Can any one help me analyze it? I use s110_nrf51822_6.0.0_softdevice.hex

My code :

#include "ble_tps.h"
#include <string.h>
#include "nordic_common.h"
#include "ble_srv_common.h"
#include "app_util.h"

#define INITIAL_TEMPERATURE_VALUE  0


/**@brief Function for handling the Connect event.
 *
 * @param[in]   p_tps       Temperature Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_connect(ble_tps_t * p_tps, ble_evt_t * p_ble_evt)
{
    p_tps->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
}


/**@brief Function for handling the Disconnect event.
 *
 * @param[in]   p_tps       Temperature Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_disconnect(ble_tps_t * p_tps, ble_evt_t * p_ble_evt)
{
    UNUSED_PARAMETER(p_ble_evt);
    p_tps->conn_handle = BLE_CONN_HANDLE_INVALID;
}


/**@brief Function for handling the Write event.
 *
 * @param[in]   p_tps       Temperature Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_tps_t * p_tps, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

    if (
        (p_evt_write->handle == p_tps->temperature_handles.cccd_handle)
         &&
        (p_evt_write->len == 2)
       )
    {
       // CCCD written, call application event handler
       if (p_tps->evt_handler != NULL)
       {
          ble_tps_evt_t evt;

          if (ble_srv_is_notification_enabled(p_evt_write->data))
          {
                evt.evt_type = BLE_TPS_EVT_NOTIFICATION_ENABLED;
          }
          else
          {
                evt.evt_type = BLE_TPS_EVT_NOTIFICATION_DISABLED;
          }

          p_tps->evt_handler(p_tps, &evt);
        }
    }
}


void ble_tps_on_ble_evt(ble_tps_t * p_tps, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_tps, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_tps, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_tps, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}


/**@brief Function for adding the Temperature characteristic.
 *
 * @param[in]   p_tps          Temperature Service structure.
 * @param[in]   p_tps_init     Information needed to initialize the service.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static uint32_t temperature_char_add(ble_tps_t * p_tps, const ble_tps_init_t * p_tps_init)
{
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
    uint8_t             encoded_initial_tps[sizeof(uint32_t)];

    memset(&cccd_md, 0, sizeof(cccd_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    cccd_md.write_perm = p_tps_init->tps_attr_md.cccd_write_perm;
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;

    memset(&char_md, 0, sizeof(char_md));

    char_md.char_props.read   = 1;
    char_md.char_props.notify = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &cccd_md;
    char_md.p_sccd_md         = NULL;

    memset(&attr_md, 0, sizeof(attr_md));

    attr_md.read_perm  = p_tps_init->tps_attr_md.read_perm;
    attr_md.write_perm = p_tps_init->tps_attr_md.write_perm;
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;

    ble_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN;
    ble_uuid.uuid = BLE_UUID_TPS_CHAR;

    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = uint32_encode(INITIAL_TEMPERATURE_VALUE, encoded_initial_tps);
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = sizeof(uint32_t);
    attr_char_value.p_value      = encoded_initial_tps;

    return sd_ble_gatts_characteristic_add(p_tps->service_handle,
                                                     &char_md,
                                               &attr_char_value,
                                               &p_tps->temperature_handles);
}


uint32_t ble_tps_init(ble_tps_t * p_tps, const ble_tps_init_t * p_tps_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure
    p_tps->evt_handler               = p_tps_init->evt_handler;
    p_tps->conn_handle               = BLE_CONN_HANDLE_INVALID;

    // Add service
    ble_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN;
    ble_uuid.uuid = BLE_UUID_TPS_SERVICE;

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_tps->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Add temperature characteristic
    err_code = temperature_char_add(p_tps, p_tps_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}

uint32_t ble_tps_temperature_update(ble_tps_t * p_tps, uint32_t tp)
{
    uint32_t err_code = NRF_SUCCESS;

    // Send value if connected and notifying
    if (p_tps->conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        uint8_t                encoded_temps[sizeof(uint32_t)];
        ble_gatts_hvx_params_t hvx_params;
        uint16_t               hvx_len;

        hvx_len = uint32_encode(tp, encoded_temps);

        memset(&hvx_params, 0, sizeof(hvx_params));

        hvx_params.handle   = p_tps->temperature_handles.value_handle;
        hvx_params.type     = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset   = 0;
        hvx_params.p_len    = &hvx_len;
        hvx_params.p_data   = encoded_temps;

        err_code = sd_ble_gatts_hvx(p_tps->conn_handle, &hvx_params);
    }
    else
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }

    return err_code;
}
Related