Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SysTick_Handler in gd32-spl-freertos shouldn't auto clear overflow flag of SysTick #8

Open
yyjdelete opened this issue Nov 19, 2022 · 1 comment

Comments

@yyjdelete
Copy link

SysTick_Handler in gd32-spl-freertos(without cmsis_os2) shouldn't auto clear overflow flag of SysTick.

extern void xPortSysTickHandler(void);
void SysTick_Handler(void)
{
/* Clear overflow flag */
SysTick->CTRL;
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
/* Call tick handler */
xPortSysTickHandler();
}
}

It will break tickless mode for FreeRTOS(#define configUSE_TICKLESS_IDLE 1), since the default vPortSuppressTicksAndSleep will check the flag

/* Disable the SysTick clock without reading the
* portNVIC_SYSTICK_CTRL_REG register to ensure the
* portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
* the time the SysTick is stopped for is accounted for as best it can
* be, but using the tickless mode will inevitably result in some tiny
* drift of the time maintained by the kernel with respect to calendar
* time*/
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT );
/* Determine if the SysTick clock has already counted to zero and
* been set back to the current reload value (the reload back being
* correct for the entire expected idle time) or if the SysTick is yet
* to count to zero (in which case an interrupt other than the SysTick
* must have brought the system out of sleep mode). */
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )

@maxgerhardt
Copy link
Member

maxgerhardt commented Nov 19, 2022

Interesting. That comes from https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c#L150-L168.

So the code should rather be

 extern void xPortSysTickHandler(void); 
 void SysTick_Handler(void) 
 { 
     /* only clear overflag in not-tickless mode */
#if !defined(configUSE_TICKLESS_IDLE) || configUSE_TICKLESS_IDLE  == 0
     /* Clear overflow flag */ 
     SysTick->CTRL; 
#endif
     if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) 
     { 
         /* Call tick handler */ 
         xPortSysTickHandler(); 
     } 
 } 

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants