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

Problem using Pstorage for 40kb data Storage

Hi, I used the pstorage example mentioned here and got it to work to an extent. A snippet of my code is :

retval = pstorage_init();
		if(retval != NRF_SUCCESS)
		{
			//	nrf_gpio_pin_set(PSTORAGE_ERROR_LED_PIN_NO);
		}
	     
		param.block_size  = 128;                  //Select a block size of 800 bytes
		param.block_count = 16;                   //Select 50 blocks, total of 40 pages (~40 kbytes). Each page is 1024 bytes....
		param.cb          = example_cb_handler;   //Set the pstorage callback handler
			
		retval = pstorage_register(&param, &master_handle);
		if (retval != NRF_SUCCESS)
		{
				//nrf_gpio_pin_set(PSTORAGE_ERROR_LED_PIN_NO);
		}
		
		//Get block identifiers
		pstorage_block_identifier_get(&master_handle, 0, &block_0_handle);
		pstorage_block_identifier_get(&master_handle, 1, &block_1_handle);
		pstorage_block_identifier_get(&master_handle, 2, &block_2_handle);
		pstorage_block_identifier_get(&master_handle, 3, &block_3_handle);
		pstorage_block_identifier_get(&master_handle, 4, &block_4_handle);
		pstorage_block_identifier_get(&master_handle, 5, &block_5_handle);
		pstorage_block_identifier_get(&master_handle, 6, &block_6_handle);
		pstorage_block_identifier_get(&master_handle, 7, &block_7_handle);
		pstorage_block_identifier_get(&master_handle, 8, &block_8_handle);
		pstorage_block_identifier_get(&master_handle, 9, &block_9_handle);
		pstorage_block_identifier_get(&master_handle, 10, &block_10_handle);
		pstorage_block_identifier_get(&master_handle, 11, &block_11_handle);
		pstorage_block_identifier_get(&master_handle, 12, &block_12_handle);
		pstorage_block_identifier_get(&master_handle, 13, &block_13_handle);
		pstorage_block_identifier_get(&master_handle, 14, &block_14_handle);
		pstorage_block_identifier_get(&master_handle, 15, &block_15_handle);
//		pstorage_block_identifier_get(&master_handle, 16, &block_16_handle);
//		pstorage_block_identifier_get(&master_handle, 17, &block_17_handle);
//		pstorage_block_identifier_get(&master_handle, 18, &block_18_handle);
//		pstorage_block_identifier_get(&master_handle, 19, &block_19_handle);
//		pstorage_block_identifier_get(&master_handle, 20, &block_20_handle);
//		pstorage_block_identifier_get(&master_handle, 21, &block_21_handle);
//		pstorage_block_identifier_get(&master_handle, 22, &block_22_handle);
//		pstorage_block_identifier_get(&master_handle, 23, &block_23_handle);
//		pstorage_block_identifier_get(&master_handle, 24, &block_24_handle);
//		pstorage_block_identifier_get(&master_handle, 25, &block_25_handle);
//		pstorage_block_identifier_get(&master_handle, 26, &block_26_handle);
//		pstorage_block_identifier_get(&master_handle, 27, &block_27_handle);
//		pstorage_block_identifier_get(&master_handle, 28, &block_28_handle);
//		pstorage_block_identifier_get(&master_handle, 29, &block_29_handle);
//		pstorage_block_identifier_get(&master_handle, 30, &block_30_handle);
//		pstorage_block_identifier_get(&master_handle, 31, &block_31_handle);
//		pstorage_block_identifier_get(&master_handle, 32, &block_32_handle);
//		pstorage_block_identifier_get(&master_handle, 33, &block_33_handle);
//		pstorage_block_identifier_get(&master_handle, 34, &block_34_handle);
//		pstorage_block_identifier_get(&master_handle, 35, &block_35_handle);
//		pstorage_block_identifier_get(&master_handle, 36, &block_36_handle);
//		pstorage_block_identifier_get(&master_handle, 37, &block_37_handle);
//		pstorage_block_identifier_get(&master_handle, 38, &block_38_handle);
//		pstorage_block_identifier_get(&master_handle, 39, &block_39_handle);
//		pstorage_block_identifier_get(&master_handle, 40, &block_40_handle);
//		pstorage_block_identifier_get(&master_handle, 41, &block_41_handle);
//		pstorage_block_identifier_get(&master_handle, 42, &block_42_handle);
//		pstorage_block_identifier_get(&master_handle, 43, &block_43_handle);
//		pstorage_block_identifier_get(&master_handle, 44, &block_44_handle);
//		pstorage_block_identifier_get(&master_handle, 45, &block_45_handle);
//		pstorage_block_identifier_get(&master_handle, 46, &block_46_handle);
//		pstorage_block_identifier_get(&master_handle, 47, &block_47_handle);
//		pstorage_block_identifier_get(&master_handle, 48, &block_48_handle);
//		pstorage_block_identifier_get(&master_handle, 49, &block_49_handle);
//		pstorage_block_identifier_get(&master_handle, 50, &block_50_handle);
		
		
		
		pstorage_clear(&block_0_handle, (1024));                   //Clear first registered page. A pstorage_clear command must operate within a single page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		pstorage_clear(&block_0_handle, (1024));                    //Clear second registered page
		
		
		
		
		
		
		
		
		//pstorage_store(&block_1_handle, source_data_0, 816, 0);     //Write to flash, only one block is allowed for each pstorage_store command
		//pstorage_store(&block_2_handle, source_data_0, 816, 0);     //Write to flash, only one block is allowed for each pstorage_store command                     //Sleep until store operation is finished 
		pstorage_wait_handle = block_1_handle.block_id;            //Specify which pstorage handle to wait for 
		pstorage_wait_flag = 1;                                    //Set the wait flag. Cleared in the example_cb_handler
		pstorage_store(&block_1_handle, source_data_0, 128, 0);     //Write to flash
		while(pstorage_wait_flag){
									 nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);//nrf_gpio_pin_toggle(CONNECTED_LED_PIN_NO);
						 nrf_delay_ms(1000);
						 nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);//nrf_gpio_pin_toggle(CONNECTED_LED_PIN_NO);
							nrf_delay_ms(1000);
															} //{ power_manage(); }               //Sleep until store operation is finished.
		pstorage_load(array, &block_1_handle, 128, 0);				 //Read from flash, only one block is allowed for each pstorage_load command

Using the code above, I'm able to clear up to 40 pages of data and can write/read but but I have an issue. I have cleared 40kb, however if I change the param.block_size to anything more than 128, or the param.block_count to anything more than 16, the wait flag remains set so my handler is never called. If I remove the while loop connected to the handler, the data written is 0. This issue restricts me to 2048 bytes or 2 pages but I obviously need to use 40. I tried using different values over 128 for param.block_size and over 16 for param.block_count but all combinations resulted in the same problem. Is there any issue that could be causing this?? And how do I fix it??? Thanks for any help :)

Related