当前位置:网站首页>[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
2022-08-05 00:32:00 【Thank you boss for not using crabs】
In the stm32 startup file, the stack size of the microcontroller is set. In the startup file here, the stack size is set to 1024 bytes, and the heap size is set to 512 bytes.
But in the FreeRTOSConfig.h file, the configTOTAL_HEAP_SIZE macro is also used to define the heap size to be used by FreeRTOS. Setting 36*1024 means that the maximum heap size used by FreeRTOS is36KB.
Obviously, 512 bytes are obviously smaller than 36 bytes, then there will be a question: why is the entire project file still able to run normally on stm32?
First of all, let's clarify the definition of stack.
Stack area (stack): It is automatically allocated and released by the compiler, and stores the parameter values of functions, the values of local variables, etc., and its operation is similar to the stack in the data structure.
heap: Generally allocated and released by the programmer, if the programmer does not release it, it may be reclaimed by the operating system at the end of the program.The allocation is similar to a linked list in a data structure.
There are two stack pointers in Cortex M3. In OS, usually use MSP in interrupts and PSP in normal tasks.
The stack size setting in the startup file can only change the MSP.In addition, Cortex M3 cannot set the stack size, only the stack pointer can be set!If the stack pointer is set at the last position of RAM and the stack space is set to 0, the compiler will not report an error, and the program can also run, as long as it does not conflict with the actual use area!
Summary: The stack size set in the stm32 startup file and the stack size set in FreeRTOSConfig.h usually do not interfere with each other (depending on different modelsIt depends on the size of RAM, as long as the sum of the two does not exceed the RAM size of the microcontroller, they should not interfere with each other), they are two independent memory spaces.
In addition, when looking for this problem, I found a cause and solution to the problem of insufficient allocation stack space. Here is almost the same words:
Summary of heap space usage: The heap space that the user can freely use (set in the startup file and allocated using the malloc() function) is about half of the total heap space.If it exceeds, the system will crash.
Summary of stack space usage: The functions being processed, including function nesting, recursion, etc., are allocated from this "stack".
Therefore, if aThere are too many local variables in the function. For example, if you define a u8 buf[512] in the function, this will take up 1/4 of the stack size. If you do it twice in other functions, it is very easy for the program to crash.At this time, you will usually enter hardfault....
This is a very easy mistake for beginners to make. Remember not to put N multiple local variables in the function, especially when there are large arrays!strong>
Reference:
KEIL toolThe stack 2_qrshi's blog-CSDN blog _keil stack window how to get it out
边栏推荐
- 2022杭电多校第一场 1004 Ball
- 进程间通信和线程间通信
- 2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
- E - Many Operations (bitwise consideration + dp thought to record the result after the operation
- 2022 Multi-school Second Session K Question Link with Bracket Sequence I
- tiup telemetry
- 2 用D435i运行VINS-fusion
- node使用redis
- Software testing interview questions: What are the three modules of LoadRunner?
- tiup telemetry
猜你喜欢
Getting started with 3D modeling for games, what modeling software can I choose?
matlab 采用描点法进行数据模拟和仿真
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
2 用D435i运行VINS-fusion
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
2022杭电多校第三场 K题 Taxi
STC89C52RC的P4口的应用问题
QSunSync Qiniu cloud file synchronization tool, batch upload
Three tips for you to successfully get started with 3D modeling
2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
随机推荐
[idea] idea configures sql formatting
Huggingface入门篇 II (QA)
【LeetCode】Summary of Two Pointer Problems
软件测试面试题:什么是软件测试?软件测试的目的与原则?
2022多校第二场 K题 Link with Bracket Sequence I
软件测试面试题:做好测试计划的关键是什么?
ARC129E Yet Another Minimization 题解 【网络流笔记】
Redis visual management software Redis Desktop Manager2022
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
标识符、关键字、常量 和变量(C语言)
matlab 采用描点法进行数据模拟和仿真
2022牛客多校第三场 A Ancestor
gorm joint table query - actual combat
node uses redis
gorm的Raw与scan
僵尸进程和孤儿进程
Software testing interview questions: What are the three modules of LoadRunner?
canvas 高斯模糊效果
[Cloud Native--Kubernetes] Pod Controller