Hello Everyone , I am using ble stack S110 , BATTERY SERVICE , my CUSTOM SERVICE and pstorage module in my application and using SDK 7.0.0 and keil 5.12 IDE .whenever a server writes anything to a client characteristic data sent by a server shud be written to flash. I am not using device manager init in my application. Following is my main code.
int main(void)
{
// Initialize.
ble_stack_init();
timers_init();
APP_GPIOTE_INIT(1);
uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_evt_handler);
APP_ERROR_CHECK(err_code);
therapy_init();
//device_manager_init();
gap_params_init();
advertising_init();
services_init();
sensor_sim_init();
conn_params_init();
// Start execution.
application_timers_start();
advertising_start();
pstorage_initialization();
pstorage_read_block();
therapy_parameters_read();
// Enter main loop.
for (;;)
{
power_manage();
}
}
I am initializing ble_stack_init() before pstorage_init as mentioned in some post. my pstorage_read,write and update works properly if called just after pstorage_initialization(). but when i call pstorage_write or pstorage_update in my event handler as given below
void on_write_mode_handler(ble_thes_t * p_thes , uint8_t *data)
{
therapy_parameters_write();
pstorage_update_block();
}
it never return from pstorage_update_block and same case if i use write function below is a code snippet.
static void example_cb_handler(pstorage_handle_t * handle,
uint8_t op_code,
uint32_t result,
uint8_t * p_data,
uint32_t data_len)
{
switch(op_code)
{
case PSTORAGE_LOAD_OP_CODE:
if (result == NRF_SUCCESS)
{
if(handle->block_id == pstorage_wait_handle)
{
pstorage_wait_flag = 0;
} //If we are waiting for this callback, clear the wait flag.
}
break;
case PSTORAGE_STORE_OP_CODE:
if (result == NRF_SUCCESS)
{
if(handle->block_id == pstorage_wait_handle)
{
pstorage_wait_flag = 0;
} //If we are waiting for this callback, clear the wait flag.
}
break;
case PSTORAGE_UPDATE_OP_CODE:
if(handle->block_id == pstorage_wait_handle)
{
pstorage_wait_flag = 0;
} //If we are waiting for this callback, clear the wait flag.
if (result == NRF_SUCCESS)
{
}
break;
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS)
{
}
break;
case PSTORAGE_ERROR_OP_CODE:
break;
default:
break;
}
}
void pstorage_initialization()
{
retval = pstorage_init();
if(retval != NRF_SUCCESS)
{
nrf_gpio_pin_clear(LED_4);
}
param.block_size = 16; //Select block size of 16 bytes
param.block_count = 1; //Select 10 blocks, total of 160 bytes
param.cb = example_cb_handler; //Set the pstorage callback handler
retval = pstorage_register(¶m, &handle);
if (retval != NRF_SUCCESS)
{
nrf_gpio_pin_set(LED_4);
}
}
uint32_t pstorage_write_block(void)
{
int i;
//Get block identifier
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
pstorage_clear(&block_0_handle, 16); //Clear 48 bytes
pstorage_wait_handle = block_0_handle.block_id; //Specify which pstorage handle to wait for
pstorage_wait_flag = 1; //Set the wait flag. Cleared in the example_cb_handler
//Store data to block. Wait for the last store operation to finish before reading out the data.
pstorage_store(&block_0_handle, source_data_0, 16, 0); //Write to flash, only one block is allowed for each pstorage_store command
//while(pstorage_wait_flag) { power_manage(); } //Sleep until store operation is finished.
for(i=0; i < 1000;i++)
{
}
}
void pstorage_read_block()
{
//Get block identifiers
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
pstorage_wait_handle = block_0_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_load(dest_data_0, &block_0_handle, 16, 0); //Read from flash, only one block is allowed for each pstorage_load command
while(pstorage_wait_flag) { power_manage(); } //Sleep until store operation is finished.
}
void pstorage_update_block(void)
{
int i;
retval = pstorage_block_identifier_get(&handle, 0, &block_0_handle);
pstorage_wait_handle = block_0_handle.block_id; //Specify which pstorage handle to wait for
pstorage_wait_flag = 1; //Set the wait flag. Cleared in the example_cb_handler
retval = pstorage_update(&block_0_handle, source_data_0, 16, 0); //update flash block 0
while(pstorage_wait_flag) { power_manage();
} //Sleep until update operation is finished.
}
what i observed after debugging it doesnt come to the callback handler. i am not getting the reason for it. can anyone please check if any mistake is there in my code or some other issue. as my mentioned in some other post that there is bug in pstorage.c file so i have change it to this :
if (m_cmd_queue.count > 0)
{
retval = cmd_process();
if (retval != NRF_ERROR_BUSY) {
app_notify (retval);
} else {
// In case of busy next trigger will be a success or a failure event.
retval = NRF_SUCCESS;
}
}
else
{
// No flash access request pending.
}
from line no 370 to end of the function of file pstorage.c .
Please do have a look. Thanks & Regards.