This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Which are different memory storage option?

Hello, I am using pca10028 and sdk 12.2. I have interfaced temp sensor with nrf51 and now I want to store that data continuously in memory of nrf51. I want to store min 4k sample consisting of 2 bytes of data. So should I prefer fds or pstorage or fstorage? Can I get example code to do this? Also I am am facing difficulty in displaying output through uart although code doesnt gives me error. I am attaching my code . Please let me know suggestions. Thanks, Shailav

error - debug1.PNG

Parents
  • FormerMember
    0 FormerMember

    For storing data, I would recommend using FDS. With FDS it is easy to store and retrieve data. FDS uses the fstorage module. Pstorage is the old storage module, and it is no longer being updated.

    For how to use FDS with the softdevice, you can take a look at the example ble_app_hrs-fds-test-github.zip in this answer.

    When adding FDS and using BLE, you will need to add the following in addition to what is in the documentation on the infocenter:

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        // Dispatch the system event to the fstorage module, where it will be
        // dispatched to the Flash Data Storage (FDS) module.
        fs_sys_event_handler(sys_evt);
       ...
    }
    
    
    static void ble_stack_init(void)
    {
        ...
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    } 
    

    For explanation on why that code section is needed, see this answer.

  • FormerMember
    0 FormerMember in reply to FormerMember

    Below is the needed FDS part in sdk_config.h (nRF51822):

     // <e> FDS_ENABLED - fds - Flash data storage module
    //==========================================================
    #ifndef FDS_ENABLED
    #define FDS_ENABLED 1
    #endif
    #if  FDS_ENABLED
    // <o> FDS_OP_QUEUE_SIZE - Size of the internal queue. 
    #ifndef FDS_OP_QUEUE_SIZE
    #define FDS_OP_QUEUE_SIZE 4
    #endif
    
    // <o> FDS_CHUNK_QUEUE_SIZE - Determines how many @ref fds_record_chunk_t structures can be buffered at any time. 
    #ifndef FDS_CHUNK_QUEUE_SIZE
    #define FDS_CHUNK_QUEUE_SIZE 8
    #endif
    
    // <o> FDS_MAX_USERS - Maximum number of callbacks that can be registered. 
    #ifndef FDS_MAX_USERS
    #define FDS_MAX_USERS 8
    #endif
    
    // <o> FDS_VIRTUAL_PAGES - Number of virtual flash pages to use. 
    // <i> One of the virtual pages is reserved by the system for garbage collection.
    // <i> Therefore, the minimum is two virtual pages: one page to store data and
    // <i> one page to be used by the system for garbage collection. The total amount
    // <i> of flash memory that is used by FDS amounts to @ref FDS_VIRTUAL_PAGES
    // <i> @ref FDS_VIRTUAL_PAGE_SIZE * 4 bytes.
    
    #ifndef FDS_VIRTUAL_PAGES
    #define FDS_VIRTUAL_PAGES 3
    #endif
    
    // <o> FDS_VIRTUAL_PAGE_SIZE  - The size of a virtual page of flash memory, expressed in number of 4-byte words.
     
    
    // <i> By default, a virtual page is the same size as a physical page.
    // <i> The size of a virtual page must be a multiple of the size of a physical page.
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef FDS_VIRTUAL_PAGE_SIZE
    #define FDS_VIRTUAL_PAGE_SIZE 256
    #endif
    
    #endif //FDS_ENABLED
    // </e>
    
    // <e> FSTORAGE_ENABLED - fstorage - Flash storage module
    //==========================================================
    #ifndef FSTORAGE_ENABLED
    #define FSTORAGE_ENABLED 1
    #endif
    #if  FSTORAGE_ENABLED
    // <o> FS_QUEUE_SIZE - Configures the size of the internal queue. 
    // <i> Increase this if there are many users, or if it is likely that many
    // <i> operation will be queued at once without waiting for the previous operations
    // <i> to complete. In general, increase the queue size if you frequently receive
    // <i> @ref FS_ERR_QUEUE_FULL errors when calling @ref fs_store or @ref fs_erase.
    
    #ifndef FS_QUEUE_SIZE
    #define FS_QUEUE_SIZE 4
    #endif
    
    // <o> FS_OP_MAX_RETRIES - Number attempts to execute an operation if the SoftDevice fails. 
    // <i> Increase this value if events return the @ref FS_ERR_OPERATION_TIMEOUT
    // <i> error often. The SoftDevice may fail to schedule flash access due to high BLE activity.
    
    #ifndef FS_OP_MAX_RETRIES
    #define FS_OP_MAX_RETRIES 3
    #endif
    
    // <o> FS_MAX_WRITE_SIZE_WORDS - Maximum number of words to be written to flash in a single operation. 
    // <i> Tweaking this value can increase the chances of the SoftDevice being
    // <i> able to fit flash operations in between radio activity. This value is bound by the
    // <i> maximum number of words which the SoftDevice can write to flash in a single call to
    // <i> @ref sd_flash_write, which is 256 words for nRF51 ICs and 1024 words for nRF52 ICs.
    
    #ifndef FS_MAX_WRITE_SIZE_WORDS
    #define FS_MAX_WRITE_SIZE_WORDS 256
    #endif
    
    #endif //FSTORAGE_ENABLED
    // </e>
    
Reply
  • FormerMember
    0 FormerMember in reply to FormerMember

    Below is the needed FDS part in sdk_config.h (nRF51822):

     // <e> FDS_ENABLED - fds - Flash data storage module
    //==========================================================
    #ifndef FDS_ENABLED
    #define FDS_ENABLED 1
    #endif
    #if  FDS_ENABLED
    // <o> FDS_OP_QUEUE_SIZE - Size of the internal queue. 
    #ifndef FDS_OP_QUEUE_SIZE
    #define FDS_OP_QUEUE_SIZE 4
    #endif
    
    // <o> FDS_CHUNK_QUEUE_SIZE - Determines how many @ref fds_record_chunk_t structures can be buffered at any time. 
    #ifndef FDS_CHUNK_QUEUE_SIZE
    #define FDS_CHUNK_QUEUE_SIZE 8
    #endif
    
    // <o> FDS_MAX_USERS - Maximum number of callbacks that can be registered. 
    #ifndef FDS_MAX_USERS
    #define FDS_MAX_USERS 8
    #endif
    
    // <o> FDS_VIRTUAL_PAGES - Number of virtual flash pages to use. 
    // <i> One of the virtual pages is reserved by the system for garbage collection.
    // <i> Therefore, the minimum is two virtual pages: one page to store data and
    // <i> one page to be used by the system for garbage collection. The total amount
    // <i> of flash memory that is used by FDS amounts to @ref FDS_VIRTUAL_PAGES
    // <i> @ref FDS_VIRTUAL_PAGE_SIZE * 4 bytes.
    
    #ifndef FDS_VIRTUAL_PAGES
    #define FDS_VIRTUAL_PAGES 3
    #endif
    
    // <o> FDS_VIRTUAL_PAGE_SIZE  - The size of a virtual page of flash memory, expressed in number of 4-byte words.
     
    
    // <i> By default, a virtual page is the same size as a physical page.
    // <i> The size of a virtual page must be a multiple of the size of a physical page.
    // <256=> 256 
    // <512=> 512 
    // <1024=> 1024 
    
    #ifndef FDS_VIRTUAL_PAGE_SIZE
    #define FDS_VIRTUAL_PAGE_SIZE 256
    #endif
    
    #endif //FDS_ENABLED
    // </e>
    
    // <e> FSTORAGE_ENABLED - fstorage - Flash storage module
    //==========================================================
    #ifndef FSTORAGE_ENABLED
    #define FSTORAGE_ENABLED 1
    #endif
    #if  FSTORAGE_ENABLED
    // <o> FS_QUEUE_SIZE - Configures the size of the internal queue. 
    // <i> Increase this if there are many users, or if it is likely that many
    // <i> operation will be queued at once without waiting for the previous operations
    // <i> to complete. In general, increase the queue size if you frequently receive
    // <i> @ref FS_ERR_QUEUE_FULL errors when calling @ref fs_store or @ref fs_erase.
    
    #ifndef FS_QUEUE_SIZE
    #define FS_QUEUE_SIZE 4
    #endif
    
    // <o> FS_OP_MAX_RETRIES - Number attempts to execute an operation if the SoftDevice fails. 
    // <i> Increase this value if events return the @ref FS_ERR_OPERATION_TIMEOUT
    // <i> error often. The SoftDevice may fail to schedule flash access due to high BLE activity.
    
    #ifndef FS_OP_MAX_RETRIES
    #define FS_OP_MAX_RETRIES 3
    #endif
    
    // <o> FS_MAX_WRITE_SIZE_WORDS - Maximum number of words to be written to flash in a single operation. 
    // <i> Tweaking this value can increase the chances of the SoftDevice being
    // <i> able to fit flash operations in between radio activity. This value is bound by the
    // <i> maximum number of words which the SoftDevice can write to flash in a single call to
    // <i> @ref sd_flash_write, which is 256 words for nRF51 ICs and 1024 words for nRF52 ICs.
    
    #ifndef FS_MAX_WRITE_SIZE_WORDS
    #define FS_MAX_WRITE_SIZE_WORDS 256
    #endif
    
    #endif //FSTORAGE_ENABLED
    // </e>
    
Children
No Data
Related