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

flash questions

Question  1 :

I write 512 words to flash but only can get some value right .and some value was wrong.

I  used      fs_store( &one_min_data,

                                                        (uint32_t *)(FLASH_DATA_ADRR),

                                                        (uint32_t *)(&buffer),

                                                        512,

                                                        NULL);

The value should be 0 -511 .but the value in the flash is not like that .

By the way my sdk is 12.3.And with   ble app uart     demo.

What  I  have done and init   light   this

err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);//添加系统事件派发

APP_ERROR_CHECK(err_code);  

void sys_evt_dispatch(uint32_t sys_evt)

{

//这函数在fstorage.c中实现

ble_advertising_on_sys_evt(sys_evt);

fs_sys_event_handler(sys_evt);

}

FS_REGISTER_CFG(fs_config_t one_min_data) =
{
.callback = one_min_data_flash_ok_event,// Function for event callbacks.
.num_pages = 6, // Number of physical flash pages required.
.priority = 0xFE // Priority for flash usage.
};

void one_min_data_flash_ok_event(fs_evt_t const * const evt, fs_ret_t result)
{
    if(evt->id==FS_EVT_STORE && result==FS_SUCCESS)
      MI_LOG_INFO("one_min_data_flash_ok_event\r\n");
}

512 flash write

Question  2 :

I  have tried another way I write three times Continuously. Also use  fs_store()

But the second time always get 00000000.

1st  value 0x55555555    address :122*4096                      ok

2nd value   whatever      address :121*4096                      wrong  get  0x00000000

3rd  value 0x5a5a5a5a    address:120*4096                        ok

And  I found that  no matter  which one is the second to write  it always wrong .

Parents
  • Hi,

    How do the memory area look before you try try to write it? Note that you cannot write to flash if it is not erased first. You should also check the error code returned from the function call, and the return code in the callback when the operation is finished.

    Best regards,
    Jørgen

  • Sure, please provide your project. Which board are you testing this on?

  • PCA1004.and I'll tell you the pin set .wait for a moment 

  • I found something ,if I write 

     fs_store( &one_min_data,

                                                            (uint32_t *)(FLASH_DATA_ADRR),

                                                            (uint32_t *)(&buffer),

                                                            512,

                                                            NULL);

  • I found something ,if I write 

     fs_store( &one_min_data,

                                                            (uint32_t *)(FLASH_DATA_ADRR),

                                                            (uint32_t *)(&buffer),

                                                            512,

                                                            NULL);

  • I found something 

    If I just  wait for event and do nothing after I call  

     fs_store( &one_min_data,

                                                            (uint32_t *)(FLASH_DATA_ADRR),

                                                            (uint32_t *)(&buffer),

                                                            512,

                                                            NULL);

    It will be OK. 

    like this 

    kk=fs_store( &one_min_data,
    (uint32_t *)(FLASH_DATA_ADRR),
    buffer_text,
    512,
    NULL);

    while(1)
    {
    if (NRF_LOG_PROCESS() == false)//将保存的LOG都吐出来之后进入休眠
    {
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
    }

    }

    SO my question is that should I wait the complete event.and do nothing before that,just SD_app_evt_wait();

    until I resieve a flag whith be set by the complete event .like below

    void one_min_data_flash_ok_event(fs_evt_t const * const evt, fs_ret_t result)
    {
    if(evt->id==FS_EVT_STORE && result==FS_SUCCESS)
      recieve_flag=1;
    }

    {......

    kk=fs_store( &one_min_data,
    (uint32_t *)(FLASH_DATA_ADRR),
    buffer_text,
    512,
    NULL);

    recieve_flag=0;

    while(recieve_flag!=1)
    {
    if (NRF_LOG_PROCESS() == false)
    {
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
    }

    }

    }

    IS the only way?

  • Yes, fstorage use asynchronous write and erase operations. You need to wait for the event before you can read back the written data, if not the operation might not be completed.

Reply Children
Related