1

I want to notify my task to run from an ISR. I red the RTOS docs but I could not do it. I would really appreciate if you tell me what I am supposed to do and give an example if it is possible. I used cmsis-V2. Inside the ISR which I am sure the ISR works correctly I wrote:

  void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* USER CODE BEGIN Callback 0 */

  /* USER CODE END Callback 0 */
  if (htim->Instance == TIM15) {
    HAL_IncTick();
  }
  /* USER CODE BEGIN Callback 1 */
  if (htim == &htim16)
    {
        BaseType_t xHigherPriorityTaskWoken;
        xHigherPriorityTaskWoken = pdFALSE;
        vTaskNotifyGiveFromISR(ADXL_HandlerHandle , &xHigherPriorityTaskWoken);
        portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
      }

  /* USER CODE END Callback 1 */
}

I also used systick timer for FREE RTOS and timer 15 as the system timer . is it possible that the problem is related to this part ? I dout because task_notify_give function only add up and is not a blocking mechanism like semaphore.

and inside the thask, inside the for loop the first lines are:

ulNotifiedValue = ulTaskNotifyTake( pdFALSE, portMAX_DELAY);
      if( ulNotifiedValue > 0 ){
//my codes ....
}

before for loop I defined:

uint32_t ulNotifiedValue;

but the task is not executed. even once. I use Nucleo H755ZIQ.

before the definition of global variable, tasks are defined like this:

/* Definitions for ADXL_Handler */
osThreadId_t ADXL_HandlerHandle;
const osThreadAttr_t ADXL_Handler_attributes = {
  .name = "ADXL_Handler",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 1024 * 4
};

then inside the main function initializing the schduler is as follows :

 osKernelInitialize();
 ADXL_HandlerHandle = osThreadNew(ADXL_Handler_TaskFun, NULL, &ADXL_Handler_attributes);
osKernelStart();

Then the timers will be started:

 HAL_TIM_Base_Start_IT(&htim16);
 

In CMSIS there is no such a thing like task notification, I took a short look. The functions I used inside the ISR routine are from FreeRTOS. will not there a contradiction? should I use only Free RTOS task create function instead of CMSIS functions?

Thanks in advance.

  • The notification related code seems ok. I think the problem is something else. Is the task properly created and started (with sufficient stack) ? Do you ensure that the ISR is not invoked until the task is created and ADXL_HandlerHandle is valid ? – HS2 Sep 19 '22 at 08:34
  • about the task handle I doubt and I edited my question and added how the task were defined by CUBE IDE. Timers are enabled after enabling the tasks. before using task notification I compiled the program and the task was running correctly so the stack size I think is not the problem. I can upload the whole code but may not be a good decision because it is little bit long. according to FREE RTOS Docs for creating the task xTaskCreated() was used and task handle was given to this function as an input argument. Might that be the problem? – Sina_Torkzadeh Sep 19 '22 at 17:08
  • You can usually mix and match CMSIS API and native FreeRTOS API in your code. The notification related code seems correct, stack size should be more than sufficient. Is any task/the scheduler running correctly and did you verify that vTaskNotifyGiveFromISR is called in the ISR ? – HS2 Sep 20 '22 at 07:23
  • yes , as I said, previously I created a task and it was working properly without Task Notify From ISR. after adding the task notification it does not work. I am totally confused. – Sina_Torkzadeh Sep 24 '22 at 22:18
  • I am having the same issue where vTaskNotifyGiveFromISR is not working and im also running an STM32 – Edwin Fairchild Sep 25 '22 at 19:59
  • vTaskNotifyGiveFromISR works. Also on STM32, of course. Did you define configASSERT (and enabled stack checking) ? This helps to catch a lot of those mystic problems. Alternatively use the debugger to step through the code to find the issue. – HS2 Sep 26 '22 at 07:18

0 Answers0