当前位置:网站首页>[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牛客多校训练第二场 J题 Link with Arithmetic Progression
- The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
- 【Unity编译器扩展之进度条】
- tensor.nozero(),面具,面具
- TinyMCE禁用转义
- tiup telemetry
- 克服项目管理中恐惧心理
- Software testing interview questions: the difference and connection between black box testing, white box testing, and unit testing, integration testing, system testing, and acceptance testing?
- Software testing interview questions: What are the seven-layer network protocols?
- Software testing interview questions: What is the difference between load testing, capacity testing, and strength testing?
猜你喜欢
找不到DiscoveryClient类型的Bean
"WEB Security Penetration Testing" (28) Burp Collaborator-dnslog out-band technology
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
leetcode经典例题——单词拆分
【idea】idea配置sql格式化
QSunSync 七牛云文件同步工具,批量上传
TinyMCE禁用转义
What is next-generation modeling (with learning materials)
软件开发工具的技术要素
2 用D435i运行VINS-fusion
随机推荐
Mysql_14 存储引擎
QSunSync Qiniu cloud file synchronization tool, batch upload
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
【unity编译器扩展之模型动画拷贝】
简单的顺序结构程序(C语言)
日志(logging模块)
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
【idea】idea配置sql格式化
Metasploit-域名上线隐藏IP
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
00、数组及字符串常用的 API(详细剖析)
TinyMCE disable escape
D - I Hate Non-integer Number (count of selected number dp
[Cloud Native--Kubernetes] Pod Controller
软件测试面试题:软件都有多少种分类?
Huggingface入门篇 II (QA)
2022牛客多校第三场 J题 Journey
2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi