Review the NVIC preemption and sub-priority settings, and the group settings that determine the bits assigned to each. System Handler priorities managed in the SCB
Is the systick good when using FreeRTOS or shall I change it to timer ? I saw in some forums saying systick is not good performing when it comes to rtos is that true please ? Shall i continue using systick or not ?
I don't like software interrupt based counters for the kinds of applications the ST HAL uses them for.
If you use SysTick, and you use the tick count it generates, and you use that count in other interrupt routines, then you are going to have to ensure that SysTick preempts ALL other interrupt sources and routines.
I don't particularly like the HAL implementation.
When your call-back routines are called you are running in interrupt context, you should do what you need quickly and leave, or queue more complex processing for a deferred thread or worker task.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
I changed the systick functions in which will be usuable by FreeRTOS like this ..systick and HAL_GetTick are declared weak so I changed it like this
/**
* dummy function to avoid the standard initialization code */HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority){ return HAL_OK;}
/**
* @brief Get the value of the Kernel SysTick timer* @param None* @retval None* @note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.*/uint32_t HAL_GetTick(void){ return osKernelSysTick();}/*** @brief This function handles System tick timer.*/void SysTick_Handler(void){ /* USER CODE BEGIN SysTick_IRQn 0 */
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
I would recommend to you to keep SysTick as a time base for FreeRTOS. In this case it will have lowest possible priority (0xF in STM32) and the same like PendSV.
Both of them are specified in FreeRTOSConfig.h file as 'configLIBRARY_LOWEST_INTERRUPT_PRIORITY'.
If you are using HAL libraries you would need a timer to generate all delay functions and timeouts. For this I would suggest to use either TIM6 or TIM7. Both are 16 bit without any input/output channels, so you would not loose any input/output timer channels. If you are using STM32CubeMX for code generation this timer assignment can be done within SYS peripheral section -> Timebase. This timer (used by HAL) will have highest possible priority (0).
Concerning rest of the interrupts you need to specify which interrupts will execute functions of FreeRTOS. For those interrupts you should set priority specified by configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY (by default in STM32CubeMX it is set to 5). Rest of the interrupts should have higher priority (lower number).
In such a model your hardware and its interrupts which will not use OS functions will not be interrupted/blocked by OS as operating system in most of its functions is using critical sections which are blocking interrupts to the level of configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY.
BASEPRI is the name of the core registers which is used to block interrupt on the desired level (always vs preemption priorities). As you see in above code you are configuring BASEPRI with configMAX_SYSCALL_INTERRUPT_PRIORITY (5 in your case).
I see you are using os functions within HAL functions .
I would separate those two worlds. Please select different timer (SYS->Timebase) for HAL libraries and leave SysTick for OS. It will help you with proper interrupt management.
If you will use Systick for HAL and OS you will face the situation that your SysTick interrupt (having lowest possible priority) will be stucked as it will be blocked by most of the OS functions at entrance to critical section (operations on BASEPRI).