Hi,
I have troubles to call a task from a timer interrupt.
First of all, I use a STM32F103C8T6 uE and CMSISv2 API with FreeRTOS 10.0.1
I use the CubeMX to generated the Hardware Layer Code in C.
I have set the Timer3 to create an overflow interrupt after ca. 100us.
I tested it without FreeRTOS and is working.
Now I enabled the FreeRTOS and the call of the task from the interrupt does not work.
CubeMX enables the timer interupt with the following Code
HAL_NVIC_SetPriority(TIM3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
Here I also tried the Macro configMAX_SYSCALL_INTERRUPT_PRIORITY as priority but the behaviour was the same.
After the overflow of the timer counter the controller goes in this function,
void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */
/* USER CODE END TIM3_IRQn 0 */
HAL_TIM_IRQHandler(&htim3);
/* USER CODE BEGIN TIM3_IRQn 1 */
/* USER CODE END TIM3_IRQn 1 */
}
and enters in the function HAL_TIM_IRQHandler(&htim3);
this function calls void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
and I wrote my own function like that,
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM3)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(ComputationINTHandle,&xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
and I wrote also my code in the ComputationINTHandle
like this,
void ComputationINTfunc(void *argument)
{
/* USER CODE BEGIN ComputationINTfunc */
HAL_TIM_Base_Start_IT(&htim3);
/* Infinite loop */
for(;;)
{
/* Will be woken up by timer interrupt*/
ulTaskNotifyTake(pdTRUE,portMAX_DELAY);
HAL_GPIO_WritePin(TestPinC13_GPIO_Port, TestPinC13_Pin, GPIO_PIN_SET);
for(int i=0;i<10;i++) asm("nop");
HAL_GPIO_WritePin(TestPinC13_GPIO_Port, TestPinC13_Pin, GPIO_PIN_RESET);
}
/* USER CODE END ComputationINTfunc */
}
Here I enable the timer interupt in the first execution and in loop I toggle a pin to debug it with my oscilloscope.
At this time I have the troubles, for a few seconds the program is running good but after some seconds, the software stops.
I use the debug to see what is going wrong and I have seen that the Code is stucking in the routine portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
I analyzed step by step with the debugger and I see the following,
in the first steps, in the function vPortValidateInterruptPriority
the variableulCurrentInterrupt
was equal to 45, but in code from STM32 has the number 29. (I did not understand if this numbers should be equal)
the variable ucCurrentPriority
was at the begging equal to 80 and in the following lines is coming the check configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
and in my program the ucMaxSysCallPriority
is equal to 80. So in this moment everything is working very good.
But after some seconds, the variable ucMaxSysCallPriority
changes to 84 or 180 and in this moment the code configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
is becoming false and boom, Software is stacking in the configASSERT.
If I commented out the configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );
then everything is working perfect, or seems to be perfect.
Can any one explain me why the ucMaxSysCallPriority
changes and how can I fix this problem?
Thank you in advance.