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

Adding Custom Service to Buttonless DFU example results in fatal error

Hi, 

I am working on NRF52840 preview DK using SDK version 15.3

I have compiled and loaded the Secure DFU bootloader onto the device, and also successfully got the BLE_BUTTONLESS_DFU template to work by uploading it through the DfuTarg.

but, once I try to write my own service in the template the app crashes with a 'fatal error' and the device keeps resetting.

Here is my service_init function

static void services_init(void)
{
    uint32_t                  err_code;
    nrf_ble_qwr_init_t        qwr_init  = {0};
    ble_dfu_buttonless_init_t dfus_init = {0};

    // Initialize Queued Write Module.
    qwr_init.error_handler = nrf_qwr_error_handler;

    err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
    APP_ERROR_CHECK(err_code);

    dfus_init.evt_handler = ble_dfu_evt_handler;

    err_code = ble_dfu_buttonless_init(&dfus_init);
    APP_ERROR_CHECK(err_code);
    err_code = ble_dfu_buttonless_async_svci_init();
    APP_ERROR_CHECK(err_code);

    ble_uuid_t        service_uuid;
    ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
    service_uuid.uuid = BLE_UUID_OUR_SERVICE_UUID;
    err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type);
    APP_ERROR_CHECK(err_code);    

    // Add our service
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                            &service_uuid,
                            &p_our_service.service_handle);
    
    APP_ERROR_CHECK(err_code);
}

some of the settings related to service is as follows

// Defining 16-bit service and 128-bit base UUIDs
#define BLE_UUID_OUR_BASE_UUID              {{0x23, 0xD1, 0x13, 0xEF, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}} // 128-bit base UUID
#define BLE_UUID_OUR_SERVICE_UUID                0xF00D // Just a random, but recognizable value


typedef struct
{
    uint16_t service_handle;                /**< Handle of Our Service (as provided by the BLE stack). */
}ble_os_t;

ble_os_t p_our_service;

static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;                            /**< Handle of the current connection. */
static void advertising_start(bool erase_bonds);                                    /**< Forward declaration of advertising start function */

// YOUR_JOB: Use UUIDs for service(s) used in your application.
static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_OUR_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN}};

I also changed 

NRF_SDH_BLE_VS_UUID_COUNT to 2 

and 

NRF_SDH_BLE_SERVICE_CHANGED = 1

in sdk_config.h

Parents Reply
  • : "Fatal Error" is printed by the app_error_fault_handler in app_error_weak.c. Please define DEBUG in your Preprocessor Definitions so that the fault id, line number etc is printed in the log output.

    __WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
    {
        __disable_irq();
        NRF_LOG_FINAL_FLUSH();
    
    #ifndef DEBUG
        NRF_LOG_ERROR("Fatal error");
    #else
        switch (id)
        {
    #if defined(SOFTDEVICE_PRESENT) && SOFTDEVICE_PRESENT
            case NRF_FAULT_ID_SD_ASSERT:
                NRF_LOG_ERROR("SOFTDEVICE: ASSERTION FAILED");
                break;
            case NRF_FAULT_ID_APP_MEMACC:
                NRF_LOG_ERROR("SOFTDEVICE: INVALID MEMORY ACCESS");
                break;
    #endif
            case NRF_FAULT_ID_SDK_ASSERT:
            {
                assert_info_t * p_info = (assert_info_t *)info;
                NRF_LOG_ERROR("ASSERTION FAILED at %s:%u",
                              p_info->p_file_name,
                              p_info->line_num);
                break;
            }
            case NRF_FAULT_ID_SDK_ERROR:
            {
                error_info_t * p_info = (error_info_t *)info;
                NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x",
                              p_info->err_code,
                              nrf_strerror_get(p_info->err_code),
                              p_info->p_file_name,
                              p_info->line_num,
                              pc);
                 NRF_LOG_ERROR("End of error report");
                break;
            }
            default:
                NRF_LOG_ERROR("UNKNOWN FAULT at 0x%08X", pc);
                break;
        }
    #endif
    
        NRF_BREAKPOINT_COND;
        // On assert, the system can only recover with a reset.
    
    #ifndef DEBUG
        NRF_LOG_WARNING("System reset");
        NVIC_SystemReset();
    #else
        app_error_save_and_stop(id, pc, info);
    #endif // DEBUG
    }

Children
No Data
Related