Couldn't run the scheduler after handling timer 5 Interrupt

Dear RTOS Hello,
I am getting started with FreeRTOS on stm32F429 board,
I download the FreeRTOS and, I integrated it into an example from ST respo. I am not using the CubeMx.
The first time I run the FreeRTOS with one static task, it works well.
I am trying to add the timer 5 interrupt and yiel from interrupt. The execution code stop in vPortRaiseBASEPRI function.
I am activating the configASSERT in the FreeRTOSConfig but my program still not working!

void TIM5_IRQHandler(void)
{
	HAL_TIM_IRQHandler(&TIM_InitStruct);

#if 1

	BaseType_t xHigherPriorityTaskWoken = pdFALSE;

	xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
	//xHigherPriorityTaskWoken = xTaskResumeFromISR(LED_TaskRed);

	portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
	//portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);

#else

	BSP_LED_Toggle(LED4);

#endif
}

When I use the interrupt directly, I could see my LEDs blinking.
This is the stack calling function :
image
I have one more question please, does I have to use any UART interface to make ASSERT methods and API work?
Thank you in advance,
S.Tarik.

First, you do not need a UART to use configASSERT, as typically configASSERT will just halt in a loop that you use the debugger to break and see that it happened.

My first guess is that you have not set the priority of this ISR, so its default of 0 is too ‘high’ (on ARM M’s lower values of interrupt priority are higher priority to the interrupt).

Hello richard-damon,
Thank you for your replay,

Ok, Since my interrupt is the highest priority, why this interrupt is not executed?
Thank you in advance,
S.Tarik

The priority is too high if using FreeRTOS calls in this ISR. That’s the reason for the assert.
The choosen prio has to match configMAX_SYSCALL_INTERRUPT_PRIORITY in your FreeRTOSConfig.h
See https://www.freertos.org/RTOS-Cortex-M3-M4.html and mabe also this pretty good picture for details.

OK, so my configMAX_SYSCALL_INTERRUPT_PRIORITY is 5,
My interrupt prio also is 5. It makes sense that my timer interrupt is masked.
In this situation what do you recommend me to do?
I am using the STM32f429 board with cube ide. and cubeMx.

Thank you in advance,
S.Tarik,

I afraid that’s not yet correct. You should e.g.
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
and use the configMAX_SYSCALL_INTERRUPT_PRIORITY macro as done in this demo example:

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
	/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
	#define configPRIO_BITS       		__NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4        /* 15 priority levels */
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			0x0f

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

And as far as I remember there is hint in the mentioned FreeRTOS docs regarding using STM32 drivers and NVIC priority grouping.

Sorry - I’m not familiar with cube. But I thought it generates all required files/configs…

My FreeRTOSConfig.h file is the same as you minched.

I didn’t understand what are you saying in this sentence. Could you clarify please?

If you’d read the documentation I already mentioned you’d find:

Maybe that’s done by cube generated code, maybe not. I’d double-check that.

Edit I didn’t find TIM5 in your screenshot :thinking:

Non, I am using TIM6 for interrupt trigger, and TIM1 for FreeRTOS.
I will test the call function of NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); and will comment the results.
Thank you for help :slight_smile:

Did you change the TIM from 5 to 6 since the first post ? The topic and also the backtrace refer to TIM5 …

Yes, The TIM3.CNT register is always 0. I changed the timer to test.

Hello again,
I resolve the problem of the interrupt trigger,
I have this message in the Debugger console when the timer is runing for the first time:

Program stopped.
xQueueGiveFromISR (xQueue=0x0, pxHigherPriorityTaskWoken=0x2002ff5c) at …/Middlewares/Third_Party/FreeRTOS/Source/queue.c:1120
1120 configASSERT( pxQueue );

Now, my interrupt is triggered but the program is stopped at this point.
I am calling this function before running the rtos HAL_NVIC_SetPriorityGrouping (NVIC_PRIORITYGROUP_4);

So did you finally resolve the problem or are you still stuck ?
If you still having the problem it seems that the xSemaphore is not yet created (NULL) when the ISR is entered 1st time.
You have to ensure that all resources used in ISRs are created and initialized before activating the corresponding interrupt.
In your specific case xSemaphore has to be created before enabling TIMx interrupt

BRAVO!
My problem is solved, thank you so much.
The semaphore was declared before the init timer, so the semaphore was null.
The HAL_NVIC_SetPriorityGrouping (NVIC_PRIORITYGROUP_4); call before the scheduler solved the priority issue, I will dig into the details and reading the documentation for more understanding.
Have a nice day.

How come configASSERT() didn’t catch these problems right at the beginning?

I think that the assert caught that before but I didn’t see the console output.
This is the first time I use FreeRTOS with STM32F4 microcontroller.

Hello,
let me add that there are ready-to-use examples in the last version of STM32CubeF4 Fw package (https://www.st.com/en/embedded-software/stm32cubef4.html)

Once you download it, you find FreeRTOS ready to use examples for the STM32F429 discovery board at the following path:
STM32Cube_FW_F4_V1.25.2\Projects\STM32F429I-Discovery\Applications\FreeRTOS

This could help on this and possible future questions.
Best Regards

Thank you massimopanzica,
The STM examples projects are very helpful and very easy to use.
I would like to use CubeMx with cubeIDE and have the ability to add and remove peripherals, change the clock frequency…