本文介绍了在stm32f4xx上freertos刻度因子2太快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的freertos设置肯定有一个错误,因为当我使用任务延迟功能或计时器周期时,这两个时间都是所需时间的两倍.

my current freertos setup must have a mistake because when i use the task delay function or the timer period, both timings are twice as fast as desired.

我已经检查了什么:

  1. 调试变量:递增滴答声包括的所有三个部分(TIMER IRQ HANDLER,FREERTOS TICK HANDLER,FREERTOS TICK HOOK)被称为每10秒10,000个计时器.到目前为止还可以.
  2. 任务和计时器周期:将周期乘以2时,计时就可以了,到目前为止还不行.
  3. Freertos配置:SystemClockCore为168MHz.滴答声设置为每秒1000个滴答声.配置中有什么错误吗?

我希望有人给我一个提示,以解决此问题..PS:系统刻度当前也运行得太慢,但这与我无关,因为未使用.可能会有所影响.

I hope someone could give me a tipp what is causing this issue.. P.S.: The system tick is currently running too slow as well, but this doesn't concern me currently since not used.. could have an influence though.

// DEBUG VARIABLES
DEBUG_CT DEBUG_CLOCK_TICK_T {...}
    DEBUG_CT_ISR_SYSTEM_TICK        uint32_t    65  // IS NOT USED
    DEBUG_CT_ISR_TIM_TICK           uint32_t    10036
    DEBUG_CT_FREERTOS_HOOK_TICK     uint32_t    10036
    DEBUG_CT_FREERTOS_TICK_HANDLER  uint32_t    10036

// FREERTOS TICK HANDLER
#ifdef DEBUG_CLOCK_TICK
DEBUG_CT.DEBUG_CT_FREERTOS_TICK_HANDLER++;
#endif
xPortSysTickHandler();

// THREAD DELAY
void delay(uint32_t ms)
{
    M_ASSERT_BOOL(_created);
    ms *= 2; // !!! CORRECTION, WHY ???
    vTaskDelay(ms/portTICK_PERIOD_MS);
}

// TIMER CREATION
_handle = xTimerCreateStatic(
    _name,
    pdMS_TO_TICKS(_msDelay*2), // !!! CORRECTION, WHY ???
    autoreload,
    (void*)_name,
    _expired,
    &_timerBuffer);

// PORTMACRO.H
#define portSTACK_GROWTH            ( -1 )
#define portTICK_PERIOD_MS          ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT          8

// FREERTOS CONFIG
#define configUSE_PREEMPTION                     1
#define configSUPPORT_STATIC_ALLOCATION          1
#define configSUPPORT_DYNAMIC_ALLOCATION         0
#define configUSE_IDLE_HOOK                      1
#define configUSE_TICK_HOOK                      1
#define configCPU_CLOCK_HZ                       ( SystemCoreClock )
#define configTICK_RATE_HZ                       ((TickType_t)1000)
#define configMAX_PRIORITIES                     ( 7 )
#define configMINIMAL_STACK_SIZE                 ((uint16_t)32)
#define configMAX_TASK_NAME_LEN                  ( 32 )
#define configUSE_16_BIT_TICKS                   0
#define configUSE_MUTEXES                        1
#define configQUEUE_REGISTRY_SIZE                8
#define configCHECK_FOR_STACK_OVERFLOW           1
#define configUSE_MALLOC_FAILED_HOOK             1
#define configUSE_DAEMON_TASK_STARTUP_HOOK       1
#define configENABLE_BACKWARD_COMPATIBILITY      0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION  1
#define configUSE_TICKLESS_IDLE                  1

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES                    0
#define configMAX_CO_ROUTINE_PRIORITIES          ( 2 )

/* Software timer definitions. */
#define configUSE_TIMERS                         1
#define configTIMER_TASK_PRIORITY                ( 2 )
#define configTIMER_QUEUE_LENGTH                 10
#define configTIMER_TASK_STACK_DEPTH             256

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet            1
#define INCLUDE_uxTaskPriorityGet           1
#define INCLUDE_vTaskDelete                 1
#define INCLUDE_vTaskCleanUpResources       0
#define INCLUDE_vTaskSuspend                1
#define INCLUDE_vTaskDelayUntil             1
#define INCLUDE_vTaskDelay                  1
#define INCLUDE_xTaskGetSchedulerState      1
#define INCLUDE_pcTaskGetTaskName           1
#define INCLUDE_xTaskGetCurrentTaskHandle   1
#define INCLUDE_eTaskGetState               1
#define INCLUDE_xTaskGetHandle              1

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
 /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
 #define configPRIO_BITS         __NVIC_PRIO_BITS
#else
 #define configPRIO_BITS         4
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY   15

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY         ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/* USER CODE END 1 */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler    SVC_Handler
#define xPortPendSVHandler PendSV_Handler

/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware,
              to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
/* #define xPortSysTickHandler SysTick_Handler */

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */

#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
void PreSleepProcessing(uint32_t *ulExpectedIdleTime);
void PostSleepProcessing(uint32_t *ulExpectedIdleTime);
#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */

/* The configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros
allow the application writer to add additional code before and after the MCU is
placed into the low power state respectively. */
#if configUSE_TICKLESS_IDLE == 1
#define configPRE_SLEEP_PROCESSING                        PreSleepProcessing
#define configPOST_SLEEP_PROCESSING                       PostSleepProcessing
#endif /* configUSE_TICKLESS_IDLE == 1 */

#endif /* FREERTOS_CONFIG_H */

推荐答案

就像前面提到的,FreeRTOS在STM32F4上配置为使用PLL作为168MHz的时钟源.在system_stm32f4xx.c中的SetSysClock函数中,设置了三个预分频器(请检查数据表中的时钟图):

Like mentioned before, FreeRTOS is configured to use PLL as clock source at 168MHz on STM32F4. In function SetSysClock in system_stm32f4xx.c, three prescaler are set (check the clock diagram in datasheet):

  • AHB预分频器设置为1,
  • APB2预分频器设置为2,
  • APB1预分频器设置为4.

如果我们以定时器2为例-它连接到总线APB1,这意味着它使用4分频的预分频器(168MHz/4 = 42MHZ).然后在寄存器RCC_DCKCFGR中还有一个TIMPRE位.默认情况下,该位设置为0,表示:

If we take for example Timer 2 - it is connected to the bus APB1, which means it uses prescaler with division 4 (168MHz/4 = 42MHZ). Then there is also a TIMPRE bit in register RCC_DCKCFGR. By default this bit is set to 0, which means:

当设置为0时:"如果将APB预分频器(RCC_CFGR寄存器中的PPRE1,PPRE2)配置为分频因子1,则TIMxCLK = PCLKx.否则,定时器时钟频率设置为2的两倍.计时器连接到的APB域的频率:TIMxCLK = 2xPCLKx."

这意味着计时器时钟的速度是预分频器的APB时钟的两倍,使其达到84MHz.

This means that the timer clock is twice as fast as APB clock that comes from prescaler, making it 84MHz.

这篇关于在stm32f4xx上freertos刻度因子2太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 15:40