搜索
bottom↓
回复: 16

FReeRTOS事件标志设置标志位会卡死,找不到解决方案啊

[复制链接]

出0入0汤圆

发表于 2019-5-20 18:13:10 | 显示全部楼层 |阅读模式
本帖最后由 lgc150 于 2019-5-21 09:49 编辑

最近在学习Freertos事件标志,用的安富莱的教程,在移植事件标志(中断方式)的时候,
运行这一句 xResult = xEventGroupSetBitsFromISR(xCreatedEventGroup,
                                                                            BIT_0 ,            
                                                                            &xHigherPriorityTaskWoken );
就会在 ucCurrentPriority = pcInterruptPriorityRegisters ;卡死,网上搜到类似的问题和解决方法:http://www.pianshen.com/article/4560139593/。FreeRTOSConfig文件是完全复制安富莱的,它的例程可以成功运行。我也尝试改了调用事件标志的定时器的中断优先级,也无法解决。现在上传工程文件,用MDK4打开,用的是stm32f103rct6,恳请各位兄台指点

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2019-5-20 18:37:57 | 显示全部楼层
调用xEventGroupSetBitsFromISR之前xCreatedEventGroup初始化了没

出0入0汤圆

 楼主| 发表于 2019-5-20 20:34:47 来自手机 | 显示全部楼层
fuu 发表于 2019-5-20 18:37
调用xEventGroupSetBitsFromISR之前xCreatedEventGroup初始化了没

有的,幸亏你提醒。貌似创建在调用之后,有可能是这个问题

出0入0汤圆

 楼主| 发表于 2019-5-21 09:41:52 | 显示全部楼层
fuu 发表于 2019-5-20 18:37
调用xEventGroupSetBitsFromISR之前xCreatedEventGroup初始化了没

还是没能解决。 可否麻烦兄台帮忙看下代码

出0入0汤圆

发表于 2019-5-21 10:07:05 | 显示全部楼层
一直用STM32CUBE生成的工程,觉得好用,不需要设置太多东西

出0入10汤圆

发表于 2019-5-21 11:27:04 来自手机 | 显示全部楼层
freertosconfig里配置了吗

出0入10汤圆

发表于 2019-5-21 11:28:32 来自手机 | 显示全部楼层
还有中断优先级高于Freertosconfig设定的优先级

出0入0汤圆

发表于 2019-5-21 12:27:27 | 显示全部楼层
硬邦邦 发表于 2019-5-21 11:27
freertosconfig里配置了吗

每次都因为你这个头像浪费好几秒。。。

出0入0汤圆

发表于 2019-5-21 12:30:09 | 显示全部楼层
stm32_xiaocai 发表于 2019-5-21 12:27
每次都因为你这个头像浪费好几秒。。。

果然是软绵绵的头像

出0入0汤圆

 楼主| 发表于 2019-5-21 13:49:39 | 显示全部楼层
硬邦邦 发表于 2019-5-21 11:27
freertosconfig里配置了吗

  1. #define configUSE_PREEMPTION                1
  2. #define configUSE_IDLE_HOOK                        0
  3. #define configUSE_TICK_HOOK                        0
  4. #define configCPU_CLOCK_HZ                        ( ( unsigned long ) 72000000 )       
  5. #define configTICK_RATE_HZ                        ( ( TickType_t ) 1000 )
  6. #define configMAX_PRIORITIES                ( 6 )
  7. #define configMINIMAL_STACK_SIZE        ( ( unsigned short ) 128 )
  8. #define configTOTAL_HEAP_SIZE                ( ( size_t ) ( 17 * 1024 ) )
  9. #define configMAX_TASK_NAME_LEN                ( 16 )
  10. #define configUSE_TRACE_FACILITY        1
  11. #define configUSE_16_BIT_TICKS                0
  12. #define configIDLE_SHOULD_YIELD                1

  13. /* Run time and task stats gathering related definitions. */
  14. #define configGENERATE_RUN_TIME_STATS                1
  15. #define configUSE_STATS_FORMATTING_FUNCTIONS         1
  16. #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()     (ulHighFrequencyTimerTicks = 0ul)
  17. #define portGET_RUN_TIME_COUNTER_VALUE()             ulHighFrequencyTimerTicks
  18. //#define portALT_GET_RUN_TIME_COUNTER_VALUE           1

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

  22. /* Set the following definitions to 1 to include the API function, or zero
  23. to exclude the API function. */

  24. #define INCLUDE_vTaskPrioritySet                1
  25. #define INCLUDE_uxTaskPriorityGet                1
  26. #define INCLUDE_vTaskDelete                                1
  27. #define INCLUDE_vTaskCleanUpResources        0
  28. #define INCLUDE_vTaskSuspend                        1
  29. #define INCLUDE_xTaskResumeFromISR      1
  30. #define INCLUDE_vTaskDelayUntil                        1
  31. #define INCLUDE_vTaskDelay                                1
  32. #define INCLUDE_xEventGroupSetBitFromISR  1
  33. #define INCLUDE_xTimerPendFunctionCall    1

  34. /* Software timer definitions. */
  35. #define configUSE_TIMERS                                  1
  36. #define configTIMER_TASK_PRIORITY                ( 5 )
  37. #define configTIMER_QUEUE_LENGTH                  20
  38. #define configTIMER_TASK_STACK_DEPTH        ( configMINIMAL_STACK_SIZE * 2 )

  39. /* Cortex-M specific definitions. */
  40. #ifdef __NVIC_PRIO_BITS
  41.         /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
  42.         #define configPRIO_BITS                       __NVIC_PRIO_BITS
  43. #else
  44.         #define configPRIO_BITS                       4        /* 15 priority levels */
  45. #endif

  46. /* The lowest interrupt priority that can be used in a call to a "set priority"
  47. function. */
  48. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY                        0x0f

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

  54. /* Interrupt priorities used by the kernel port layer itself.  These are generic
  55. to all Cortex-M ports, and do not rely on any particular library functions. */
  56. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  57. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
  58. See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
  59. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  60.        
  61. /* Normal assert() semantics without relying on the provision of an assert.h
  62. header file. */
  63. #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }       
  64.        
  65. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
  66. standard names. */
  67. #define vPortSVCHandler SVC_Handler
  68. #define xPortPendSVHandler PendSV_Handler
  69. #define xPortSysTickHandler SysTick_Handler


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

config文件里面已经配置了,其实我不是很了解Freertos所说的的任务优先级和中断优先级,因为就算是最低级的中断触发了,即使有当前运行的是最高优先级任务,也是会跳转到中断服务程序里面的

出0入0汤圆

 楼主| 发表于 2019-5-21 13:57:57 | 显示全部楼层
硬邦邦 发表于 2019-5-21 11:28
还有中断优先级高于Freertosconfig设定的优先级
  1. void Time2_init(void * _pCallBack)
  2. {
  3.        
  4.         TIM_TimeBaseInitTypeDef TIM_InitStructure;
  5.         NVIC_InitTypeDef NVIC_InitStructure;
  6.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
  7.         TIM_InitStructure.TIM_Period=10000-1;                       
  8.         TIM_InitStructure.TIM_Prescaler=72-1;               
  9.         TIM_InitStructure.TIM_ClockDivision=0;               
  10.         TIM_InitStructure.TIM_CounterMode=TIM_CounterMode_Up;
  11.         TIM_InitStructure.TIM_RepetitionCounter=0;
  12.         TIM_TimeBaseInit(TIM2,&TIM_InitStructure);
  13.         TIM_ClearFlag(TIM2,TIM_FLAG_Update);
  14.         TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);

  15.         NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
  16.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;               
  17.         NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
  18.         NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  19.         NVIC_Init(&NVIC_InitStructure);

  20.         s_TIM_CallBack = (void (*)(void))_pCallBack;               
  21.         TIM_Cmd(TIM2,ENABLE);
  22. }
复制代码

定时器中断优先级是3,中断中调用以下回调函数。发现函数运行到这里的时候就会卡住。
  1.         xResult = xEventGroupSetBitsFromISR(xCreatedEventGroup,
  2.                                                                             BIT_0 ,
  3.                                                                             &xHigherPriorityTaskWoken );
复制代码
  1. static void TIM_CallBack(void)
  2. {
  3.         BaseType_t xResult;
  4.         BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  5.         Run = ~Run;       
  6.         xResult = xEventGroupSetBitsFromISR(xCreatedEventGroup,
  7.                                                                             BIT_0 ,
  8.                                                                             &xHigherPriorityTaskWoken );
  9.         if( xResult != pdFAIL )
  10.         {
  11.                 portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
  12.         }       
  13. }
复制代码

出0入10汤圆

发表于 2019-5-20 18:13:11 | 显示全部楼层
   1.        HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );这个是设成4吗?

2.    xResult = xEventGroupSetBitsFromISR(xCreatedEventGroup,
                                                                            BIT_0 ,
                                                                            &xHigherPriorityTaskWoken );
换成普通的试试,回调说不定不在中断里。

出0入0汤圆

发表于 2019-5-21 14:25:48 | 显示全部楼层
1.在main函数开头调用NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
2.定时器优先级改大点,改15试试:        
        NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=15;               
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_Init(&NVIC_InitStructure);

出0入0汤圆

 楼主| 发表于 2019-5-21 14:26:00 | 显示全部楼层
硬邦邦 发表于 2019-5-20 18:13
   1.        HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );这个是设成4吗?

2.    xResult = xEv ...

老哥英明啊!!!! 果然是第一个问题。我本以为配置了FreeRTOSconfig,里面中断分组就自动设为Group4了,就没再main函数里加上这一句。现在加上这一句就可以了。问题解决,结贴啦

出0入0汤圆

 楼主| 发表于 2019-5-21 14:28:46 | 显示全部楼层
fuu 发表于 2019-5-21 14:25
1.在main函数开头调用NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
2.定时器优先级改大点,改15试试: ...

嗯嗯,已经搞定了。就是在main里面没有再次设置中断分组。我以为配置好Freertosconfig 分组就默认采用Group4了。非常感谢兄弟的回复  哈哈哈哈 楼上比你快了一步 我点完最佳答案才看到你的回复

出0入0汤圆

发表于 2019-9-6 13:47:53 | 显示全部楼层
我也是同样问题,按上法试试,谢谢!

出0入0汤圆

 楼主| 发表于 2019-9-10 17:02:16 | 显示全部楼层
eddia2012 发表于 2019-9-6 13:47
我也是同样问题,按上法试试,谢谢!

搞掂了吗
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-18 22:36

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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