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
  • Here is my working example code:

    Global:

    static pstorage_handle_t base_handle;
    typedef struct ble_XXX_state_s
    {
    	uint32_t magic;
    	uint8_t registered;
    	uint8_t reserved[3];
    	uint8_t XXX[XXX_LENGTH];
    	ble_XXX_XXX_t XXX;
    } ble_XXX_state_t;
    

    Saving:

    pstorage_handle_t block_handle;
    err_code = pstorage_block_identifier_get(&base_handle, 0, &block_handle);
    APP_ERROR_CHECK(err_code);
    err_code = pstorage_update(&block_handle, (uint8_t*)&XXX_state, sizeof(ble_XXX_XXX_t), 0);
    APP_ERROR_CHECK(err_code);
    

    Registration:

    // [ ==== Pstorage initialization and configuration ==== ]
    	
    pstorage_module_param_t param;
    pstorage_handle_t block_handle;
    param.block_size = sizeof(ble_XXX_XXX_t); // XXXstructure
    param.block_count = 1;
    param.cb = pstorage_cb_handler;
    err_code = pstorage_register(&param, &base_handle);
    APP_ERROR_CHECK(err_code);
    	
    err_code = pstorage_block_identifier_get(&base_handle, 0, &block_handle);
    APP_ERROR_CHECK(err_code);
    	
    err_code = pstorage_load((uint8_t*)&XXX_XXX, &block_handle, sizeof(ble_XXX_XXX_t), 0);
    APP_ERROR_CHECK(err_code);
    		
    // If we have not initialized this flash area yet or we want to reset XXX
    if (XXX_XXX.magic != 0xDEADFACE || p_XXX_init->XXX_XXX_XXX== true)
    {
      XXX_XXX.magic = 0xDEADFACE;
      XXX_XXX.XXX.XXX_XXX = 0;
      XXX_XXX.XXX.XXX_XXX = 0;
      XXX_XXX.XXX.XXX_XXX = 0;
      XXX_XXX.XXX_XXX = 0;
      memset((uint8_t*)&XXX_XXX.XXX, 0, XXX_LENGTH);
    }
    else		
    {
      // XXX
    }
    err_code = pstorage_update(&block_handle, (uint8_t*)&XXX_XXX, sizeof(ble_XXX_XXX_t), 0);
    APP_ERROR_CHECK(err_code);
    

    pstorage_platform.h:

    #define PSTORAGE_MAX_APPLICATIONS   3                                                           /**< Maximum number of applications that can be registered with the module, configurable based on system requirements. */
    #define PSTORAGE_MIN_BLOCK_SIZE     0x0010                                                      /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. 
    

    I believe pstorage_min_block_size must be word aligned -- my structure is 0x20 I think.

    Hope this helps!!

  • mohamed, If syntronik's answer helped you, Could you please mark it as accepted answer by clicking the ✓ mark.

    Good practices for acknowledging and encouraging help -> devzone.nordicsemi.com/.../

Reply Children
No Data
Related