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

NRF52 Auto Reset

Hi everyone,

I'm programming nRF52833 for my application. In my application, I used ble_advdata_parse to read the advertising packet for filtering mine device. However, The systems only run for few seconds and then it reset by itself. When I debug I got some messages like this. Here is my code. Can anyone tell me some ways to figures it out?? Please reply as soon as possible!!!

Thanks

Best regards!!

 

void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    ble_gap_evt_adv_report_t const *p_adv_report = &p_ble_evt->evt.gap_evt.params.adv_report;		
    uint8_t const * addr = p_adv_report->peer_addr.addr;
    int8_t rssi_h = p_adv_report->rssi;
    const ble_data_t * data = &p_adv_report -> data;

    //uint8_t * device_name = ble_advdata_parse(data -> p_data, data -> len, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
    //char target_name[9] = "BLE_DEMO";
    //target_name[8] = NULL;
    //char name_test[9];
    //if(data -> len == 0)
    //{
    //    asm("NOP");
    //}
    //else{
    //    for(int i = 0; i < sizeof(target_name)/sizeof(target_name[i]); i++)
    //    {
    //        name_test[i] = (char)*(device_name+i);
    //        if(i == sizeof(target_name)/sizeof(target_name[i]) - 1)
    //        {
    //            name_test[i] = NULL;
    //        }
    //    }
    //}

    //int result = strcmp(name_test,target_name);
    int check = 0;
    uint8_t * manuf_data;
    manuf_data = ble_advdata_parse(data -> p_data, data -> len, BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA);
    char string_test[10];
    char target_string[3] = FILTER_DEVICE_IDENTIFICATION;
    //data_check = (char*)manuf_data;
    
    for(int i = 0; i < sizeof(string_test)/sizeof(string_test[0]); i++)
    {
        if (((*(manuf_data+i) > 64) && (*(manuf_data+i) < 91)) || ((*(manuf_data+i) > 96) && (*(manuf_data+i) < 123))) 
        {
            string_test[i] = (char) * (manuf_data + i);
            //printf("%c",*(data_check + i));
        }
    }
    //for(int i = 0 ; i < sizeof(string_test)/sizeof(string_test[0]); i++)
    //{
    //    printf("%c", *(string_test + i));
    //    if (i == strlen(string_test) - 1) {
    //        printf("\r\n");
    //    }
    //}
    
    for (int i = 0 ; i < sizeof(string_test)/sizeof(string_test[0]); i++)
    {
        if ((string_test[i] == target_string[0]) && (string_test[i + 1] == target_string[1]) && (string_test[i + 2] == target_string[2])) 
        {
            check = 1;
        }
    }
    //int result = strcmp(data_store,data_check);
    //printf("\r\n %d", result);

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
            //if (rssi_h > LOWEST_RSSI_THRESHOLD)
            //{
                //if(((*addr == DEVICE_ADD0) && (*(addr+1) == DEVICE_ADD1)))
                //if(result == 0)
                if (check == 1)
                {
                    
                    SRSSIData_t item;
                    memcpy(&item.ID[0], addr, sizeof(item.ID));
                    item.RSSI  = rssi_h;
                    item.Timestamp = xTaskGetTickCount();

                    DeviceMng_InsertRSSI(item);

                    //SLogRSSI_t logItem;
                    //logItem.TimeStamp = xTaskGetTickCount();
                    //logItem.RSSI = rssi_h;
                    //BufferPush(&rbLogRSSIBuf, &logItem);
                }
            //}
            //else {
            //    asm("NOP");
            //}
            //}
        break;

        case BLE_GAP_EVT_CONNECTED:
            printf("Connected");
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            printf("Disconnected");
            // LED indication will be changed when advertising starts.
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG("PHY update request.");
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            // No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

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

Parents
  • Hi,

    It looks like one of the functions in ble_evt_handler() is returning the NRF_ERROR_INVALID_STATE(8) error. I can't tell  which one based on the image of the callstack you posted. However, the debug logs from the default error handler (Error module) should include that information. If this is based on an SDK project you should be able to enable logging over RTT simply by applying the following configurations to sdk_config.h

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0
    NRF_LOG_BACKEND_RTT_ENABLED 1

    And make sure you also select the "Debug" configuration before you debug. This will make the crashlog include the file name and line number of where the error occured..

     

  • Here is where the error comes from. Sr I can't follow your Instruction. There are many error when I change things like what you said because I used FREERTOS for my application so it's seems like I have some troubles to handle with if I change like that.

  • Nguyen Trong Tuan said:
    Here is where the error comes from

    Where is the error coming from?

    Nguyen Trong Tuan said:
    There are many error when I change things

     Are you able to upload your project here or in a private support ticket so I can take a look?

    Edit: For some reason I didn't see the screenshot you posted earlier. Anyway, it seems like the error is returned by sd_ble_gap_disconnect() in the  BLE_GATTS_EVT_TIMEOUT event, which indicates that the device was already disconnected when this event got processed.

Reply
  • Nguyen Trong Tuan said:
    Here is where the error comes from

    Where is the error coming from?

    Nguyen Trong Tuan said:
    There are many error when I change things

     Are you able to upload your project here or in a private support ticket so I can take a look?

    Edit: For some reason I didn't see the screenshot you posted earlier. Anyway, it seems like the error is returned by sd_ble_gap_disconnect() in the  BLE_GATTS_EVT_TIMEOUT event, which indicates that the device was already disconnected when this event got processed.

Children
No Data
Related