CommunityGD32Cores / gd32-pio-projects

PlatformIO test projects for the new GD32 platform and arduino core
42 stars 10 forks source link

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

Open yyjdelete opened 1 year ago

yyjdelete commented 1 year ago

SysTick_Handler in gd32-spl-freertos(without cmsis_os2) shouldn't auto clear overflow flag of SysTick. https://github.com/CommunityGD32Cores/gd32-pio-projects/blob/76bdc2dacb82f64a1ca436d2efc592b96acaed54/gd32-spl-freertos/src/main.c#L139-L149

It will break tickless mode for FreeRTOS(#define configUSE_TICKLESS_IDLE 1), since the default vPortSuppressTicksAndSleep will check the flag https://github.com/CommunityGD32Cores/gd32-pio-projects/blob/d16b658da884a59b2d13c52d802eb0d0262e043f/gd32-spl-freertos/lib/FreeRTOS/src/portable/ARM_CM3/port.c#L552-L566

maxgerhardt commented 1 year ago

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(); 
     } 
 } 

?