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

Not getting NRF_EVT_FLASH_OPERATION_SUCCESS

Hi all, After receiving data from my host app, I am trying to write to write the data to flash with the sd_flash_write command. I have 3 pages of data to write, so need to make sure the last write has finished by waiting for NRF_EVT_FLASH_OPERATION_SUCCESS. I do not receive this however while the ble is running. I placed the sd_evt_get in the interrupt handler:

void SWI2_IRQHandler(void)
{
	uint error;
	uint event;
	word length;
	bool softEvent = true;
	bool bleEvent = true;
	
	while (1)
	{
		if (softEvent)
		{
			error = sd_evt_get(&event);
			if (error == NRF_ERROR_NOT_FOUND)
				softEvent = false;
			else if (error != NRF_SUCCESS)
			{
				// Error
			}
			else
			{
				BluetoothSystemEventHandler(event); // Doesn't get called	

			}
		}
		if (bleEvent)
		{
			length = bleBufferSize;
			error = sd_ble_evt_get(bleEventBufferOffset, &length);
			if (error == NRF_ERROR_NOT_FOUND)
				bleEvent = false;
			else if (error != NRF_SUCCESS)
			{
				// Error
			}
			else
				BluetoothEventHandler((ble_evt_t *) bleEventBufferOffset);
		}
		if (!softEvent && !bleEvent)
			break;
	}
}

And in my main() I have just:

while(1)
{
	__wfi();
}

However, the BluetoothSystemEventHandler() never gets called. Is this the correct way to do it? Thanks again.

Parents
  • two things

    1. in your SWI2 interrupt handler, you need to set softEvent and bleEvent = false inside

       else if (error != NRF_SUCCESS)
       {
           // Error
       }
      

    otherwise the interrupt handler might never return if the error is not equal to NRF_SUCCESS or NRF_ERROR_NOT_FOUND and keeps looping with this error

    1. instead of waiting for interrupt, wait for event using __wfe(); Please go through this thread for the differences in two.
  • Hi Aryan, Thanks for the reply and apologies for the delay in answering. I have added the changes, but I still don't get the event. Could it be because I am calling the routine from the event handler right after the final BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST message (which I reply with a ble_gatts_rw_authorize_reply_params_t)? The reason I ask is, I wrote some test code to write the three pages directly from main line code and I do get the NRF_EVT_FLASH_OPERATION_SUCCESS event. Thanks again.

Reply
  • Hi Aryan, Thanks for the reply and apologies for the delay in answering. I have added the changes, but I still don't get the event. Could it be because I am calling the routine from the event handler right after the final BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST message (which I reply with a ble_gatts_rw_authorize_reply_params_t)? The reason I ask is, I wrote some test code to write the three pages directly from main line code and I do get the NRF_EVT_FLASH_OPERATION_SUCCESS event. Thanks again.

Children
No Data
Related