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

How can i write 10kB of data to internal flash?

Hi,

I use nRF51822 with 256k flash and external sensor, and i want to write the data i receive from it via SPI to internal flash?

After the data received i want to send it to iOS application with s110 uart_app.

How can i do it?

P.S. I tried pstorage option but it always give me one page of 0x400 bytes. How to move to next page?

Thanks

intFlash - Copy.c intFlash - Copy.h

  • hi,Stefan: how to call pstorage operation from an app timer interrupt handler without blocking.

  • @hawk Please add a new question with a detailed description of your problem.

  • @hawk I can answer this here. on nRF51, application timer will always block softdevice callbacks. You need to call pstorage operation from main context in order to ever receive the callback for the pstorage operation.

    You could call the scheduler from the application timer handler and let the scheduler task call the pstorage operation in the main context.

    Another option would be simply to set a global flag in the application timer handler. In the main loop you check for that flag every time you wake up from an interrupt, if the flag is true, you call pstorage operation.

  • Hi,

    Could you help me figure out the bug in the code below.

    I have a code to test writing and loading using pstorage (I use nrf51, SDK11).

    When power on, it will load from flash to check:

    • If data is not existed (=0xFF) it will save the default data to flash
    • Else (data is exist) it will change data then update to flash again. So after each reset, the data loaded must be changed.

    But with my code, the data loaded does not change.

    Help me. Thanks.

    My code:

    	pstorage_handle_t       block_handle;
    	pstorage_module_param_t param;
    	uint8_t					dest_data[4];
    	uint8_t					default_data[4];
    	uint32_t				retval;
    	
    	param.block_size  		= 16;
    	param.block_count 		= 1;
    	param.cb				= app_cb_handler;
    
    	default_data[0] 		= 1;
    	default_data[1] 		= 2;
    	default_data[2] 		= 3;
    	default_data[3] 		= 4;
    	
    	retval = pstorage_init();							// Initialization
    	if(retval == NRF_SUCCESS)
    			printf("\r\nPstorage init success");
    	else
    			printf("\r\nPstorage init failed");
    	retval = pstorage_register(&param, &block_handle);	// Register
    	if(retval == NRF_SUCCESS)
    			printf("\r\nPstorage regis success");
    	else
    			printf("\r\nPstorage regis failed");
    	
    	// Request to read 4 bytes from block at an offset of 0 bytes.
    	retval = pstorage_load(dest_data, &block_handle, 4, 0);
    	if(retval == NRF_SUCCESS)
    			printf("\r\nLoad success");
    	else
    			printf("\r\nLoad failed");
    	if(dest_data[1] == 0xFF)
    	{
    			printf("\r\nData is not exist, save data...");
    			retval = pstorage_clear(&block_handle, 4);
    			if(retval == NRF_SUCCESS)
    					printf("\r\nClear success");
    			else
    					printf("\r\nClear failed");
    			retval = pstorage_store(&block_handle, default_data, 4, 0);
    			if(retval == NRF_SUCCESS)
    					printf("\r\nStore success");
    			else
    					printf("\r\nStore failed");
    	}
    	else
    	{
    			printf("\r\ndata0 = %d", dest_data[0]);
    			printf("\r\ndata1 = %d", dest_data[1]);
    			printf("\r\ndata2 = %d", dest_data[2]);
    			printf("\r\ndata3 = %d", dest_data[3]);
    			dest_data[0] += 1;
    			dest_data[1] += 1;
    			dest_data[2] += 1;
    			dest_data[3] += 1;			
    			retval = pstorage_update(&block_handle, dest_data, 4, 0);
    			if(retval == NRF_SUCCESS)
    					printf("\r\nUpdate success");
    			else
    					printf("\r\nUpdate failed");
    	}
    

    On termial:

    Pstorage init success
    Pstorage regis success
    Load success
    Data is not exist, save data...
    Clear failed
    Store success
    ---Reset---
    Pstorage init success
    Pstorage regis success
    Load success
    data0 = 1
    data1 = 2
    data2 = 3
    data3 = 4
    Update success
    ---Reset---
    Pstorage init success
    Pstorage regis success
    Load success
    data0 = 1
    data1 = 2
    data2 = 3
    data3 = 4
    Update success
    
Related