title: freertos tick factor 2 too fast on stm32f4xx
body: <p>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.</p>
  
  <p>what have i checked already:</p>
  
  <ol>
  <li>DEBUG VARIABLES: all three parts included in incrementing the tick (TIMER IRQ HANDLER, FREERTOS TICK HANDLER, FREERTOS TICK HOOK) are called 10'000 timer per 10 seconds. So far OK.</li>
  <li>TASK and TIMER periods: when multiplying the period by 2, the timing is OK, so far NOT ok.</li>
  <li>Freertos Config: SystemClockCore is 168MHz. Ticks are set to 1000 ticks per second. is there somewhere a mistake in the config?</li>
  </ol>
  
  <p>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.</p>
  
  <pre><code>// 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,
      &amp;_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 &lt;&lt; (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 &lt;&lt; (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 */
  </code></pre>