Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly obtain CPU Utilization in freeRTOS Environment

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

It is believed that many inexperienced people do not know what to do about how to quickly obtain the utilization rate of CPU in the freeRTOS environment. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. Abstract

In the freeRTOS environment, taking STM32 as an example, this paper introduces how to quickly obtain the utilization rate of CPU and cooperate with CubeMonitor testing.

two。 Preparatory work

1, IAR 8.32.1

2, STM32Cube_FW_H7_V1.6.0

3. CPU utilization

The CPU utilization here refers to the ratio of the total CPU running time of all task stacks except idle tasks within a certain period.

OsCPU_Usage = (osCPU_TotalIdleTime * 100) / CALCULATION_PERIOD; in fact, by calculating the time of idle tasks, you can obtain the utilization of CPU, while the running time of idle tasks can be obtained by using hooks or hook functions, specifically under freeRTOS

And all our calculations are based on the CPU time base, which takes STM32H743 as the MCU under freeRTOS, and usually sets the time base as 1ms, which is the TICK of the operating system, and freeRTOS also provides hook functions.

So to use these two hook functions, we must first configure enable under freeRTOSConfig.h

4. Get CPU utilization

There will be a common file cpu_utils.c and cpu_utils.h in the SDK provided by ST. These two files provide a scheme and method to obtain the utilization rate of CPU under freeRTOS. For reference, we can add the two files to the project and need to configure and modify something.

In the comments section at the beginning of the cpu_utilis.c file, there are instructions on how to use this module, according to the module instructions, which we listed in the previous section must first enable the HOOK function configuration of IDEL and TICK. You must also define two macros. For freeRTOS, you can define the following in freeRTOSConfig.h

Add a function declaration to the header file

This method can only be used for preliminary estimation. If accurate estimation is needed, a hardware timer with higher priority than sysTick can be started, but in general formal projects, not doing so will affect the real-time performance of the system.

External API interface

Just call it directly. FreeRTOS+Trace can be used for more elaborate testing and debugging.

5. test

After the compilation is correct, you can download it for debugging. There are about a dozen tasks in the project.

You can see the utilization of CPU. You can also use the CubeMonitor launched by ST for testing, and the next push will arrange detailed CubeMonitor use for everyone.

6. Reference documentation

Serial number

Literature

one

STM32H743RM

two

3, STM32Cube_FW_H7_V1.6.0

After reading the above, have you mastered how to quickly obtain CPU utilization in freeRTOS environment? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report