当前位置:网站首页>Solution to the problem of incorrect clock in FreeRTOS kernel
Solution to the problem of incorrect clock in FreeRTOS kernel
2022-06-25 17:04:00 【Lixiaoyao】
Focus on 、 Official account of star standard , Straight to the highlights
source : Technology makes dreams bigger
problem
In the use of RTOS when , Suddenly found that RTOS There is something wrong with your clock , Specific performance in the use of vTaskDelay or vTaskDelayUntil The delay time is not correct , Roughly targeted 10 About times .
Problem location
After checking for a long time, it was found that the problem was configSYSTICK_CLOCK_HZ, By this definition . The original understanding of this macro was , First, only for Cortex-M You can use , And then if Systick Like the system clock, there is no need to define , When different, it is defined as Systick The clock frequency of , Then the following methods are simply used when transplanting :
#define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 )
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZLeading to the final problem .
Problem analysis
Why didn't you find any problems at the beginning , Because I only saw the following picture at the beginning , There are no settings for the whole Systick understand ,

Look at , I think the setting value is correct , Then I didn't read the next sentence , I didn't pay attention to configSYSTICK_CLOCK_HZ This
The difference between macro definition and undefined . Two questions need to be understood when identifying the source of the problem :
1.Systick Is your clock the system kernel clock , Whether the clock frequency can be selected
2.Systick How to switch the system clock
The first question is
Systick Your clock is not necessarily a system clock (AHB), find CM The kernel can see Systick register , in 2 Bit type , It is clear that , There are two situations 1 Is the kernel clock ,0 Is the kernel clock 8 frequency division

The second question is
Obviously, the second question , Come out naturally , By changing the bit 2 Can change
good , After clarifying the above two questions , Let's ask RTOS How to help us set up Systick Of
/* 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 );Two words , No problem , The first sentence is set in the numerical value , The second step is to set the control, that is, the status register , good , First translate it according to my original problem :
/* Configure SysTick to interrupt at the requested rate. */
0xE000_E014 = ( 72000000/ 1000) - 1UL;
0xE000_E010 = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );Only pay attention to the correctness of reloading register data , The configuration of control and status registers is ignored , When you pay attention to this problem, it will be solved naturally , First find portNVIC_SYSTICK_CLK_BIT Definition
#ifndef configSYSTICK_CLOCK_HZ
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ
/* Ensure the SysTick is clocked at the same frequency as the core. */
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
#else
/* The way the SysTick is clocked is not modified in case it is not the same
as the core. */
#define portNVIC_SYSTICK_CLK_BIT ( 0 )
#endifSee? , If you define configSYSTICK_CLOCK_HZ It will change portNVIC_SYSTICK_CLK_BIT The numerical , Even if you promise configSYSTICK_CLOCK_HZ It can't be the same as the system clock frequency , This will cause the clock source of the clock source to change , Leading to the final problem .
terms of settlement
How to solve this problem perfectly? Let's go to the official website to see the official explanation of macro itself :
Undefine configSYSTICK_CLOCK_HZ
Optional parameter for ARM Cortex-M ports only.
By default ARM Cortex-M ports generate the RTOS tick interrupt from the Cortex-M SysTick timer. Most Cortex-M MCUs run the SysTick timer at the same frequency as the MCU itself - when that is the case configSYSTICK_CLOCK_HZ is not needed and should be left undefined. If the SysTick timer is clocked at a different frequency to the MCU core then set configCPU_CLOCK_HZ to the MCU clock frequency, as normal, and configSYSTICK_CLOCK_HZ to the SysTick clock frequency.
The general meaning is only to Cortex-M The kernel is valid , The second is if Systick The system clock is the same as the kernel, so don't define this macro , On the contrary, define the macro , At the same time, the actual clock frequency after dividing its value .
That's easy , Just remove the definition .
summary
stay RTOS If RTOS The kernel clock is wrong , First position Systick Configuration problem , Check whether the configuration of each step changes the relevant clock frequency , There is no need to focus on other issues .
Copyright notice : Source network of this paper , Free delivery of knowledge , The copyright belongs to the original author . If involves the work copyright question , Please contact me to delete .
‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧ END ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧
Pay attention to my WeChat official account , reply “ Add group ” Join the technical exchange group according to the rules . Click on “ Read the original ” See more sharing , Welcome to share 、 Collection 、 give the thumbs-up 、 Looking at .边栏推荐
猜你喜欢

Redis series - overview day1-1

Perfect shuffle problem

内卷?泡沫?变革?十个问题直击“元宇宙”核心困惑丨《问Ta-王雷元宇宙时间》精华实录...

Redis系列——概述day1-1

Generate post order traversal according to pre order traversal and mid order traversal

Simple dialogue system -- implement transformer by yourself

redis 分布式锁整理

The problem of missing precision of kettle table input components

Involution? Foam? Change? Ten questions directly hit the core puzzle of "meta universe" – the essence of "ask ta- Wang Lei about the time of the universe"

好胖子带你学Flink系列-Flink源码剖析第一集Standalone启动脚本分析
随机推荐
Paper notes: generalized random forests
Wechat official account server configuration
剑指 Offer II 035. 最小时间差
PLSQL 存储函数SQL编程
Perfect shuffle problem
TCP chat + transfer file server server socket v2.8 - fix 4 known problems
IO stream
pychrm的这些配置,你都知道吗?
FreeRTOS内核时钟不对的问题解决
千万级购物车系统缓存架构方案
Xshell connecting VMware virtual machines
计网 | 形象理解路由协议RIP、OSPF、BGP
Redis系列——概述day1-1
解析数仓lazyagg查询重写优化
Kotlin
2022云的世界会更好吗
Ten thousand volumes - list of Dali wa
[untitled]
Internship: the annotation under swagger involves the provision of interfaces
软考中的嵌入式系统设计师为什么考的人少?