当前位置:网站首页>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 .边栏推荐
- The problem of missing precision of kettle table input components
- 单例模式应用
- Effects and laws
- 【无标题】
- 【精通高并发】深入理解C语言基础与汇编下的C语言
- WPF development essays Collection - ECG curve drawing
- 【 apprentissage automatique】 cas de prévision et d'analyse de l'examen d'entrée à l'Université basé sur des séries chronologiques multiples
- mac php多版本管理以及安装swoole扩展
- 批量--07---断点重提
- Day_ seventeen
猜你喜欢
随机推荐
XXIX - orbslam2 real-time 3D reconstruction using realsensed435
How smart PLC constructs ALT instruction
SMART PLC如何构造ALT指令
2021年5月云南省网络空间安全比赛赛题复盘
Differences between et al and etc
TCP chat + transfer file server server socket v2.8 - fix 4 known problems
Uncover ges super large scale graph computing engine hyg: Graph Segmentation
Sword finger offer 39 Numbers that occur more than half the time in the array
项目经理在项目中起到的作用
计网 | 形象理解路由协议RIP、OSPF、BGP
Knowing these interview skills will help you avoid detours in your test job search
千万级购物车系统缓存架构方案
How to talk about salary correctly in software testing interview
剑指 Offer II 035. 最小时间差
这项最新的调查研究,揭开多云发展的两大秘密
A complete collection of APP testing tools. It's enough to collect this one
Structure de la mémoire JVM
How did I get a salary increase of 13k+ after one year of employment?
批量--07---断点重提
Do you know all the configurations of pychrm?







