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
  • Hi all,

    I repost my question here. I found the problem chain is

    1. pstorage_init() called sd_flash_page_erase(), and set m_cmd_queue.flash_access = true;

    2. sd_flash_page_erase() will not trigger system event handler which calls pstorage_sys_event_handler, and thus m_cmd_queue.flash_access kept true;

    3. because m_cmd_queue.flash_access is true, then later the pstorage_clear() is not executed immediately but enqueued.

    4. Enqueued command will not be executed, and thus m_cmd_queue.count is always 1.

    .........

  • Thank for for answering your own question, and separating the questions.

Reply Children
No Data
Related