Dependent on a HW assembly variant my firmware should operate with 2.1 or 4.2 MHz. In FreeRTOS configCPU_CLOCK_HZ
is already set while compile time. Is there any possibility to set this frequency while initialisation time?
1 Answers
configCPU_CLOCK_HZ
seems to be used in vPortSetupTimerInterrupt()
function, which simply configures SysTick hardware registers (if you're not using tickless mode). I guess it should be possible to configure these register manually even when the scheduler is running (but I'm not sure).
But there is probably a better way: vPortSetupTimerInterrupt()
is defined with __attribute__((weak))
in the source code. It means that, if you provide your own version of vPortSetupTimerInterrupt()
, it will replace the original one. In your own version, simply load SysTick CTRL & LOAD registers with the appropriate values.
Here is the original version of vPortSetupTimerInterrupt()
(This can vary depanding on the uC model):
/*
* Setup the systick timer to generate the tick interrupts at the required
* frequency.
*/
__attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
{
/* Calculate the constants required to configure the tick interrupt. */
#if ( configUSE_TICKLESS_IDLE == 1 )
{
ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );
xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ );
}
#endif /* configUSE_TICKLESS_IDLE */
/* Stop and clear the SysTick. */
portNVIC_SYSTICK_CTRL_REG = 0UL;
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
/* Configure SysTick to interrupt at the requested rate. */
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
}
You can probably just copy the original one (without the weak attribute of course) and replace configCPU_CLOCK_HZ
with some global variable you set in your code.

- 2,412
- 2
- 11
- 14