34
34
#include "FreeRTOS.h"
35
35
#include "task.h"
36
36
37
+ #ifndef configSYSTICK_CLOCK_HZ
38
+ #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
39
+ /* Ensure the SysTick is clocked at the same frequency as the core. */
40
+ #define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
41
+ #else
42
+
43
+ /* The way the SysTick is clocked is not modified in case it is not the same
44
+ * as the core. */
45
+ #define portNVIC_SYSTICK_CLK_BIT ( 0 )
46
+ #endif
47
+
37
48
/* Constants required to manipulate the NVIC. */
38
49
#define portNVIC_SYSTICK_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000e010 ) )
39
50
#define portNVIC_SYSTICK_LOAD_REG ( *( ( volatile uint32_t * ) 0xe000e014 ) )
40
51
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( *( ( volatile uint32_t * ) 0xe000e018 ) )
41
52
#define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) )
42
53
#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) )
43
- #define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
44
54
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
45
55
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
46
56
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL )
@@ -382,9 +392,9 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
382
392
/* Calculate the constants required to configure the tick interrupt. */
383
393
#if ( configUSE_TICKLESS_IDLE == 1 )
384
394
{
385
- ulTimerCountsForOneTick = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ );
395
+ ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );
386
396
xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick ;
387
- ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR ;
397
+ ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ) ;
388
398
}
389
399
#endif /* configUSE_TICKLESS_IDLE */
390
400
@@ -393,7 +403,7 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
393
403
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL ;
394
404
395
405
/* Configure SysTick to interrupt at the requested rate. */
396
- portNVIC_SYSTICK_LOAD_REG = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ;
406
+ portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ;
397
407
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ;
398
408
}
399
409
/*-----------------------------------------------------------*/
0 commit comments