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

fstorage with nrf51 and sdk12.2

i want to store and retrieve data in flash. i followed steps as in the sdk infocenter but i am not getting the interrupt after fs_store(). Actually return value of fs_store() i am getting success but interrupt is not executed. i changed only the start address of write as in the program // p_config_i->p_start_addr = p_current_end - (p_config_i->num_pages * FS_PAGE_SIZE_WORDS);

to p_config_i->p_start_addr = p_current_end - 50 * FS_PAGE_SIZE_WORDS;

because i think if write in the beginning addresses it may corrupt the board.i AM using a soft device also.is the start address assignment got any problem. so my registered interrupt is not serviced, how to sort out this problem

  • Could you try this..it would much easy to store data.

    #if     defined(NRF51)
    #define PAGE_SIZE_WORDS 256
    #elif defined (NRF52)
    #define PAGE_SIZE_WORDS 1024
    #endif
    
    uint32_t page_1_datas[PAGE_SIZE_WORDS];
    uint8_t  erase_flag=0;
    uint8_t  store_flag=0;
    
    static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
    {
    	 if( (evt->id == FS_EVT_STORE) && (result == FS_SUCCESS) ){
    		    store_flag = 0;
    		    NRF_LOG_RAW_INFO("store_flag: %d  \r\n", store_flag);
    	 }else if( (evt->id == FS_EVT_ERASE) && (result == FS_SUCCESS) ){
    		    erase_flag = 0;
    		    NRF_LOG_RAW_INFO("erase_flag: %d  \r\n", erase_flag);
    	 }else if (result != NRF_SUCCESS) {
    				NRF_LOG_RAW_INFO("fstorage error and code: %d  \r\n", result);
    	 }
    }
    
    FS_REGISTER_CFG(fs_config_t fs_config) =
    {
        .callback  = fs_evt_handler,// Function for event callbacks.
        .num_pages = 1,             // Number of physical flash pages required.
        .priority  = 0xFE           // Priority for flash usage.
    };
    
    // Retrieve the address of a page.
    static uint32_t const * address_of_page(uint16_t page_num)
    {
        return fs_config.p_start_addr + (page_num * PAGE_SIZE_WORDS);
    }
    
    void m_flash_read_page_0 (const uint32_t* address)
    {
    	uint32_t* m_addr = (uint32_t*)address;
    	for(int i=0; i<PAGE_SIZE_WORDS; i++ ){
    		  page_1_datas[i] = *m_addr;
    	    //NRF_LOG_INFO("Data: %d\r\n",m_tbd_obj.flash_test[i]);
    		  m_addr++;
    	}
    }
    
    void m_flash_write_page_0(void)
    {
    	  fs_ret_t ret;
    	  erase_flag=1;
    	  // Erase one page (page 0).
        ret = fs_erase(&fs_config, address_of_page(0), 1,NULL);
        if (ret != FS_SUCCESS)
        {
           NRF_LOG_INFO("fs_erase error\r\n");
        }
    			else
    		{
    			  NRF_LOG_INFO("fs_erase FS_SUCCESS\r\n");
    		}
    	  while(erase_flag == 1) { power_manage(); }
    	 
    	  store_flag=1;
        ret = fs_store(&fs_config, fs_config.p_start_addr, page_1_datas, PAGE_SIZE_WORDS,NULL);
        if (ret != FS_SUCCESS)
        {
            NRF_LOG_INFO("fs_store error\r\n");
        }
    		else
    		{
    			  NRF_LOG_INFO("fs_store FS_SUCCESS\r\n");
    		}
    	  while(store_flag == 1) { power_manage(); }
    }
    
    void m_flash_erase_page_0(void)
    {
    	  erase_flag=1;
    	  // Erase one page (page 0).
        fs_ret_t ret = fs_erase(&fs_config, address_of_page(0), 1, NULL);
        if( ret != FS_SUCCESS )
        {
            NRF_LOG_INFO("fs_erase error\r\n");
        }
    		else
    		{
    			  NRF_LOG_INFO("fs_erase FS_SUCCESS\r\n");
    		}
    		while(erase_flag == 1) { power_manage(); }
    }
    
    int main(void)
    {
        uint32_t err_code;
        bool     erase_bonds;
    
        // Initialize.
        err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        timers_init();
        buttons_leds_init(&erase_bonds);
        ble_stack_init();
        peer_manager_init(erase_bonds);
        if (erase_bonds == true)
        {
            NRF_LOG_INFO("Bonds erased!\r\n");
        }
        gap_params_init();
        advertising_init();
        services_init();
        conn_params_init();
    		
    		//==================================================
    		fs_ret_t ret = fs_init();
        if( ret != FS_SUCCESS ){
           NRF_LOG_INFO("fs_init failed\r\n");
        }else{
    			 NRF_LOG_INFO("fs_init OK\r\n");
    			 m_flash_erase_page_0();
    		}
    		//==================================================
    		
    
        // Start execution.
        NRF_LOG_INFO("Template started\r\n");
        application_timers_start();
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    
        // Enter main loop.
        for (;;)
        {
            if (NRF_LOG_PROCESS() == false)
            {
                power_manage();
            }
        }
    }
    
  • Hey, i hope it´s ok if i pick up this question again. I am trying to use the flash storage for some data aswell, but i can´t get the event handler to work, the software seems to stuck after 2 loops after fs_erase FS_SUCCESS.

     while(erase_flag == 1) { power_manage();SEGGER_RTT_printf(0,"loop\r\n"); } 
    

    The event handler doesn´t fire at all. Any ideas?

    Best regards

  • Can you try uncomenting the call to fs_sys_event_handler() on main.c:sys_evt_dispatch()?

    That works for me...

Related