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

Use nrf_fstorage_sd with nrf_sdh_ble_enable

Hi, I'm using SDK15.2.0 and A nRF52832 for my project.

I followed the "flash_fstorage" example give by Nordic, to write in the flash memory in my project. 

When I run my program the function nrf_fstorage_erase(&fstorage, address, 1, NULL); and nrf_fstorage_write(&fstorage, address, &data, sizeof(data), NULL); work perfectly but after I had called nrf_sdh_ble_enable(), the functions nrf_fstorage_erase() and nrf_fstorage_write() don't work anymore even if I don't use BLE.

The SVCALL is never called to write or erase the flash, I still stuck in nrf_fstorage_is_busy().

Do I need to change some priorities in sdk_config.h ?

Thanks, Automne

Parents
  • Hi, 

    Just to make sure, are you initializing Fstorage with the Softdevice backend (p_fs_api = &nrf_fstorage_sd;), and not nrf_fstorage_nvmc?

    Thanks,

    Vidar 

  • Hi Vidar,

    I tried to implant fstorage in my code as you did in your example, I got the same problem. The functions nrf_fstorage_write() and nrf_fstorage_erase() work perfectly when the softdevice stack is disable.
    When the softdevice is enable nrf_fstorage_write() and nrf_fstorage_erase() work only once and I never get out of the SVCALL. I didn't get the events NRF_FSTORAGE_EVT_WRITE_RESULT or NRF_FSTORAGE_EVT_ERASE_RESULT.

    I don't call this functions from an interrupt.

    Which resource use SVCALL(nrf_fstorage_write) and SVCALL(nrf_fstorage_erase) ?

    Thanks, Automne

  • Glad to hear that you were able to make it work:) It sounds like you are satisfied with this solution but are you receiving any SoC events from the Softdevice when you use sd_flash* API directly?  

  • I wired the problem, the function sd_evt_get(uint32_t * p_evt_id) wasn't called after we get the event NRF_EVT_FLASH_OPERATION_SUCCESS to clear the flag is_busy.

  • Hello,

    I am having the same problem.  In the end did you stay with this solution of using the sd functions directly?  Did you manage to get a callback confirming the operation was successful?  I don't fully understand your comment below "I wired the problem"  -did you manage to get fstorage working?  how?  

    Seems to be a problem with the fstorage library right?  i know fds is the preferred route but seems like overkill for simple storage of a few settings.

    many thanks

    Barney

  • Hi Barley,

    The fds was also too much for my use case. I continue to call the function directly.

    In the example fstorage work properly, but in my code it isn't working, the flag is_busy isn't clear after the success of the operation, I don't know what's append inside Nordic code.

    I call sd_evt_get(uint32_t * p_evt_id) when the operation flash/write return a success :

    void flash_page_clear(uint32_t address)
    {
        uint32_t i = 0, j = 0, evt_id = 0xff, err = 0xff;

        err = sd_flash_page_erase((uint32_t)(address/FLASH_PAGE_SIZE));
        log_dbg("sd_flash_page_erase, ret code : %d", __func__, err);
        for(j = FLASH_OP_MAX_RETRIES; j!=0 && evt_id != NRF_EVT_FLASH_OPERATION_SUCCESS; j--)
        {
            for(i = 1000;i != 0
            && evt_id != NRF_EVT_FLASH_OPERATION_SUCCESS
            && evt_id != NRF_EVT_FLASH_OPERATION_ERROR; i--)
            {
                delay_ms(1);
                err = sd_evt_get(&evt_id);
            }
       }
        delay_ms(1);
        log_dbg("i = %d, evt_id = %d", __func__, i, evt_id);
    }

  • , it might be better if you post a new question with more details about your setup in case your issue is caused by something else (whether you use the Softdevice or not, etc.).

    Anyway, have you tried the sample code I posted above (link)?  

Reply Children
  • Hello.  I just tried it and it works.

    I think problem comes because I didnt have nrf_sdh_soc.c included in my project.

    However when I add it I get this error:

    Output/ant_plus_velo_cb-011 Debug/Obj/nrf_sdh_soc.o:E:\Nordic_Semi\nRF5_SDK_15.2.0\components\softdevice\common/nrf_sdh_soc.c:64: undefined reference to `__start_sdh_soc_observers'
    I have looked through all of my include directories etc but can't find why this error gets thrown in the linker.  Do you have any ideas where I can look?  

    Otherwise I can start to try building my project up again from scratch.

    If it helps, I am using ANT rather than BLE.

    Thank you!

  • Hello,

    bgarrood said:
    I have looked through all of my include directories etc but can't find why this error gets thrown in the linker.  Do you have any ideas where I can look?  

    Yes, the start symbol should be defined in your linker script. Exactly how depends on the toolchain you use. Suggest that you use ble_app_hrs project or other projects that use flash storage, and use that linker script as a reference (flash_placement.xml if you use SES). 

    Edit: forgot to add that nrf_sdh_soc.c is responsible for forwarding the flash events to the fstorage module and is therefore required. See Softdevice handler library documentation (link) for more details. 

  • Dear Vidar,

    Sorry I realised the last two posts were hidden.  I will have a look at the flash_placement.xml file now.

    I have posted a separate question here:

    https://devzone.nordicsemi.com/f/nordic-q-a/45671/using-fstorage-with-ant

    Many thanks.

Related