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

sd_flash_write only once

I'm attaching a function where I use the sd function :

    void edit_speed_ID(uint8_t speed)
    {		
uint32_t value;//, err_code;
value=5  * speed;
while(sd_flash_write(address,(uint32_t *) & value,1)==NRF_ERROR_BUSY);
nrf_delay_ms(1000);
pattern_ID_3();
     }

the problem is that, when I call this function for the first time, it works fine & if I try to call this function its call is done correctly but the sd_flash_write doesn't overwrite the written value for the first time even I don't change the address passed to the sd_flash_write

Parents
  • I use this code:

    static pstorage_handle_t m_p_example_id;
    static pstorage_ntf_cb_t example_cb_handler;
      uint16_t dummy_block = 0;
    uint16_t dummy_size  = 4;
    uint16_t dummy_offset = 0;
    pstorage_handle_t p_block_id;
    
    static void example_pstorage_init()
    {
    uint32_t err_code;         
    pstorage_module_param_t p_example_param;    
    // Setup pstorage with 10blocks of 16byte in each.
    p_example_param.block_size  = 0x04; // recommended to be >= 4 byte
    p_example_param.block_count = 10;
    p_example_param.cb          = example_cb_handler;
    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);  
    err_code = pstorage_register (&p_example_param, &m_p_example_id);
    APP_ERROR_CHECK(err_code);  
    }
    
    	int main(void)
    	{ 	
    			// Initialize
    			//flash_init();
    			leds_init();
    			timers_init();
    			gpiote_init();
    			ble_stack_init();
    			scheduler_init();    
    			gap_params_init();
    			services_init();
    			advertising_init();
    			conn_params_init();
    			sensor_simulator_init();
    			sec_params_init();
    					example_pstorage_init();
    
    			// Start execution
    			advertising_start();
    			LPCOMP_init();
    			// Enter main loop
    			for (;;)
    			{
    					app_sched_execute();
    					power_manage();
    			}
    	}
    
    void edit_speed_ID(uint8_t speed)
    {	
    	//	uint8_t * value;
    		uint32_t err_code;
    	//	*value =speed;
    		err_code = pstorage_block_identifier_get(&m_p_example_id, dummy_block, &p_block_id);
    		APP_ERROR_CHECK(err_code);
    		err_code = pstorage_store(&p_block_id,&speed, dummy_size, dummy_offset);
    		APP_ERROR_CHECK(err_code);
        }
    

    it caused me not to see the bluetooth device & I'm unable to communicate with it

  • Deleting the error check isnt' the right idea at all. The error check is telling you that one of your calls to one of the pstorage functions failed and it's telling you WHY it failed. You need to fix the underlying problem by looking at the error code returned, understanding why you have it and fixing the problem. Functions are defined to return error codes to tell you you have made an error and have you fix it, you can't just ignore them. So put the error check back and go figure out what you're doing wrong by checking the error codes, they are documented.

    And I have no idea what you mean about using static variables. That's not going to help you with long-term storage when the power goes off, static variables are in RAM.

    Go look at the error codes, if you don't understand them, post them.

Reply
  • Deleting the error check isnt' the right idea at all. The error check is telling you that one of your calls to one of the pstorage functions failed and it's telling you WHY it failed. You need to fix the underlying problem by looking at the error code returned, understanding why you have it and fixing the problem. Functions are defined to return error codes to tell you you have made an error and have you fix it, you can't just ignore them. So put the error check back and go figure out what you're doing wrong by checking the error codes, they are documented.

    And I have no idea what you mean about using static variables. That's not going to help you with long-term storage when the power goes off, static variables are in RAM.

    Go look at the error codes, if you don't understand them, post them.

Children
No Data
Related