新手入门 
 
	- 积分
 - 3
 
        - 金钱
 - 3 
 
       - 注册时间
 - 2024-3-27
 
      - 在线时间
 - 1 小时
 
 
 
 | 
 
1金钱 
第一次用FREERTOS做项目,可能有些概念不清楚。这个问题困扰两天了 
Stm32cubemx生成的 Freertos工程,用TIM6作为systick的定时器(stm32f1xx_hal_timebase_tim.c),在定时器中断调用xEventGroupSetBitsFromISR就卡死了, 
用其它定时器调用xEventGroupSetBitsFromISR不会有问题,其实只是想弄清楚原因。 
下面是代码片段,麻烦各位帮忙分析一下原因: 
stm32cubemx生成的stm32f1xx_hal_timebase_tim.c,下面是初始化systick的代码 
- HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
 
 - {
 
 -   RCC_ClkInitTypeDef    clkconfig;
 
 -   uint32_t              uwTimclock, uwAPB1Prescaler = 0U;
 
  
-   uint32_t              uwPrescalerValue = 0U;
 
 -   uint32_t              pFLatency;
 
 -   HAL_StatusTypeDef     status = HAL_OK;
 
  
-   /* Enable TIM6 clock */
 
 -   __HAL_RCC_TIM6_CLK_ENABLE();
 
  
-   /* Get clock configuration */
 
 -   HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
 
  
-   /* Get APB1 prescaler */
 
 -   uwAPB1Prescaler = clkconfig.APB1CLKDivider;
 
 -   /* Compute TIM6 clock */
 
 -   if (uwAPB1Prescaler == RCC_HCLK_DIV1)
 
 -   {
 
 -     uwTimclock = HAL_RCC_GetPCLK1Freq();
 
 -   }
 
 -   else
 
 -   {
 
 -     uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
 
 -   }
 
  
-   /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
 
 -   uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
 
  
-   /* Initialize TIM6 */
 
 -   htim6.Instance = TIM6;
 
  
-   /* Initialize TIMx peripheral as follow:
 
  
-   + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
 
 -   + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
 
 -   + ClockDivision = 0
 
 -   + Counter direction = Up
 
 -   */
 
 -   htim6.Init.Period = (1000000U / 1000U) - 1U;
 
 -   htim6.Init.Prescaler = uwPrescalerValue;
 
 -   htim6.Init.ClockDivision = 0;
 
 -   htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
 
 -   htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 
  
-   status = HAL_TIM_Base_Init(&htim6);
 
 -   if (status == HAL_OK)
 
 -   {
 
 -     /* Start the TIM time Base generation in interrupt mode */
 
 -     status = HAL_TIM_Base_Start_IT(&htim6);
 
 -     if (status == HAL_OK)
 
 -     {
 
 -     /* Enable the TIM6 global Interrupt */
 
 -         HAL_NVIC_EnableIRQ(TIM6_IRQn);
 
 -       /* Configure the SysTick IRQ priority */
 
 -       if (TickPriority < (1UL << __NVIC_PRIO_BITS))
 
 -       {
 
 -         /* Configure the TIM IRQ priority */
 
 -         HAL_NVIC_SetPriority(TIM6_IRQn, TickPriority, 0U);
 
 -         uwTickPrio = TickPriority;
 
 -       }
 
 -       else
 
 -       {
 
 -         status = HAL_ERROR;
 
 -       }
 
 -     }
 
 -   }
 
  
-  /* Return function status */
 
 -   return status;
 
 - }
 
  复制代码 
 
定时器中断函数: 
- void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
 
 - {
 
 -   /* USER CODE BEGIN Callback 0 */
 
 -         BaseType_t        tmp;
 
 -   /* USER CODE END Callback 0 */
 
 -   if (htim->Instance == TIM6) {
 
 -     HAL_IncTick();
 
 -                 //lv_tick_inc(1);
 
 -                 xEventGroupSetBitsFromISR(DebugUartEventHandle, 1, &tmp);
 
 -   }
 
 -   /* USER CODE BEGIN Callback 1 */
 
  
-   /* USER CODE END Callback 1 */
 
 - }
 
  复制代码 程序走到xEventGroupSetBitsFromISR(DebugUartEventHandle, 1, &tmp);就卡住了 
 
 
#define  TICK_INT_PRIORITY            15U    /*!< tick interrupt priority (lowest by default)  */ 
systick的优先级是最低的 
 
 
下面是rtos的配置文件: 
- /* USER CODE BEGIN Header */
 
 - /*
 
 -  * FreeRTOS Kernel V10.0.1
 
 -  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 
 -  *
 
 -  * Permission is hereby granted, free of charge, to any person obtaining a copy of
 
 -  * this software and associated documentation files (the "Software"), to deal in
 
 -  * the Software without restriction, including without limitation the rights to
 
 -  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 
 -  * the Software, and to permit persons to whom the Software is furnished to do so,
 
 -  * subject to the following conditions:
 
 -  *
 
 -  * The above copyright notice and this permission notice shall be included in all
 
 -  * copies or substantial portions of the Software.
 
 -  *
 
 -  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
 -  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 
 -  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 
 -  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 
 -  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
 -  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 -  *
 
 -  * http://www.FreeRTOS.org
 
 -  * http://aws.amazon.com/freertos
 
 -  *
 
 -  * 1 tab == 4 spaces!
 
 -  */
 
 - /* USER CODE END Header */
 
  
- #ifndef FREERTOS_CONFIG_H
 
 - #define FREERTOS_CONFIG_H
 
  
- /*-----------------------------------------------------------
 
 -  * Application specific definitions.
 
 -  *
 
 -  * These definitions should be adjusted for your particular hardware and
 
 -  * application requirements.
 
 -  *
 
 -  * These parameters and more are described within the 'configuration' section of the
 
 -  * FreeRTOS API documentation available on the FreeRTOS.org web site.
 
 -  *
 
 -  * See http://www.freertos.org/a00110.html
 
 -  *----------------------------------------------------------*/
 
  
- /* USER CODE BEGIN Includes */
 
 - /* Section where include file can be added */
 
 - /* USER CODE END Includes */
 
  
- /* Ensure definitions are only used by the compiler, and not by the assembler. */
 
 - #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
 
 -   #include <stdint.h>
 
 -   extern uint32_t SystemCoreClock;
 
 - #endif
 
 - #define configUSE_PREEMPTION                     1
 
 - #define configSUPPORT_STATIC_ALLOCATION          1
 
 - #define configSUPPORT_DYNAMIC_ALLOCATION         1
 
 - #define configUSE_IDLE_HOOK                      0
 
 - #define configUSE_TICK_HOOK                      0
 
 - #define configCPU_CLOCK_HZ                       ( SystemCoreClock )
 
 - #define configTICK_RATE_HZ                       ((TickType_t)1000)
 
 - #define configMAX_PRIORITIES                     ( 7 )
 
 - #define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
 
 - #define configTOTAL_HEAP_SIZE                    ((size_t)10240)
 
 - #define configMAX_TASK_NAME_LEN                  ( 16 )
 
 - #define configUSE_16_BIT_TICKS                   0
 
 - #define configUSE_MUTEXES                        1
 
 - #define configQUEUE_REGISTRY_SIZE                8
 
 - #define configUSE_PORT_OPTIMISED_TASK_SELECTION  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             0
 
 - #define INCLUDE_vTaskDelay                  1
 
 - #define INCLUDE_xTaskGetSchedulerState      1
 
 - #define INCLUDE_xEventGroupSetBitFromISR    1
 
 - #define INCLUDE_xTimerPendFunctionCall      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 is commented when used with STM32Cube firmware, when the timebase source is SysTick,
 
 -               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 */
 
  
- #endif /* FREERTOS_CONFIG_H */
 
 
  复制代码 
 
 
 |   
 
 
 
 
 
 |