在stm32f4xx

时间:2017-10-27 06:34:32

标签: eclipse stm32 freertos stm32f4discovery

我当前的freertos设置必定有错误,因为当我使用任务延迟功能或定时器时间时,两个时间都是所需时间的两倍。

我已经检查了什么:

  1. DEBUG VARIABLES:增加勾号所包含的所有三个部分(TIMER IRQ HANDLER,FREERTOS TICK HANDLER,FREERTOS TICK HOOK)每10秒称为10'000计时器。到目前为止确定。
  2. TASK和TIMER周期:当周期乘以2时,时间还可以,到目前为止还不行。
  3. Freertos配置:SystemClockCore是168MHz。刻度设置为每秒1000个刻度。配置中有错误吗?
  4. 我希望有人可以告诉我一个导致这个问题的问题.PS:系统勾号目前运行速度太慢,但这并不关心我,因为没有使用..但可能会产生影响。

    // 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 */
    

2 个答案:

答案 0 :(得分:0)

STM32F4上的FreeRTOS通常配置为使用SysTick作为生成OS滴答计时器的计时器。但是,如果正确设置,可以使用任何所需的计时器。

如果SysTick运行的速度只有它应该的一半那么这可能解释了你的问题,因为它运行主时钟(即168MHz)。

我认为如果是这种情况,那么你的PLL配置不正确,你的主时钟频率是168MHz / 2而不是168MHz(或者你正在运行不同的时钟)。

我建议不要使用无空闲的闲置,同时对此进行调整,因为它可能会使事情变得更容易。

答案 1 :(得分:0)

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

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

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

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

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