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

How to store the received data from ble nus into flash memory

Hi...  I have merged the ble_app_uart and fstorge example .  I am storing the received data in a variable and passing in flash using nrf_fstorage_write command . I am getting nrf_breakpoint while I am sending the data from ble_app. Why ? What is the issue .. When I tried to send the data from ble_app only I am getting this error.  Please anyone suggest me 

Thanks&Regards 

Pspavi

  • Could you upload your code (main.c) to this ticket? Then I can take a look at it and figure out what might cause the unwanted behavior. Click on Insert→Insert image/video/file→From→File Upload, then find main.c and click Ok.

  • Hi, I am also facing the same issue. The data is being received in p_data, but I am unable to write the received data to flash memory. I have tried using fds and fstorage. PFA the main.c file below. This is a snippet of the ble_data_handler and int_main(). 

     

    char data[100];
    uint32_t address=0x60000;
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        //ret_code_t err_code;
        app_uart_flush();
        if (p_evt->type == BLE_NUS_EVT_RX_DATA && p_evt->params.rx_data.length>0)
        {
            uint32_t err_code;
    
            NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
            //NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    data[i]=p_evt->params.rx_data.p_data[i];
                    err_code = nrf_fstorage_write(&fstorage, address, p_evt->params.rx_data.p_data[i], p_evt->params.rx_data.length, NULL);
                    //APP_ERROR_CHECK(err_code);
                    address++;
                    //err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    //if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    //{
                    //    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                    //    APP_ERROR_CHECK(err_code);
                    //}
                } while (err_code == NRF_ERROR_BUSY);
            }
            //if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            //{
            //    while (app_uart_put('\n') == NRF_ERROR_BUSY);
            //}
        }
        printf("The length of data is: %d\n\r",p_evt->params.rx_data.length);
        ble_data_receive=true;
        printf("BLE Data received and bool changed to true\n\r");
    }
    
    
    int main(void)
    {
    ////////////////////////////// F STORAGE CODE//////////////////////////
    
        ret_code_t err_code;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        err_code = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(err_code);
     
    //////////////////////////////// BLE UART CODE/////////////////////////    
        bool erase_bonds;
        // Initialize.
        uart_init();
        log_init();
        //cli_init();
        timer_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();                         
        conn_params_init();
        advertising_start();
        //cli_start();
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
            if(ble_data_receive==true){
                const char sms[100]={"Hello we are speaking from sunlux technovations!"};
                printf("Commencing write operation\n\r");
                //err_code = nrf_fstorage_write(&fstorage, 0x60000, &data, 115, NULL);
                //APP_ERROR_CHECK(err_code);
                if(err_code==NRF_SUCCESS){
                  printf("Write operation done!\n\r");
                }
                printf("Printing data here\n\r");
                printf(&data);
                //printf("Printing ends here\n\r");
                printf("The data in String is: %s\n\r",data);
                printf("The data pointer value is: %d\n\r",data);
                ble_data_receive=false;
                printf("BLE Data received and bool changed to false\n\r");
                //char a[100];uint32_t len=100;
                //printf("Reading flash\n\r");
                //ret_code_t rc;
                //rc=nrf_fstorage_read(&fstorage,0x200040D1,a,len);
                ////APP_ERROR_CHECK(rc);
                //printf("The data is: %s\n\r",a);
            }
            //cli_process();
        }
    }
    

  • Could you open a new ticket and ask the question there?

    Best regards,

    Simon

Related