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

pstorage_raw_mode

HI: I try use pstorage_raw_mode to store data. According to the document description,first steps: ble_stack_init() and scheduler_init(). Then, in turn, calls the function: pstorage_init(), pstorage_raw_register(), pstorage_raw_clear(), pstorage_raw_store(). All return NRF_SUCCESS. But pstorage_callback_handler is never executed. I read back entire chip, found that nothing data. I use SoftDevice7.0. The following is my application:

void pstorage_callback_handler(pstorage_handle_t * handle, uint8_t op_code, uint32_t result, uint8_t * p_data, uint32_t data_len) { simple_uart_putstring("pstorage call back handler \r\n"); }

void sys_evt_dispatch(uint32_t event) { pstorage_sys_event_handler(event); }

void ble_stack_init(void) { uint32_t err_code; sd_mbr_command_t com = {SD_MBR_START_SD, };

err_code = sd_mbr_command(&com);
APP_ERROR_CHECK(err_code);

err_code = sd_softdevice_forward_to_application(BOOTLOADER_REGION_START);
APP_ERROR_CHECK(err_code);

SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true);

err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);

}

static void scheduler_init(void) { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); }

int main(void) { uint32_t err_code = NRF_SUCCESS;

UART_Init();
timers_init();

ble_stack_init();
scheduler_init();	

nrf_gpio_cfg_output(10);
nrf_gpio_cfg_output(11);


err_code = pstorage_init();
if (err_code != NRF_SUCCESS)
{	
	simple_uart_putstring("pstorage init error \r\n");
    //APP_ERROR_CHECK(err_code);
}		
nrf_delay_us(1000000);

pstorage_param.cb = pstorage_callback_handler;

err_code = pstorage_raw_register(&pstorage_param, &pstorage_handle_app);
if (err_code != NRF_SUCCESS)
{	
	simple_uart_putstring("pstorage register error \r\n");
    //APP_ERROR_CHECK(err_code);
}	

nrf_delay_us(1000000);

pstorage_handle_app.block_id = CODE_REGION_1_START;
//pstorage_handle_swap = pstorage_handle_app;
//pstorage_handle_swap.block_id += BANK1_MAX_SIZE;

err_code = pstorage_raw_clear(&pstorage_handle_app, DFU_REGION_TOTAL_SIZE);
if (err_code != NRF_SUCCESS)
{
	simple_uart_putstring("pstorage clear error \r\n");
	//APP_ERROR_CHECK(err_code);
}	
nrf_delay_us(1000000);
err_code = pstorage_raw_store(&pstorage_handle_app, buf, 8, 4);
if (err_code != NRF_SUCCESS)
{
	simple_uart_putstring("pstorage store error \r\n");
	//APP_ERROR_CHECK(err_code);
}	
nrf_delay_us(1000000);	
while(1)
{	
	nrf_gpio_pin_set(10);
	nrf_gpio_pin_set(11);
	nrf_delay_us(1000000);
	nrf_gpio_pin_clear(10);
	nrf_gpio_pin_clear(11);
	nrf_delay_us(1000000);		
}

NVIC_SystemReset();

}

  • I have test successfully.I modify the code below:

    while(1)
    {	
    	//nrf_gpio_pin_set(10);
    	//nrf_gpio_pin_set(11);
    	//nrf_delay_us(1000000);
    	//nrf_gpio_pin_clear(10);
    	//nrf_gpio_pin_clear(11);
    	//nrf_delay_us(1000000);	
    	uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    
        // Event received. Process it from the scheduler.
        app_sched_execute();		
    }
    

    I always thought the callback function just notice that the tast have been executed , I can ignore this notice. But it couldn't.

  • Just wanted to second jixing's answer above. I couldn't figure out why my handler wasn't being called. I had the sd_app_evt_wait() in my loop, which worked fine when the Stack did not use the Scheduler. But as soon as I switched the Stack to using the Scheduler, my whole system froze. I realized that the handler wasn't being called. I added app_sched_execute(); and everything has worked great. Thanks for the answer jixing

Related