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

NO_SWAP error from pages_init() when initializing FDS

I'm using SDK 14.2, S132, and the NRF52832

This problem occurs during the pm_init() function when initializing the soft device. Investigating further has led to the pages_init() function which returns NO_SWAP.

If I erase the flash of the device first and then load the program afterwards, this problem doesn't happen. If I try to use buttonless DFU however, this problem starts to occur.

The firmware that's on the device originally has the following settings:

FDS_VIRTUAL_PAGES 14

FDS_VIRTUAL_PAGE_SIZE 1024

The firmware that's used during DFU has these settings:

FDS_VIRTUAL_PAGES 4

FDS_VIRTUAL_PAGE_SIZE 1024

Everything else should be the same so I feel like this issue is occurring because of the difference in FDS pages. Also, if I use buttonless DFU but there is data stored on the device using FDS, does this data get overwritten?

EDIT: So I think the proper way to go about this would be to erase all the FDS pages that were allocated by the firmware currently on the device so that the new FDS can basically start fresh?

EDIT2: I tried adding logic in the DFU section so that when the device is preparing to enter DFU, it would use sd_flash_page_erase and loop through the FDS_VIRTUAL_PAGES. This immediately returns NRF_ERROR_FORBIDDEN when calling it for page 0 however.

EDIT3: I'm almost at the point of just using fstorage directly and not using FDS at all at this point. I can't find a simple way with the FDS API to erase pages so I just decided to use sd_flash_erase_page directly. I'm calling this function from the main context and I'm setting a flag in nrf_fstorage_sys_evt_handler on the NRF_EVT_FLASH_OPERATION_SUCCESS event so that I can then call the next erase. I've used sd_app_evt_wait() and __WFE() to wait for the flag to be set and they never are set. I also tried to just overwrite the word after 0xDEADC0DE (with sd_flash_write) which is used to identify the page as data to 0xFFFFFFFF in an attempt to just let the FDS clean those pages up when it initializes at boot-up but I get the same problem (NRF_EVT_FLASH_OPERATION_SUCCESS never happens). I can't find anything on the forums that explains why I'm not getting this event.

Parents
  • I fixed this with a similar approach as senorwigglez by wiping out the old data.  I did it by modifying fds_init() to wipe out the data and let FDS re-init.

    I added a parameter force_wipe so the caller can demand a clean start.  If it encountered NO_PAGES or NO_SWAP, then I changed init_opts to FRESH_INSTALL, and let it continue and wipe out the storage rather than failing by returning FDS_ERR_NO_PAGES.  Seems to work so far.

    switch (init_opts)
        {
            case NO_PAGES:
            case NO_SWAP:
                if(eInitMode == FDS_INIT_FORCE_REDO)
                {
                    // they want to force a fresh filesystem on us
                    init_opts = FRESH_INSTALL;
                }
                else
                {
                    return FDS_ERR_NO_PAGES;
                }
    
            case ALREADY_INSTALLED:
            {
                // No initialization is necessary. Notify the application immediately.
                m_flags.initialized  = true;
                m_flags.initializing = false;
                event_send(&evt_success);
                return FDS_SUCCESS;
            }
    
            default:
                break;
        }

Reply
  • I fixed this with a similar approach as senorwigglez by wiping out the old data.  I did it by modifying fds_init() to wipe out the data and let FDS re-init.

    I added a parameter force_wipe so the caller can demand a clean start.  If it encountered NO_PAGES or NO_SWAP, then I changed init_opts to FRESH_INSTALL, and let it continue and wipe out the storage rather than failing by returning FDS_ERR_NO_PAGES.  Seems to work so far.

    switch (init_opts)
        {
            case NO_PAGES:
            case NO_SWAP:
                if(eInitMode == FDS_INIT_FORCE_REDO)
                {
                    // they want to force a fresh filesystem on us
                    init_opts = FRESH_INSTALL;
                }
                else
                {
                    return FDS_ERR_NO_PAGES;
                }
    
            case ALREADY_INSTALLED:
            {
                // No initialization is necessary. Notify the application immediately.
                m_flags.initialized  = true;
                m_flags.initializing = false;
                event_send(&evt_success);
                return FDS_SUCCESS;
            }
    
            default:
                break;
        }

Children
No Data
Related