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

sd_flash_write hangs after 10 words written

Hi

I'm learning to use the sd_flash_write function to write words into flash memory. I've the SD enabled, but not advertising, so I'm able to debug. Scheduler is also initialized.

What I get, it is than when executing this little code:

buf[4] = {0, 0, 0, 0};
		for(i=10; i<256;i++){
			buf[0] = i;
			res = sd_flash_write(FLASH_DIR_LAST_PAGE+(i*4), (uint32_t *)buf, 1);
			TIMER_BASE_Delay(1000);
		}

my SW hangs hangs and resets after 9 words written. The 10th word is which hangs the SW. Any idea??? Note than I'm waiting about 1 second between each write operation.

For now, I'm trying to handle the flash memory whitout using the pstorage module. Should I use it?

Thanks in advance

Elena

  • The call to sd_flash_write returns before the write operation is complete. I'm guessing you know that since you have the delay in between calls to sd_flash_write. However, you really should be waiting for a flash system event before proceeding onto the next write operation.

    This is where pstorage is helpful as it will queue up to, I believe, 20 flash operations. So, you can fire off a number of flash operations and pstorage will take care of them. The flash events will come to you system event handler and you can then call the pstorage event handler and it will dequeue the next operation and run it. NOTE: You will want to check to make sure that the system event is a flash event before calling the pstorage event handler as it doesn't screen the event type (at least it doesn't in revision 5.2.0 of the SDK).

  • Hi

    Thanks for your reply. You're right: I'm waiting for one second in order to wait sufficient time to perform de operation. One second should be more than sufficient, so I don't understand what's happening.

    I'll review my code and check the pstorage module.

    Thanks again,

    Regards,

    Elena

  • I don't know why the delay is not working for you. However, I don't have your code so it is hard to tell. Does the call the sd_flash_write ever return anything other than NRF_SUCCESS?

  • Hi again

    I've discovered the problem. My fault: I wasn't calling the scheduler from my loop. I've edited the code as follows:

    	for(i=10; i<256;i++){
    		buf[0] = i;
    		res = sd_flash_write(FLASH_DIR_LAST_PAGE+(i*4), (uint32_t *)buf, 1);
    		TIMER_BASE_Delay(1000);
    		**app_sched_execute();**
    	}
    

    Thanks for your help

    Cheers

Related