OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 751|回复: 0

Stm32 Freertos工程,用TIM6作为systick,中断调用xEventGroupSetBitsFromISR卡死

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
3
金钱
3
注册时间
2024-3-27
在线时间
1 小时
发表于 2024-3-27 17:59:49 | 显示全部楼层 |阅读模式
1金钱
第一次用FREERTOS做项目,可能有些概念不清楚。这个问题困扰两天了
Stm32cubemx生成的 Freertos工程,用TIM6作为systick的定时器(stm32f1xx_hal_timebase_tim.c),在定时器中断调用xEventGroupSetBitsFromISR就卡死了,
用其它定时器调用xEventGroupSetBitsFromISR不会有问题,其实只是想弄清楚原因。
下面是代码片段,麻烦各位帮忙分析一下原因:
stm32cubemx生成的stm32f1xx_hal_timebase_tim.c,下面是初始化systick的代码
  1. HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  2. {
  3.   RCC_ClkInitTypeDef    clkconfig;
  4.   uint32_t              uwTimclock, uwAPB1Prescaler = 0U;

  5.   uint32_t              uwPrescalerValue = 0U;
  6.   uint32_t              pFLatency;
  7.   HAL_StatusTypeDef     status = HAL_OK;

  8.   /* Enable TIM6 clock */
  9.   __HAL_RCC_TIM6_CLK_ENABLE();

  10.   /* Get clock configuration */
  11.   HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);

  12.   /* Get APB1 prescaler */
  13.   uwAPB1Prescaler = clkconfig.APB1CLKDivider;
  14.   /* Compute TIM6 clock */
  15.   if (uwAPB1Prescaler == RCC_HCLK_DIV1)
  16.   {
  17.     uwTimclock = HAL_RCC_GetPCLK1Freq();
  18.   }
  19.   else
  20.   {
  21.     uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
  22.   }

  23.   /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
  24.   uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);

  25.   /* Initialize TIM6 */
  26.   htim6.Instance = TIM6;

  27.   /* Initialize TIMx peripheral as follow:

  28.   + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
  29.   + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
  30.   + ClockDivision = 0
  31.   + Counter direction = Up
  32.   */
  33.   htim6.Init.Period = (1000000U / 1000U) - 1U;
  34.   htim6.Init.Prescaler = uwPrescalerValue;
  35.   htim6.Init.ClockDivision = 0;
  36.   htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  37.   htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

  38.   status = HAL_TIM_Base_Init(&htim6);
  39.   if (status == HAL_OK)
  40.   {
  41.     /* Start the TIM time Base generation in interrupt mode */
  42.     status = HAL_TIM_Base_Start_IT(&htim6);
  43.     if (status == HAL_OK)
  44.     {
  45.     /* Enable the TIM6 global Interrupt */
  46.         HAL_NVIC_EnableIRQ(TIM6_IRQn);
  47.       /* Configure the SysTick IRQ priority */
  48.       if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  49.       {
  50.         /* Configure the TIM IRQ priority */
  51.         HAL_NVIC_SetPriority(TIM6_IRQn, TickPriority, 0U);
  52.         uwTickPrio = TickPriority;
  53.       }
  54.       else
  55.       {
  56.         status = HAL_ERROR;
  57.       }
  58.     }
  59.   }

  60. /* Return function status */
  61.   return status;
  62. }
复制代码


定时器中断函数:
  1. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  2. {
  3.   /* USER CODE BEGIN Callback 0 */
  4.         BaseType_t        tmp;
  5.   /* USER CODE END Callback 0 */
  6.   if (htim->Instance == TIM6) {
  7.     HAL_IncTick();
  8.                 //lv_tick_inc(1);
  9.                 xEventGroupSetBitsFromISR(DebugUartEventHandle, 1, &tmp);
  10.   }
  11.   /* USER CODE BEGIN Callback 1 */

  12.   /* USER CODE END Callback 1 */
  13. }
复制代码
程序走到xEventGroupSetBitsFromISR(DebugUartEventHandle, 1, &tmp);就卡住了


#define  TICK_INT_PRIORITY            15U    /*!< tick interrupt priority (lowest by default)  */
systick的优先级是最低的


下面是rtos的配置文件:
  1. /* USER CODE BEGIN Header */
  2. /*
  3. * FreeRTOS Kernel V10.0.1
  4. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * http://www.FreeRTOS.org
  24. * http://aws.amazon.com/freertos
  25. *
  26. * 1 tab == 4 spaces!
  27. */
  28. /* USER CODE END Header */

  29. #ifndef FREERTOS_CONFIG_H
  30. #define FREERTOS_CONFIG_H

  31. /*-----------------------------------------------------------
  32. * Application specific definitions.
  33. *
  34. * These definitions should be adjusted for your particular hardware and
  35. * application requirements.
  36. *
  37. * These parameters and more are described within the 'configuration' section of the
  38. * FreeRTOS API documentation available on the FreeRTOS.org web site.
  39. *
  40. * See http://www.freertos.org/a00110.html
  41. *----------------------------------------------------------*/

  42. /* USER CODE BEGIN Includes */
  43. /* Section where include file can be added */
  44. /* USER CODE END Includes */

  45. /* Ensure definitions are only used by the compiler, and not by the assembler. */
  46. #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
  47.   #include <stdint.h>
  48.   extern uint32_t SystemCoreClock;
  49. #endif
  50. #define configUSE_PREEMPTION                     1
  51. #define configSUPPORT_STATIC_ALLOCATION          1
  52. #define configSUPPORT_DYNAMIC_ALLOCATION         1
  53. #define configUSE_IDLE_HOOK                      0
  54. #define configUSE_TICK_HOOK                      0
  55. #define configCPU_CLOCK_HZ                       ( SystemCoreClock )
  56. #define configTICK_RATE_HZ                       ((TickType_t)1000)
  57. #define configMAX_PRIORITIES                     ( 7 )
  58. #define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
  59. #define configTOTAL_HEAP_SIZE                    ((size_t)10240)
  60. #define configMAX_TASK_NAME_LEN                  ( 16 )
  61. #define configUSE_16_BIT_TICKS                   0
  62. #define configUSE_MUTEXES                        1
  63. #define configQUEUE_REGISTRY_SIZE                8
  64. #define configUSE_PORT_OPTIMISED_TASK_SELECTION  1

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

  68. /* Software timer definitions. */
  69. #define configUSE_TIMERS                         1
  70. #define configTIMER_TASK_PRIORITY                ( 2 )
  71. #define configTIMER_QUEUE_LENGTH                 10
  72. #define configTIMER_TASK_STACK_DEPTH             256

  73. /* Set the following definitions to 1 to include the API function, or zero
  74. to exclude the API function. */
  75. #define INCLUDE_vTaskPrioritySet            1
  76. #define INCLUDE_uxTaskPriorityGet           1
  77. #define INCLUDE_vTaskDelete                 1
  78. #define INCLUDE_vTaskCleanUpResources       0
  79. #define INCLUDE_vTaskSuspend                1
  80. #define INCLUDE_vTaskDelayUntil             0
  81. #define INCLUDE_vTaskDelay                  1
  82. #define INCLUDE_xTaskGetSchedulerState      1
  83. #define INCLUDE_xEventGroupSetBitFromISR    1
  84. #define INCLUDE_xTimerPendFunctionCall      1

  85. /* Cortex-M specific definitions. */
  86. #ifdef __NVIC_PRIO_BITS
  87. /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
  88. #define configPRIO_BITS         __NVIC_PRIO_BITS
  89. #else
  90. #define configPRIO_BITS         4
  91. #endif

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

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

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

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

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

  115. /* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
  116.               to prevent overwriting SysTick_Handler defined within STM32Cube HAL */

  117. #define xPortSysTickHandler SysTick_Handler

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

  121. #endif /* FREERTOS_CONFIG_H */
复制代码



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-22 11:57

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表