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

flash memory R/W

I am using nRF 5 SDK v 14.2.0.

Store six items of data in flash memory with int or float,
In the program, the values ​​of the six items are acquired,
I want to operate with that value,
Including include and variables, coding method
I do not understand.
It is a simple sample program and it will be helpful if you let me know.

Thank you.
Parents
  • Hi,

    Recommend you to have a look at our Flash Data Storage Example, it uses the Experimental: Flash Data Storage library to manage persistent storage.   

  • Thank you for your reply.

    I saw these two pages once, but after all I did not know which part of the sample to divert.
    infocenter.nordicsemi.com/index.jsp
    infocenter.nordicsemi.com/index.jsp

    Also, I did not understand the difference between Flash Data Storage and Flash Storage.

    It depends on being posted here.

    When using Flash Data Storage,
    What is necessary with include etc. other than logic,
    In logic, the concrete procedure of writing and reading
    We would like to have a professor only.

    Sorry to trouble you, but thank you.

  • Also, the data handled by fds this time is written from smartphone with Bluetooth,
    I want to read the written value with this program,
    Can you do it?
  • When I debugged, I got it below, Unknown function 0x000008C8
    It is displayed.
        ret = fds_record_find(record.file_id, record.key , &record_desc, &ftok);

  • I also debugged again.
    below
    "Ret = fds_record_find (record.file_id, record.key, & record_desc, & ftok);"
    "If (ret! = FDS_SUCCESS) By the way, it becomes Unknown function 0x000008C8.
    Did you break the memory?
    ////////////////////////////////////
    //              FDS               //
    ////////////////////////////////////
    // Simple event handler to handle errors during initialization.
    static void fds_evt_handler(fds_evt_t const * p_fds_evt)
    {
        ret_code_t ret;
        switch (p_fds_evt->id)
        {
            case FDS_EVT_INIT:
                if (p_fds_evt->result != FDS_SUCCESS)
                {
                    // Initialization failed.
                    //NRF_LOG_RAW_INFO("----(Initialization failed.)(p_fds_evt->result:%d----\n", (p_fds_evt->result);
                    SEGGER_RTT_printf(0,"(Initialization failed.)p_fds_evt->result: %X \n",p_fds_evt->result);
                }
                break;
            default:
                break;
        }
    }

    /////////////////////////////////////
    //  fds test                    //
    /////////////////////////////////////
    ble_stack_init();
    ret_code_t ret = fds_register(fds_evt_handler);
    if (ret != FDS_SUCCESS)
    {
        /* fds_register error. */
        NRF_LOG_RAW_INFO("----(fds_register error.)ret:%d----\n", ret);
    }else{
        NRF_LOG_RAW_INFO("----(fds_register success.)ret:%d----\n", ret);
    }
    ret = fds_init();
    if (ret != FDS_SUCCESS)
    {
        /* fds_init error. */
        NRF_LOG_RAW_INFO("----(fds_init error.)ret:%d----\n", ret);
    }else{
        NRF_LOG_RAW_INFO("----(fds_init success.)ret:%d----\n", ret);
    }
    #define FILE_ID         0x0001  /* The ID of the file to write the records into. */
    #define RECORD_KEY_1    0x1111  /* A key for the first record. */
    #define RECORD_KEY_2    0x2222  /* A key for the second record. */
    //static uint32_t   const m_deadbeef = 0xDEADBEEF;
    static int32_t    const m_deadbeef = 300;
    static char       const m_hello[]  = "Hello, world!";
    fds_record_t        record;
    fds_record_desc_t   record_desc;
    // Set up record.
    record.file_id           = FILE_ID;
    record.key               = RECORD_KEY_1;
    record.data.p_data       = &m_deadbeef;
    record.data.length_words = 4;   /* one word is four bytes. */
    ret_code_t rc;
    rc = fds_record_write(&record_desc, &record);
    if (rc != FDS_SUCCESS)
    {
        /* Handle error. */
        NRF_LOG_RAW_INFO("----(fds_record_write error.)rc:%d----\n", rc);
    }else{
        NRF_LOG_RAW_INFO("----(fds_record_write success.)rc:%d file_id:0x%x key:0x%x data:%d----\n", rc,record.file_id,record.key,m_deadbeef);
    }
    // Set up record.
    //record.file_id           = FILE_ID;
    //record.key               = RECORD_KEY_2;
    //record.data.p_data       = &m_hello;
    /* The following calculation takes into account any eventual remainder of the division. */
    //record.data.length_words = (sizeof(m_hello) + 3) / 4;
    //rc = fds_record_write(&record_desc, &record);
    //if (rc != FDS_SUCCESS)
    //{
    //    /* Handle error. */
    //    NRF_LOG_RAW_INFO("----(Handle error.)rc:%d----\n", rc);
    //
    //}

    // Set up record.
    //record.file_id           = FILE_ID;
    //record.key               = RECORD_KEY_1;
    fds_flash_record_t  flash_record;
    fds_find_token_t    ftok;
    /* It is required to zero the token before first use. */
    memset(&ftok, 0x00, sizeof(fds_find_token_t));
    /* Loop until all records with the given key and file ID have been found. */
    for( ; ; )
    {
        ret = fds_record_find(record.file_id, record.key , &record_desc, &ftok);
        if (ret != FDS_SUCCESS)
        {
            /* Handle error. */
            NRF_LOG_RAW_INFO("----(fds_record_find error.)ret:%d----\n", ret);
            break;
        }else{
            NRF_LOG_RAW_INFO("----(fds_record_find success.)ret:%d----\n", ret);
        }
        ret = fds_record_open(&record_desc, &flash_record);
        if (ret != FDS_SUCCESS)
        {
            /* Handle error. */
            NRF_LOG_RAW_INFO("----(fds_record_open error.)ret:%d----\n", ret);
        }else{
            NRF_LOG_RAW_INFO("----(fds_record_open success.)ret:%d----\n", ret);
        }
        /* Access the record through the flash_record structure. */
        /* Close the record when done. */
        ret = fds_record_close(&record_desc);
        if (ret != FDS_SUCCESS)
        {
            /* Handle error. */
            NRF_LOG_RAW_INFO("----(fds_record_close error.)ret:%d----\n", ret);
        }else{
            NRF_LOG_RAW_INFO("----(fds_record_close success.)ret:%d----\n", ret);
        }
    }
  • I am very embarrassed.
    I debugged by commenting fds_record_write, fds_record_find, fds_record_open, fds_record_close other than fds_register () and fds_init () and it worked normally.
    After that, I put fds_record_write in it, but I made it function Unknown function 0x000008C8 with this function.
    I am sorry because I want to make it work properly next week, but thanking you in advance.
  • I think the Unknown function at 0x000008C8 is the Hardfault handler, please try to disable the hardfault breakpoint as shown in this post (link) and check if the exception gets forwarded to the application. 

Reply Children
No Data
Related