cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 with RTOS PeriodElapsCallback executed once only

CSand
Associate III

Hello,

I have a simple project. I'm using FreeRTOS and programmed TIM2 1ms interrupt.

The TIM2_IRQHandler and PeriodElapsCallback are only called once in the beginning but not after.

I set Clock at 64MHz, the PSC is 63999 and Counter period is 9 I expect 1ms interrupt. I set NVIC TIM2 global intterupt.

I intend to use vTaskNotifyGiveFromISR but first need to make TIM2 interrupt to work.

The real time tasks seem to work fine.

Currently I programmed a counter increment in the PeriodElapsCallback  to make sure it works.

I attached the project if someone can support and check. I am probably missing something.

Thanks

3 REPLIES 3
CSand
Associate III

I'm not sure what I've changed, in any case the PeriodElapseCallback works ok if I have the test increment counter code.

But I'm back in problems if I call vTaskNotifyGiveFromISR. I may not use correct task handler.

In the main.c file I have

extern osThreadId UserTaskIMUHandle;

and the call for vTaskNotifyGiveFromISR is

	  void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* USER CODE BEGIN Callback 0 */
 
  /* USER CODE END Callback 0 */
  if (htim->Instance == TIM1) {
    HAL_IncTick();
  }
  /* USER CODE BEGIN Callback 1 */
  if (htim->Instance == TIM2)
  {
	  BaseType_t xHigherPriorityTaskWoken;
	  xHigherPriorityTaskWoken = pdFALSE;
 
 
	  vTaskNotifyGiveFromISR( UserTaskIMUHandle, &xHigherPriorityTaskWoken );
	  portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  }

In the freertos.c I have

void StartUserTaskIMU(void const * argument)
 {
  /* USER CODE BEGIN StartUserTaskSND */
 	uint32_t ulNotifyValue;
  
 for(;;)
  {
 	 ulNotifyValue = ulTaskNotifyTake(pdTRUE, 0xFFFFFFFF);
 	 if(ulNotifyValue != 0)
 	 {
 		 // User code
 	 }
 
 }

Would someone support to check if this is correct please?

Thanks

CSand
Associate III

Some more details that I found ...

The run stops and holds in the Tasks.c file at line "configASSERT( xTaskToNotify )" in the function ...

void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken )

 Should I suspect it is something about the task handler?

hs2
Senior

Double check that the tasks are created (and the assigned handle is not NULL) before arming the interrupt.