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

Getting error code 4 while trying to initialize device information services repeatedly from main

Hi 

I am working on the application in which I wanted to initialize and uninitialize different services. I am using device information services to read manufacturer data from connected devices. 

below is my code snippet for initialization and initialization of dis services. 

static ble_dis_init_t dis_init;

void dis_init( void )

{

memset( &dis_init, 0, sizeof(ble_dis_init_t) );
ble_srv_ascii_to_utf8( &dis_init.manufact_name_str, (char*)MANUFACTURER_NAME );

dis_init.dis_char_rd_sec = SEC_OPEN;
ret_code_t error_code = ble_dis_init( &dis_init );
APP_ERROR_CHECK( error_code );

}

void dis_uninit( void )

{

dis_init.dis_char_rd_sec = SEC_NO_ACCESS;
dis_init.manufact_name_str.length = 0;
dis_init.manufact_name_str.p_str = NULL;

}

This routine is working fine when I call this once from my main code. but if I call this repeatedly (when 3rd time it is called) from my code "ble_dis_init(  &dis_init) returns error code 4.

One solution I know I can change my RAM settings but that wont resolve my issue. 

Am I doing anything wrong in this?

Thanks 

KRA

Parents
  • Hello,

    Actually i am also getting the same problem and as you suggested increase the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE so i increase it from 1408 to 1600( in bytes ).

    After changing the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE still it gives error code 4 but this time it goes in error when i try to call "ble_dis_init" function 4th time.

    i investigate the error and find that it gives the error in "char_add" function

        // Add characteristics
        if (p_dis_init->manufact_name_str.length > 0)
        {
            err_code = char_add(BLE_UUID_MANUFACTURER_NAME_STRING_CHAR,
                                p_dis_init->manufact_name_str.p_str,
                                p_dis_init->manufact_name_str.length,
                                p_dis_init->dis_char_rd_sec,
                                &manufact_name_handles);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }

    so according to me when we are repeatedly calling the dis service init, attributes are created in database and when it reaches maximum  attribute tab size which we are giving by NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE macro, code gives NO_MEMORY ERROR

    is there any way to delete the attribute which is created in database at the time of dis service initialization, so we will delete that at the time of uninit of dis service.  

Reply
  • Hello,

    Actually i am also getting the same problem and as you suggested increase the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE so i increase it from 1408 to 1600( in bytes ).

    After changing the NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE still it gives error code 4 but this time it goes in error when i try to call "ble_dis_init" function 4th time.

    i investigate the error and find that it gives the error in "char_add" function

        // Add characteristics
        if (p_dis_init->manufact_name_str.length > 0)
        {
            err_code = char_add(BLE_UUID_MANUFACTURER_NAME_STRING_CHAR,
                                p_dis_init->manufact_name_str.p_str,
                                p_dis_init->manufact_name_str.length,
                                p_dis_init->dis_char_rd_sec,
                                &manufact_name_handles);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }

    so according to me when we are repeatedly calling the dis service init, attributes are created in database and when it reaches maximum  attribute tab size which we are giving by NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE macro, code gives NO_MEMORY ERROR

    is there any way to delete the attribute which is created in database at the time of dis service initialization, so we will delete that at the time of uninit of dis service.  

Children
Related