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

Not Saving in Flash Memory

Hi,
I am saving data in flash memory but when I read after restarting the device it shows FF. 
How can I read from flash after restarting the device? and how can I check that there is already data?
Thanks 

  • Hi
    Here is the output. When I call the same function before connection it saves and read data from memory BUT when I call the same function after connecting the device it not work.

  • How many bytes are you writing? And what values do you write? Remember that I don't know anything apart from what you have written here. How am I supposed to know what your log is supposed to write?

    According to your snippets so far, the save_data[] array is two bytes long (but it doesn't say). And the values are {0x55, 0x55}.

    This is what you read, but the save_data[] array looks like it is 8 bytes long.

     

    Muqarrab said:
    BUT when I call the same function after connecting the device it not work.

     So what do you read then? It seems you forgot to mention that in the log? Or do you not call the function after you have connected?

  • Hi ,

    1-These are two functions to save/read data from flash. These are okay?

    void write_in_flash(uint8_t place)
    {
        ret_code_t rc;
        place=place*16;
    
        sd_flash_page_erase(0x47);
    
        rc = nrf_fstorage_write(&fstorage, flash_start_address+place, save_data, sizeof(save_data), NULL);
        APP_ERROR_CHECK(rc);
    
        wait_for_flash_ready(&fstorage);
        NRF_LOG_INFO("Done.");
    }
    void read_in_flash(uint8_t place)
    {
        ret_code_t rc;
        place=place*16;
    
        rc = nrf_fstorage_read(&fstorage, flash_start_address+place, read_data, sizeof(save_data));
        APP_ERROR_CHECK(rc);
    
        wait_for_flash_ready(&fstorage);
       
        NRF_LOG_INFO("Reading from flash hex:");
        for(uint8_t i=0; i<sizeof(read_data); i++)
        {
            NRF_LOG_RAW_INFO("%02x:", read_data[i]);
        }
        NRF_LOG_RAW_INFO("\r\n");
        NRF_LOG_INFO("done");
    }
    

    2-When I called these functions without connection it works.

    void Charcteristics_10(uint8_t test)
    {
        NRF_LOG_INFO("Function Called");
    
        save_data[0]=0x55;
        save_data[1]=0x55;
        write_in_flash(2);
        read_in_flash(2);
    
    
    }
    






    3-When I called the same function after connecting the device I get no response also device does not connect. (Stuck in connecting) 

            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("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);
    
               connection_state=1;
               NRF_LOG_INFO("Connected LED Set");
    
               nrf_gpio_pin_set(State_LED);
    
               Charcteristics_10(5);
    
    
                break;
    



  • Muqarrab said:
    3-When I called the same function after connecting the device I get no response also device does not connect. (Stuck in connecting) 

     From where are you calling the flash read and write functions? I don't think you included that in your snippets.

    What is your connection interval? What are you connected to? A phone or another nRF? What is your role? Central or Peripheral?

    Perhaps you can upload the entire project, so that I don't have to ask for all these things, in case there is some information missing? At least all the relevant functions.

  • Hi





    A phone or another nRF?

    With a mobile phone.

    What is your role?

    Peripheral.

    I have attached the project kindly check. These are the functions I have written for read/write data in flash memory. 

    void write_in_flash(uint8_t place)
    void read_in_flash(uint8_t place)


    void Charcteristics_10(uint8_t test) //
    In this function I called above functions.





    Flash(PR.Y.MK.5.0.1.X).zip

Related