This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pstorage: stuck in erase operation

This is my code snippet

int main(void)
{
	uint32_t err_code;
	
	...
	
	// Scheduler
	scheduler_init();
	
	// Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true); // Use scheduler

    ..... register system event dispatch here .......
	
	// Initialize persistent storage module.
	err_code = pstorage_init();	
	APP_ERROR_CHECK(err_code);
	
	storage_param.block_size = DATA_BLOCK_SIZE;
	storage_param.block_count = DATA_BLOCK_COUNT;
	storage_param.cb = pstorage_callback;
	
	err_code = pstorage_register(&storage_param, &storage_handle);
	APP_ERROR_CHECK(err_code);
	
	err_code = pstorage_block_identifier_get(&m_base_handle, 0, &storage_handle);
	APP_ERROR_CHECK(err_code);
	
	err_code = pstorage_clear(&m_base_handle, DATA_BLOCK_COUNT * DATA_BLOCK_SIZE);
	APP_ERROR_CHECK(err_code);

	// Wait until FLASH all cleared
	uint32_t count;
	do {
		err_code = pstorage_access_status_get(&count);
		APP_ERROR_CHECK(err_code);
	} while(count); /* Stuck here??? */
	
    	....
    	
}

The program stuck in the while segment, and count is always 0x1. Why?

Parents
  • No, you must use softdevice_sys_evt_handler_set(), because it's where softdevice will handle end of flash operations ans start new operations:

    Registering for system events and passing them on to pstorage module using the pstorage_sys_event_handler is mandatory for the module to function as expected. Code snippet below demonstrates what application needs to do for this.
    /**@brief Function for dispatching a system event to interested modules.
      
       @details This function is called from the System event interrupt handler after a system
                event has been received.
      
       @param[in]   sys_evt   System stack event.
     */
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        pstorage_sys_event_handler(sys_evt);
    }
    /**@brief BLE stack initialization.
      
       @details Initializes the SoftDevice and the stack event interrupt.
     */
    static void ble_ant_stack_init(void)
    {
        // Initialize SoftDevice
        SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
        
        // Subscribe for BLE events.
        uint32_t err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
        APP_ERROR_CHECK(err_code);
        
        // Register with the SoftDevice handler module for System events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    }
    

    You will block CPU until Flash erase is done with your code:

    // Wait until FLASH all cleared
    uint32_t count;
    do {
        err_code = pstorage_access_status_get(&count);
        APP_ERROR_CHECK(err_code);
    } while(count); /* Stuck here??? */
    
Reply
  • No, you must use softdevice_sys_evt_handler_set(), because it's where softdevice will handle end of flash operations ans start new operations:

    Registering for system events and passing them on to pstorage module using the pstorage_sys_event_handler is mandatory for the module to function as expected. Code snippet below demonstrates what application needs to do for this.
    /**@brief Function for dispatching a system event to interested modules.
      
       @details This function is called from the System event interrupt handler after a system
                event has been received.
      
       @param[in]   sys_evt   System stack event.
     */
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        pstorage_sys_event_handler(sys_evt);
    }
    /**@brief BLE stack initialization.
      
       @details Initializes the SoftDevice and the stack event interrupt.
     */
    static void ble_ant_stack_init(void)
    {
        // Initialize SoftDevice
        SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
        
        // Subscribe for BLE events.
        uint32_t err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
        APP_ERROR_CHECK(err_code);
        
        // Register with the SoftDevice handler module for System events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    }
    

    You will block CPU until Flash erase is done with your code:

    // Wait until FLASH all cleared
    uint32_t count;
    do {
        err_code = pstorage_access_status_get(&count);
        APP_ERROR_CHECK(err_code);
    } while(count); /* Stuck here??? */
    
Children
No Data
Related