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

NRF52840 Fstorage

Hi,

I would like to store 180 000 bytes on the flash with fstorage. By using the example after some trouble it works. When I try to apply this example on my own program, it is limited to 1000 bytes. I think that it is due to a parameter on sdk_config.h ! any idea ?

regards

Parents
  • Hi,

    There is a maximum if you use the SoftDevice, which is configurable with NRF_FSTORAGE_SD_MAX_WRITE_SIZE. That does not change the SoftDevice implementation though, and fstorage will handle it by splitting the write in smaller parts. Other then that, the only limitation is that you must write to a page aligned address, and that the length must be a multiple of 4.

    What do you do, and how does it fail?

  • yes i use a softdevice

    NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
    {
        /* Set a handler for fstorage events. */
        .evt_handler = fstorage_evt_handler,

        /* These below are the boundaries of the flash space assigned to this instance of fstorage.
         * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
         * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
         * last page of flash available to write data. */
        .start_addr = 0x40000,
        .end_addr   = 0x6Dfff,
    };

    NRF_FSTORAGE_SD_MAX_WRITE_SIZE = 4096 as on the example

    actually, there is no fail, no error, but i have data only between 0x40000 and 0x41000

    it works on the example but not in my program :-(

    regards

Reply
  • yes i use a softdevice

    NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
    {
        /* Set a handler for fstorage events. */
        .evt_handler = fstorage_evt_handler,

        /* These below are the boundaries of the flash space assigned to this instance of fstorage.
         * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
         * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
         * last page of flash available to write data. */
        .start_addr = 0x40000,
        .end_addr   = 0x6Dfff,
    };

    NRF_FSTORAGE_SD_MAX_WRITE_SIZE = 4096 as on the example

    actually, there is no fail, no error, but i have data only between 0x40000 and 0x41000

    it works on the example but not in my program :-(

    regards

Children
  • 0x1000 is equal to 4096 bytes, do you confirme that in case I try to write more than 4096 bytes, it will be done in further part automatically or do I perform further write with only 4096 bytes ?

  • ciramor said:
    0x1000 is equal to 4096 bytes

     Yes, that is correct (so this is 1024 words, which is a full flash page).

    ciramor said:
    do you confirme that in case I try to write more than 4096 bytes, it will be done in further part automatically or do I perform further write with only 4096 bytes ?

     Yes, if you try to write more than NRF_FSTORAGE_SD_MAX_WRITE_SIZE, it will be split in several writes. You should get an error if something goes wrong. Do you not? Do you get the event indicating that write completed? You could also try to reduce NRF_FSTORAGE_SD_MAX_WRITE_SIZE to half, though if that was the problem you should have got a SoftDevice assert.

  • hi Thank you for your answer

    I tried too with smaller table, even below 4096 bytes and perform the same write on an other adress 0x42000 for example, the second write never occurs, so seems that the flash is not ready. Seems to be my problem !!

    if I use the function wait_for_flash_ready(), I stay in the loop. it explains the behaviour.

    i already met this problem and I understood that priority must be changed on sdk_config.h

    do you confirm that only this parameter (see below) must be lower priority ? because even by changing priority, I have the same behaviour !

    / <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest)
    // <1=> 1
    // <2=> 2
    // <3=> 3
    // <4=> 4
    // <5=> 5
    // <6=> 6
    // <7=> 7

    #ifndef APP_TIMER_CONFIG_IRQ_PRIORITY
    #define APP_TIMER_CONFIG_IRQ_PRIORITY 4  //6
    #endif

    regards

    seb

  • Hi Seb,

    What you are describing here is a general issue when working with different interrupt priorities. If you wait for something in one thread/task/ISR/etc. that should happen in another, that must have a higher interrupt priority. The typical way to solve this is to wait with low priority. So for instance, do your flash writing from your main loop and not a interrupt. That is often the simplest and best approach. You could also try to work with priorities, but in many nRF applications your interrupts will come from the SoftDevice and if you do your work there it will be the same priority as fstorage (which in the end also is the SoftDevice in this case).

    So in a nutshell: try to write to flash and wait from your main loop and not in an interrupt/event handler.

Related