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

Problems with sd_flash_write() function

Hello,

I am trying to write data to flash. I did successful write data to flash, but I need delays between erases and writes. I tried to avoid the delays with the NRF_EVT_FLASH_OPERATION_SUCCESS interrupt, but this did not work for me. I am doing it like this right now:

    sd_flash_page_erase((NRF_FICR->CODESIZE - 1));

	/* addr points to the first byte in the last page */
	uint32_t *addr = (uint32_t *)(NRF_FICR->CODEPAGESIZE * (NRF_FICR->CODESIZE - 1));

	nrf_delay_ms(20);

	sd_flash_write(addr, data, ADDRESS_WORD_SIZE);
	
	/* Wait to make sure the flash is writed */
	nrf_delay_ms(20);

	/* addr points to last word */
	addr += (NRF_FICR->CODEPAGESIZE - 4);

	sd_flash_write((uint32_t*)addr2, (uint32_t*) crc, 1);

	/* Wait to make sure the flash is writed */
	nrf_delay_ms(20);

Without the delays this code does not work. I want to replace the delays with a status bit from the NRF_EVT_FLASH_OPERATION_SUCCESS. I did this as follows:

	flash_is_busy = true;
	while(flash_is_busy)
	{   
       //wait for flash operation interrupt	
    }

In this code the flash_is_busy is set to false when the NRF_EVT_FLASH_OPERATION_SUCCESS occurs. The program gives a hardfault for when I try this construction.

What am I doing wrong? Is there any example?

Thanks.

Parents
  • Hi

    I would recommend to use the pstorage module which uses the sd_flash_write and sd_flash_page_erase commands internally. Only one flash command can be issued at one time, which is why you need the delay. An erase cycle takes typically around 20ms and you can not issue another flash command until the former completes.

    The pstorage module on the other hand queues up the flash commands and sends another flash command first when the former one completes. Therefore you can call flash erase and flash write commands without delay when using pstorage. There is a pstorage example available on this thread.

Reply
  • Hi

    I would recommend to use the pstorage module which uses the sd_flash_write and sd_flash_page_erase commands internally. Only one flash command can be issued at one time, which is why you need the delay. An erase cycle takes typically around 20ms and you can not issue another flash command until the former completes.

    The pstorage module on the other hand queues up the flash commands and sends another flash command first when the former one completes. Therefore you can call flash erase and flash write commands without delay when using pstorage. There is a pstorage example available on this thread.

Children
No Data
Related