搜索
bottom↓
回复: 8

请教:SysTick与TIM做RTOS的timebase,孰优孰劣?

[复制链接]

出0入0汤圆

发表于 2016-10-14 10:29:07 | 显示全部楼层 |阅读模式
最近做新项目更新了一下STM32CubeMX到4.16.1,执行生成代码时提示:
WARNINGS:
- When FreeRTOS is used, it is strongly recommanded to use HAL timebase source other than the Systick.
然后按提示设置SYS部分的Timebase Source,除了SysTick可选的就是各个未占用的TIM。
按我之前的理解,SysTick就是为了RTOS准备的专用定时器,这会CubeMX让我选普通的TIM,有点晕了,不知道为什么。
SysTick与TIM做RTOS的timebase,孰优孰劣?

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

 楼主| 发表于 2016-10-14 11:02:51 | 显示全部楼层
找到原因了,完整的见:https://my.st.com/public/STe2eco ... mp;currentviews=502

摘一部分:
As mentioned is the UM1718 “STM32CubeM user manual:

“ By default, the STM32Cube HAL is built around a unique timebase source which is the ARM-Cortex system timer (SysTick).
However, HAL-timebase related functions are defined as weak so that they can be overloaded to use another hardware timebase source. This is strongly recommended when the application uses an RTOS, since this middleware has full control on the SysTick configuration (tick and priority) and most RTOSs force the SysTick priority to be the lowest.
Using the SysTick remains acceptable if the application respects the HAL programming model, that is, does not perform any call to HAL timebase services within an Interrupt Service Request context (no dead lock issue).
To change the HAL timebase source, go to the SYS peripheral in the IP tree pane and select a clock among the available clock sources: SysTick, TIM1, TIM2,...”

反正我TIM这块也不依赖HAL库,用systick无妨。

出0入0汤圆

发表于 2016-10-14 11:03:10 | 显示全部楼层
没区别

只是,既然已经有个专业的了,为何还要去挤其它功能。

出0入75汤圆

发表于 2016-10-14 12:11:48 | 显示全部楼层
中断优先级

出0入0汤圆

发表于 2016-11-30 21:40:38 | 显示全部楼层
iskywolf 发表于 2016-10-14 11:02
找到原因了,完整的见:https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFo ...

没太理解原因。。。。
给讲一下?

出0入0汤圆

发表于 2019-3-12 22:01:41 | 显示全部楼层
主要是滿多HAL函數如果是阻塞型呼叫,內部會用到HAL_Delay(),FreeRTOS應該還是使用SystTick。如果使用的時基操作來源一樣,怕有不可預期問題出現。

出105入79汤圆

发表于 2019-3-12 22:33:17 | 显示全部楼层
应该是当用了RTOS,就要设置HAL的timebase为其他Timer,因为Systick会被操作系统设置为最低优先级中断,以及HAL使用了weak定义timebase的ISR中断函数,大家用同一个,会被RTOS的版本重载。

出0入0汤圆

发表于 2019-4-17 20:20:34 | 显示全部楼层
本帖最后由 steve_zhang 于 2019-4-17 20:30 编辑

刚研究STM32CUBE 产生的 FREERTOS代码,搞清楚它那个提示是怎么回事了,它提示的意思是HAL时基 不要选的和 RTOS的一样,RTOS默认是使用SysTick的中断来调度任务的,但是 HAL库也需要一个周期性的中断,它就建议你这两个周期性的中断不要用一个定时器。具体看摘出来的代码。


1     RTOS port.c里面的代码
/* Constants required to manipulate the core.  Registers first... */
#define portNVIC_SYSTICK_CTRL_REG                        ( * ( ( volatile uint32_t * ) 0xe000e010 ) )
#define portNVIC_SYSTICK_LOAD_REG                        ( * ( ( volatile uint32_t * ) 0xe000e014 ) )
#define portNVIC_SYSTICK_CURRENT_VALUE_REG        ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
#define portNVIC_SYSPRI2_REG                                ( * ( ( volatile uint32_t * ) 0xe000ed20 ) )
以上宏定义的地址 就是STM32各系列 的 Systick的相关寄存器地址。
void vPortSetupTimerInterrupt( void ) /*该函数在xPortStartScheduler( void )里被调用,也就是系统启动调度的时候,会初始化SysTick来产生定时中断的*/
        {
                /* Calculate the constants required to configure the tick interrupt. */
                #if configUSE_TICKLESS_IDLE == 1
                {
                        ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );
                        xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;
                        ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ );
                }
                #endif /* configUSE_TICKLESS_IDLE */

                /* Configure SysTick to interrupt at the requested rate. */
                portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
                portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
        }


2 再来 找到 #define xPortSysTickHandler SysTick_Handler
在找到 该函数的实现代码 ,实现了RTOS时钟节拍的递增
void xPortSysTickHandler( void )
{
        /* The SysTick runs at the lowest interrupt priority, so when this interrupt
        executes all interrupts must be unmasked.  There is therefore no need to
        save and then restore the interrupt mask value as its value is already
        known - therefore the slightly faster vPortRaiseBASEPRI() function is used
        in place of portSET_INTERRUPT_MASK_FROM_ISR(). */
        vPortRaiseBASEPRI();
        {
                /* Increment the RTOS tick. */
                if( xTaskIncrementTick() != pdFALSE )
                {
                        /* A context switch is required.  Context switching is performed in
                        the PendSV interrupt.  Pend the PendSV interrupt. */
                        portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
                }
        }
        vPortClearBASEPRIFromISR();
}

3 另外HAL库本身一些函数的操作是需要始终节拍的,所以把这两个时钟节拍独立开来。

出0入4汤圆

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

本版积分规则

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

GMT+8, 2024-4-24 03:00

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

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