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

FDS erase

Hello,

I need to reset FDS. How can I get it's address / size in code ? How to erase it's area ?

Thank you.

Parents
  • Hi
    You can use nrfjprog for erasing the data in flash if it's not a part of your application. However, if it's part of your application then you can use nrf_fstorage_erase(). Flash can contain a lot of stuff, boot-loader, softdevice, application etc. Erasing flash would therefore require you to have an overview of its contents. If not, you can risk deleting the application itself. SES gives an overview of the content of flash after compilation. I would recommend  that you use the FDS module so that you avoid the scenario of having to erase the entire flash. The FDS module gives you a reference to data in flash with its files, and records. You write that you get a fatal error when you use  nrf_fstorage_erase(), could be more specific? What kind of error code is thrown? What are the parameters you use in  nrf_fstorage_erase()? 
    Jared 
  • Error printed fatal error on RTT output (in event management)

    I finally found a way to create my "FDS" format that works nice. Thank you for your help.

  • This sounds interesting. Is this code publicly  accessible on github?

  • void fds_erase()
    {
    	flash_bounds_set();
    	
    	NRF_LOG_INFO("FDS area is 0x%08X - 0x%08X", m_fs.start_addr, m_fs.end_addr - 1);
    	
    
    	ret_code_t rc = nrf_fstorage_init(&m_fs, &nrf_fstorage_nvmc, NULL); // only working for bootloader
    
    	if (rc == NRF_SUCCESS)
    	{
    		NRF_LOG_INFO("nrf_fstorage_init OK");
    	}
    	else
    	{
    		NRF_LOG_ERROR("nrf_fstorage_init error (%d)", rc);
    		return;
    	}
    	
    	for (int a = m_fs.start_addr; a < m_fs.end_addr; a++)
        {
    		unsigned char * fds_area = (unsigned char *) a;
            if (fds_area[0] != 0xFF)
            {
                NRF_LOG_INFO("FDS not clear at 0x%08X", a);
    			break;
            }
        }
    	
    	for (int p = 0; p < FDS_VIRTUAL_PAGES; p++)
    	{
    		NRF_LOG_INFO("FDS erasing page %d", (int) p);
    
    		#if   defined(NRF51)
    			int erase_unit = 1024;
    		#elif defined(NRF52_SERIES)
    			int erase_unit = 4096;
    		#endif
    
    		int page_addr = m_fs.start_addr + p * erase_unit; // erase unit == virtual page size
    
    		nrf_nvmc_page_erase(page_addr);
    
    		low_power_delay_ms(200);
    	}
    	
    	for (int a = m_fs.start_addr; a < m_fs.end_addr; a++)
        {
    		unsigned char * fds_area = (unsigned char *) a;
            if (fds_area[0] != 0xFF)
            {
                NRF_LOG_ERROR("FDS erase failed at 0x%08X", a);
    			break;
            }
        }
    		
    	NRF_LOG_INFO("FDS erase finished");
    }

  • This is the part of my code that can interest you (for bootloader).

Reply Children
Related