I can't get callback when I call second pstorage clear function.

Hi,

    I want use 3 block flash. each size is 16bytes. My code as below

int main(void)
{
    check_ant_gpio_mode();
  
    if(factory_dm_mode == 1)
    {
        power_check();
        sense_gpio_init();
        control_uart_init();
    
        adc_configure();
    
        //Peer manager init,then we can connect BLE
        peer_manager_init(true);
        
        utils_setup();
        softdevice_setup();
  
        factory_control_dynamometer();
    }
}

void factory_control_dynamometer()
{
    uint32_t err_code;
    static uint16_t omega = 0;  // angular velocity to be set, unit is rpm
    
    while(1)
    {
        if(start_test == 0)
        {
            start_test = 1;
            
            pstorage_data_init();
            pstorage_torque_0_clear();
            pstorage_torque_w_clear();
            pstorage_torque_i_clear();
        }
    }
}

static void example_cb_handler(pstorage_handle_t  *handle,
			       uint8_t            op_code,
                               uint32_t           result,
                               uint8_t            *p_data,
                               uint32_t           data_len)
{   
    if(handle->block_id == pstorage_torque_0_wait_handle) 
    { 
        pstorage_torque_0_wait_flag = 0; 
    } 
    else if(handle->block_id == pstorage_torque_w_wait_handle) 
    { 
        pstorage_torque_w_wait_flag = 0; 
    } 
    else if(handle->block_id == pstorage_torque_i_wait_handle) 
    { 
        pstorage_torque_i_wait_flag = 0; 
    } 
}

static void pstorage_data_init(void)
{
    uint32_t retval;
    
    //1. torque_0 array: 16x4 => 2 x 18 x 2bytes + 2 bytes header => 74 Bytes
    //2. torque_w array: 2x2 => 2 x 2 x 2bytes + 2bytes contact + 2 bytes header => 12 Bytes 
    //3. torque_i array: 2x2 => 2 x 11 x 2bytes + 2bytes contact + 2 bytes header => 48 Bytes 
			     
    param.block_size  = 16;           
    param.block_count = 3;                  
    param.cb          = example_cb_handler; 
			
    retval = pstorage_register(&param, &pstorage_handle);
    pstorage_block_identifier_get(&pstorage_handle, 0, &block_torque_0_handle);
    pstorage_torque_0_wait_handle = block_torque_0_handle.block_id;
    
    pstorage_block_identifier_get(&pstorage_handle, 1, &block_torque_w_handle);
    pstorage_torque_w_wait_handle = block_torque_w_handle.block_id;
    
    pstorage_block_identifier_get(&pstorage_handle, 2, &block_torque_i_handle);
    pstorage_torque_i_wait_handle = block_torque_i_handle.block_id;
}

static void pstorage_torque_0_clear(void)
{
    uint32_t retval;

    pstorage_torque_0_wait_flag = 1;                              
    retval = pstorage_clear(&block_torque_0_handle, 16);                       				
    while(pstorage_torque_0_wait_flag) 
    {
        //nrf_delay_ms(10);
    }              		

}

static void pstorage_torque_w_clear(void)
{
    uint32_t retval;

    pstorage_torque_w_wait_flag = 1;                              
    retval = pstorage_clear(&block_torque_w_handle, 16);                       				
    while(pstorage_torque_w_wait_flag) 
    {
        //nrf_delay_ms(10);
    }              		

}

static void pstorage_torque_i_clear(void)
{
    uint32_t retval;

    pstorage_torque_i_wait_flag = 1;                              
    retval = pstorage_clear(&block_torque_i_handle, 16);                       				
    while(pstorage_torque_i_wait_flag) 
    {
        //nrf_delay_ms(10);
    }              		

}

When I call pstorage_torque_0_clear(). I can get flag change from callback function.

but then call pstorage_torque_1_clear(). I can not get flag change from callback function.

I think the callback function did not enter this. Why?

    

Parents Reply
  • Hi,

    pstorage is not supported in SDK 14.2.0, it was removed in SDK 12.0.0, as its functionality had been replaced by Flash storage (fstorage)/Flash Data Storage (FDS). Did you port/copy the library from an older SDK version?

    It looks like you also use peer_manager in your code, this may use fstorage/FDS to store bonding data, which may conflict with your use of pstorage.

    JohnCC said:
    I don't know what is reasonable. If I get number 0,1,2 id. Those will be 520192,520272,520352

    This sounds reasonable, it corresponds to 0x7F000, 0x7F050 and 0x7F0A0, which is 80 byte blocks, starting at the beginning of the last page of flash, which is likely where pstorage is configured to store the data. This is also one of the pages that will be used by FDS by default (0x7D000-0x80000).

    Best regards,
    Jørgen

Children
Related