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

BLE Advertising module still uses pstorage in SDK 11?

I'm trying to migrate a BLE peripheral app on nRF51822 from SDK 10 and s110 to SDK 11 and s130.

I saw that the new Peer Manager does away with pstorage in favour of fstorage. I've migrated most of my code over and notice I'm now going to be very tight for RAM.

I was then disappointed to see that /ble/ble_advertising/ble_advertising.c includes pstorage.h. Must I now link in both pstorage and fstorage in order to advertise and use the Peer Manager? This will probably run me out of flash, or RAM, or both.

If so, are you going to move away from pstorage for this in SDK 12?

  • Hi,

    Pstorage does not need to be linked in when using fstorage, and should have been removed from the SDK examples using peer manager / fstorage (reported as bug internally). The problem lays in the flash_access_in_progress() function which uses both fstorage and pstorage API to check for pending flash operations:

    static bool flash_access_in_progress()
    {
    uint32_t err_code;
    uint32_t count = 0;
    
    // Will always return NRF_ERROR_INVALID_STATE since pstorage is not initialized
    err_code = pstorage_access_status_get(&count);
    if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_SUCCESS))
    {
        ADV_LOG("[ADV]: pstorage_access_status_get returned %d.\r\n", err_code);
        return true;
    }
    
    if (err_code == NRF_ERROR_INVALID_STATE)
    {
        err_code = fs_queued_op_count_get(&count);
        if (err_code != FS_SUCCESS)
        {
            return false;
        }
        ADV_LOG("[ADV]: fs_queued_op_count_get gives count %d.\r\n", count);
    }
    
    if(count != 0)
    {
        return true;
    }
    else
    {
        return false;
    }
    }
    

    But the pstorage call won't have any effect since it is not initialized and therefore safe to remove:

    static bool flash_access_in_progress()
    {
       uint32_t err_code;
       uint32_t count = 0;
    
       err_code = fs_queued_op_count_get(&count);
       if (err_code != FS_SUCCESS)
       {
           return false;
       }
       ADV_LOG("[ADV]: fs_queued_op_count_get gives count %d.\r\n", count);
    
    
      if(count != 0)
      {
          return true;
       }
       else
       {
          return false;
       }
    }
    

    Note that fstorage and pstorage are not designed to co-exist in the same project so the advertising module should either use pstorage_access_status_get() or fs_queued_op_count_get depending on what module is used in the application, but not both (wasting memory).

  • Not clear, sorry. The BLE advertising module does still use pstorage in SDK 11, yes? So if I want to use the Peer Manager and advertise, I must use both pstorage and pstorage in the one project?

  • rewrote my answer, hope it is more clear now. The short answer is that you can remove any reference to pstorage in your code.

  • But it's not in my code. It's not even in the example project's code. It's your code - it's in the SDK. It's ble_advertising.c L185. Are you saying it's an SDK bug?

Related