Change from binary semaphore to task notify for deferred interrupts

Hi I want to change one of my deferred interrupt handlers from using a binary semaphore to taskNotify.

Is this the correct way to do it.

Using A semaphore:

	if(HAL_SPI_TransmitReceive_DMA_rjg(&hspi2,
																		 wiFiDataOut,
																		 wiFiDataIn,
																		 2U,
																		 4U,
																		 SPI_IT_EOT,
																		 0xF0000005) != HAL_OK)
	{
		return WIFI_SPI_DRIVER_ERROR;
	}

	/* Wait for Ready state from WiFi * then check that it is Not ready */
	if (xSemaphoreTake(wiFiReadySemHandle, (uint32_t)WIFI_CMD_TIME0UT) == pdFAIL)
	{
		return WIFI_SPI_TIMEOUT;
	}


/**
  * @brief This function handles EXTI line[9:5] interrupts.
  */
USE_ITCM void EXTI9_5_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;

#if(CHK_LINE_IRQ_5 == 1)
  if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_5) != 0x00U)
  {
  	/* DataReady Pin Rising */
  	__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
  	wiFiRdyState = true;
  	xSemaphoreGiveFromISR(wiFiReadySemHandle, &xHigherPriorityTaskWoken);
  	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  	return;
  }
#endif

Using Task Notify

if(HAL_SPI_TransmitReceive_DMA_rjg(&hspi2,
																		 wiFiDataOut,
																		 wiFiDataIn,
																		 2U,
																		 4U,
																		 SPI_IT_EOT,
																		 0xF0000005) != HAL_OK)
	{
		return WIFI_SPI_DRIVER_ERROR;
	}

	/* Wait for Ready state from WiFi * then check that it is Not ready */
	if(!ulTaskNotifyTake(pdTRUE, (uint32_t)WIFI_CMD_TIME0UT))
	{
		return WIFI_SPI_TIMEOUT;
	}

/**
  * @brief This function handles EXTI line[9:5] interrupts.
  */
USE_ITCM void EXTI9_5_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;

#if(CHK_LINE_IRQ_5 == 1)
  if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_5) != 0x00U)
  {
  	/* DataReady Pin Rising */
  	__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
  	wiFiRdyState = true;

    vTaskNotifyGiveFromISR(wiFiTskHandle, &xHigherPriorityTaskWoken);
  	portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  	return;
  }
#endif

I created a test program to try this out and started getting the occasional hard fault. So I thought maybe I was doing something wrong.

Regards
Rob

I think your code is ok. Do you ensure (e.g. be enabling EXTI interrupt after task creation) that the wiFiTskHandle is properly initialized before the ISR is invoked ?
Maybe add an assert checking the handle being valid in the ISR.

Thank’s HS,

Yes I do set up the handle prior to enabling the peripheral interrupts. The HAL Driver call enables the peripheral interrupts although the global MCU interrupts are enabled at start up.

I thought I had it correct, I just wanted to be sure. The hard fault I’m getting seems to be related to a “flaky” debugger. I don’t get the fault when running without the debugger. It could be the USB cable.

Best regards
Rob.