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

How to do pstorage writes while connected?

I'm using s120 v2.1, with SDK 9, on an nRF51 with 256K ROM and 16K RAM. With s120 I only have 6K of usable RAM for my application. I am running critically low on RAM, and while I am looking at ways to better utilize RAM, and reduce the amount of RAM my application uses. I could free up almost 1K of RAM, if I could do a FLASH write while maintaining a connection.

My application is a BLE Remote control. The remote can control a group of up to 8 devices at a time. The user can configure up to 5 groups. When the user needs to configure a group I switch the remote from a central device to a peripheral device. The user can then connect to the remote with their Android or iOS device, and configure the groups. I have to have enough memory to store all 5 groups, then on disconnect I use pstorage_update() to save the data. If I could save the data to Flash, while maintaining a connection, I could cut my RAM usage from 1K to 200 bytes.

I was looking at the post here.

In the post Aryan first states:

you cannot write to flash directly while softdevice is enabled and connections/advertising/scanning is active

But then says:

You can use either pstorage API or SOC API (sd_flash_write) to access flash safely while in connections

I followed the link labelled documentation and thought I had done everything outlined, but my connection is dropped when I try to do the update. Note - during the write to FLASH, I only need to maintain the connection, all other BLE operations can wait until the write is complete.

I know waiting until there is no connection, advertising, or scanning (basically any radio operations) is the preferred method, but in this case I need the RAM.

Is writing to FLASH possible, while maintaining a connection (several threads imply that it is)? Is there an example that actually writes to the FLASH while maintaining a connection?

Thanks, Clint

  • I am using pstorage succesfully to flash the data during connection.

    But... why don't you just go to chip with 32kB RAM...?

  • This is a firmware upgrade for existing hardware that was built prior to the 32K RAM chip being available. All new builds have the 32K RAM parts

    Did you start with a Nordic example, if so which one?

    edit. sorry, i missclicked and converted this comment to answer :/

  • I just used pstorage api - you can read its documentation on infocenter.

  • Hi

    flash erase operation takes about 21ms. pstorage_update contains two flash erase operations under the hood. It will have impact on BLE communication if the connection interval is <30ms. flash operation and radio activity can not happen concurrently. The softdevice will drop packets in order to fit in a flash operation. If the connection timeout is too short, the connection will be lost. Could that be the case?

    Try to play around with the connection interval and the connection timeout, to see if that fixes the problem

  • c cook how did you eventually solve this? With sd_flash_write or changing the connection interval? Thx!

1 2