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.

Related