freertos + fds

Hi. I am trying to add FDS to my application where I used freertos and ble. I tried few things always ending with hardfault, one time it was from Freertos scheduler and the other times I cannot really tell.

- first I was trying to simply add fds_record_write() as fds was already initilized by peer_manager

- second I removed peer manager and initlized fds myself, I got the fds_init event but on fds_record_write() attempt it failed with harfault - altthough call to fds_record_write() itself returned success

- third I took raw (unmodified) ble_app_hrs_freertos and tried to add fds_record_write() on every battery_level_update. 

Until I tried third solution I was thinking that maybe something was witihin my app but looks like it is something (bug?) with fds/freertos. 

Can someone advise me what is proper way to use FDS with Freertos?

Thanks

  • It looks like problem is with writing data to flash from interrupt context. All of 3 attempts I was trying to use fds_record_write() from either gpio interrupt or freertos timer interrupt. However I did not find any documentation that would confirm this.

    I tried using it from main context and works ok.

    It would be nice if someone can confirm this and either fix documentation or show me where in documentation it is said that function cannot be used from interrupt context.

    Regards

  • Hi,

    You might get into problems with interrupt context depending on how you write your code. For instance, you cannot wait inside higher interrupt level for the FDS event coming on a lower interrupt level. But in the general case calling FDS APIs from interrupt context should not be an issue, at least not as I am aware of.

    When using FreeRTOS and SoftDevice, make sure to define SOFTDEVICE_PRESENT. If not then that might explain strange behavior such as hardfaults and asserts.

    Initializing FDS even though peer manager has already done the same should not be a problem, ref. Flash Data Storage Usage documentation: "In the Peer Manager, fds_init is part of the initialization function pm_init. The module can be initialized multiple times, with no side effects."

    Regards,
    Terje

  • I have similar problems on the very same setup. I can also confirm that the fds_record_write() returns FDS_SUCCESS and it never really finishes writing anything. However, When I dump the flash afterwards,  you can see below that it writes my word size (15) and record key (0x0C13), but not the actual data (i ran it three times, hence the 3 "dirty" records). I have no idea why this happens. When i take the fds_record_write() out of the FreeRTOS task function by running it before vTaskStartScheduler() it works perfectly.

    0x000FDFE0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FDFF0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE000: DEADC0DE F11E01FE 000F0C13 FFFFFFFF   |................|
    0x000FE010: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE020: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE030: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE040: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE050: 000F0C13 FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE060: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE070: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE080: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE090: FFFFFFFF FFFFFFFF 000F0C13 FFFFFFFF   |................|
    0x000FE0A0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE0B0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE0C0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE0D0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE0E0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    0x000FE0F0: FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF   |................|
    

  • for @Kosmine and any other:
    In my case problem was that when opening existing record I was using local variable `record` and didnt copy it to my global one. So there was no error just a mistake in programming. I advise you to double check flow of your application and maybe try to debug and see what values are available in `record` after callig `fds_record_open`. Regards !