This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to add custom service to the Ble_app_template example

Hello i am using nrf52810 with SDK version 17.0.2 , i want to add custom service to the ble_app_template example and i followed this tutorial link https://github.com/edvinand/custom_ble_service_example so at first debug i got this error as expected 

next i have change the RAM_START AND RAM_SIZE as per the memory size mentioned in the error then i DEBUG it again so the i got 

so i don't know what's happening please help me to resolve this . 

thank you.

Parents Reply Children
  • Hello,

    You will need to look at the end of the error message to see which line it is pointing to, then check which function returned the error code that was checked on the line specified in the error message.
    Then, you should check the API refence of the function that returned the error code to see why it would return this specific error, so you may resolve the issue.
    Please try this, and let me know if you are able to resolve the issue.
    If not, please share all the information mentioned above so I may take a look.

    Furthermore, I see that you have commented out an APP_ERROR_CHECK in your code - this is not advisable, because you will not be alerted if the function fails, if the error code is never checked. Please reinstate the APP_ERROR_CHECK, and all other APP_ERROR_CHECK's you might have removed as well, they serve an important function.

    Best regards,
    Karl

  • Hello ,

    please share all the information mentioned above so I may take a look

    i got issue like the p_cus_init->evt_handler == NULL in ble_cus_init() function after this its not executing

    and its back to break point. for more information please have look at this,

      

    Furthermore, I see that you have commented out an APP_ERROR_CHECK in your code - this is not advisable, because you will not be alerted if the function fails, if the error code is never checked. Please reinstate the APP_ERROR_CHECK, and all other APP_ERROR_CHECK's you might have removed as well, they serve an important function.

    if i uncomment APP_ERROR_CHECK write characteristics will not add however that is redundant so after commenting that only characteristic was added.

    so i don't know i am blanked what to do i tried so many times if i comment the  p_cus_init->evt_handler == NULL in ble_cus_init() function then it starts advertising. so please help me to resolve this.

    thank you.

  • Hello again,

    sagarnayakm said:
    so i don't know i am blanked what to do i tried so many times if i comment the  p_cus_init->evt_handler == NULL in ble_cus_init() function then it starts advertising. so please help me to resolve this.

    But this does not solve the underlying issue, it is just treating the symptoms. If you just remove error checks that fail the errors will still be there, you just will not know about it.
    To fix it, and make it function as expected you will need to resolve the underlying issue.

    sagarnayakm said:
    i got issue like the p_cus_init->evt_handler == NULL in ble_cus_init() function after this its not executing

    Have you implemented and provided an event handler for your custom service during its initialization?

    Best regards,
    Karl

  • Have you implemented and provided an event handler for your custom service during its initialization?

    Yes, in service init() i have declare like this,

    .

    static void services_init(void)
    {
        ret_code_t         err_code;
        
        nrf_ble_qwr_init_t qwr_init = {0};
        ble_cus_init_t                     cus_init;
        
        
    
        // Initialize Queued Write Module.
        qwr_init.error_handler = nrf_qwr_error_handler;
    
    
         cus_init.evt_handler               = on_cus_evt;
       
    
        err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
        APP_ERROR_CHECK(err_code);
    
        /* YOUR_JOB: Add code to initialize the services used by the application.
           ble_xxs_init_t                     xxs_init;
           ble_yys_init_t                     yys_init;
    
           // Initialize XXX Service.
           memset(&xxs_init, 0, sizeof(xxs_init));
    
           xxs_init.evt_handler                = NULL;
           xxs_init.is_xxx_notify_supported    = true;
           xxs_init.ble_xx_initial_value.level = 100;
    
           err_code = ble_bas_init(&m_xxs, &xxs_init);
           APP_ERROR_CHECK(err_code);
    
           // Initialize YYY Service.
           memset(&yys_init, 0, sizeof(yys_init));
           yys_init.evt_handler                  = on_yys_evt;
           yys_init.ble_yy_initial_value.counter = 0;
    
           err_code = ble_yy_service_init(&yys_init, &yy_init);
           APP_ERROR_CHECK(err_code);
         */
    
        
        
        // Initialize CUS Service.
        memset(&cus_init, 0, sizeof(cus_init));
        
        err_code = ble_cus_init(&m_cus, &cus_init);
        printf("err_code:%d",err_code);
        APP_ERROR_CHECK(err_code);   
     
        
        
    }
    

    and handler is,

     

    static void on_cus_evt(ble_cus_t     * p_cus_service,
                           ble_cus_evt_t * p_evt)
    {
     
        switch(p_evt->evt_type)
        {
            case BLE_CUS_EVT_CONNECTED:
                break;
    
            case BLE_CUS_EVT_DISCONNECTED:
                break;
    
            default:
                // No implementation needed.
                break;
        }
    
    }
    

    in tutorial i got that the handler should not be NULL so how can achieve this.??

  • It looks to me like you do not set the event handler as part of the ble_cus_init function in the function you shared previously. It seems you have omitted the line where the provided handler is registered to the custom service.
    Please rectify this, and let me know if this resolves your issue.

    Best regards,
    Karl

Related