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

Status bit for sd_flash_write()

Hello,

I am using the sd_flash_write function. If I use this function without the nrf_delay_ms() function (see code below) the data is not being written.

	sd_flash_write((uint32_t*)addr, (uint32_t*) &data, 1);

	nrf_delay_ms(20);

Is there a status bit I can poll or is there an another solution to use this function without the delay?

Thanks.

Parents
  • Hello,

    I see some people still have this problem. I did solve it as follows:

    	/* flash_is_busy is a simple boolean */
    	flash_is_busy = true;
    	sd_flash_page_erase((NRF_FICR->CODESIZE - 1));
    
        /* Wait till the callback handler (see below) sets the boolean to false*/
    	while(Flash_Is_Busy());
    
    	/* addr points to the first byte in the last page */
    	uint32_t *addr = (uint32_t *)(NRF_FICR->CODEPAGESIZE * (NRF_FICR->CODESIZE - 1));
    
    	/* Write the address in flash*/
    	flash_is_busy = true;
    	sd_flash_write(addr, temp, ADDRESS_WORD_SIZE);
    	
    	while(Flash_Is_Busy());	
    

    And this is my callback handler (you have to subscribe for system events to get this callback).

        void Flash_Interrupt_Handler(uint32_t sys_evt)
        {
            if (sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS)
            {
                /*Flash_Is_Idle sets the flash_is_busy boolean to false */
    			Flash_Is_Idle();
            }
        }
    

    I hope this helps.

Reply
  • Hello,

    I see some people still have this problem. I did solve it as follows:

    	/* flash_is_busy is a simple boolean */
    	flash_is_busy = true;
    	sd_flash_page_erase((NRF_FICR->CODESIZE - 1));
    
        /* Wait till the callback handler (see below) sets the boolean to false*/
    	while(Flash_Is_Busy());
    
    	/* addr points to the first byte in the last page */
    	uint32_t *addr = (uint32_t *)(NRF_FICR->CODEPAGESIZE * (NRF_FICR->CODESIZE - 1));
    
    	/* Write the address in flash*/
    	flash_is_busy = true;
    	sd_flash_write(addr, temp, ADDRESS_WORD_SIZE);
    	
    	while(Flash_Is_Busy());	
    

    And this is my callback handler (you have to subscribe for system events to get this callback).

        void Flash_Interrupt_Handler(uint32_t sys_evt)
        {
            if (sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS)
            {
                /*Flash_Is_Idle sets the flash_is_busy boolean to false */
    			Flash_Is_Idle();
            }
        }
    

    I hope this helps.

Children
No Data
Related