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

NRF51822: Bonds not saving with SDK5.1.0

I am finding that bonds are not saved to flash when using the latest SDK and S110 SoftDevice.

To test this, I am using the HTS example code, and the Master Dongle. I open Master Control Panel, and [Start Discovery] to list the advertising device.

First, I [select device], then do [Service discovery], [Bond], and [Enable services]. The temperature service starts notifying.

I then click [Disconnect] and [Back] and repeat the process. The bond is still in nRF51822 RAM, so temperature notifies fine.

I then click [Disconnect] and [Back], CYCLE POWER, and repeat the process. Temperature does not notify, the bond is not made since the nRF51822 looses it on power cycle.

I then click [Disconnect] and [Back] and then click [Delete bond info] and repeat. A new bond is created, and temperature is notifying again.

I am using: SDK 5.1.0 S110 6.0.0 production

When using old SDK and S110 (prior to pstorage) the Bond persists over power cycle.

Parents
  • Hi Krishna,

    No I am not turning the entire system off, so this is not the problem.

    The problem is in the function bond_info_store in the file ble_bondmngr.c.

    This function first writes the bond data to the flash, and then writes the CRC to the same page of flash (located immediately before the bond).

    It seems that pstorage does not function correctly when doing two seperate writes to the same page of flash, without any erase operation in between. Indeed, as you can see from my memory dump above, the second write, the CRC, is not written and remains as 0xFFFFFFFF.

    This corrosponds with your own documentaton which states: "Flash memory is unreliable when writing to a block already containing data, a clear operation is needed." devzone.nordicsemi.com/.../a00131.html

    When I change the function bond_info_store to write both CRC and bond to an array*, and then write the array to the flash (using a singe pstorage_store, instead of two), then the bond saves fine.

    This finding has made me very doubtful as to the reliability of the bond manager, particularly since you are unable to reproduce the issue.

    • if anyone else is attempting this fix, make sure your array is persistant! the proper approach is probably to include a field for crc in the structure central_bond_t.
Reply
  • Hi Krishna,

    No I am not turning the entire system off, so this is not the problem.

    The problem is in the function bond_info_store in the file ble_bondmngr.c.

    This function first writes the bond data to the flash, and then writes the CRC to the same page of flash (located immediately before the bond).

    It seems that pstorage does not function correctly when doing two seperate writes to the same page of flash, without any erase operation in between. Indeed, as you can see from my memory dump above, the second write, the CRC, is not written and remains as 0xFFFFFFFF.

    This corrosponds with your own documentaton which states: "Flash memory is unreliable when writing to a block already containing data, a clear operation is needed." devzone.nordicsemi.com/.../a00131.html

    When I change the function bond_info_store to write both CRC and bond to an array*, and then write the array to the flash (using a singe pstorage_store, instead of two), then the bond saves fine.

    This finding has made me very doubtful as to the reliability of the bond manager, particularly since you are unable to reproduce the issue.

    • if anyone else is attempting this fix, make sure your array is persistant! the proper approach is probably to include a field for crc in the structure central_bond_t.
Children
  • Paul,

    You statement:

    "It seems that pstorage does not function correctly when doing two seperate writes to the same page of flash, without any erase operation in between. Indeed, as you can see from my memory dump above, the second write, the CRC, is not written and remains as 0xFFFFFFFF."

    is incorrect. PStorage has no problems with writing to any flash valid location. You are misinterpreting the requirement of having to clear the page before an update. The update is required if and only if there was information at a certain location in the flash and you were trying to update the same location (this is not the same as page). CRC and bond information are written to the same block on the same flash page but different addresses, hence there is no requirement to clear to write the CRC once bond information has been written.

    Also, I did notice that CRC was not written in your dump, which makes me suspect that all flash operations could not be completed before system was turned off.

    Also, CRC is also a persistent global array, one for each bond and system attribute. Hence CRC is already persistent. What you are saving by including CRC in central_bond_t is performing flash write in one operation instead of two. However, you should be aware if you do that, you would be calculating CRC on CRC field as well.

Related