ARM Cortex-M3 启动代码 [英] ARM Cortex-M3 Startup Code

查看:31
本文介绍了ARM Cortex-M3 启动代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 Keil (realview v4) 附带的用于 STM32 微控制器的初始化代码是如何工作的.具体来说,我试图了解堆栈是如何初始化的.

I'm trying to understand how the initialization code works that ships with Keil (realview v4) for the STM32 microcontrollers. Specifically, I'm trying to understand how the stack is initialized.

文档中 在 ARM 的网站上,它提到了 startup_xxx.s 中的一个例程,__user_initial_stack_heap,不应使用超过 88 字节的堆栈.你知道这个限制来自哪里吗?

In the documentation on ARM's website it mentions that one of the routines in startup_xxx.s, __user_initial_stack_heap, should not use more than 88 bytes of stack. Do you know where that limitation is coming from?

似乎当重置处理程序调用 System_Init 时,它正在 C 环境中执行几个函数,我认为这意味着它使用某种形式的临时堆栈(它分配了一些自动变量).但是,一旦返回并调用 __main 后,所有这些堆栈的项目都应该超出范围,这是从其中调用 __user_initial_stack_heap 的地方.

It seems that when the reset handler calls System_Init it is executing a couple functions in a C environment which I believe means it is using some form of a temporary stack (it allocates a few automatic variables). However, all of those stack'd items should be out of scope once it returns back and then calls __main which is where __user_initial_stack_heap is called from.

那么为什么对 __user_initial_stack_heap 有这个要求,不能使用超过 88 个字节?__main 的其余部分是否使用了大量堆栈或其他东西?

So why is there this requirement for __user_initial_stack_heap to not use more than 88 bytes? Does the rest of __main use a ton of stack or something?

关于 cortex-m3 堆栈架构的任何与启动顺序相关的解释都会很棒.

Any explanation of the cortex-m3 stack architecture as it relates to the startup sequence would be fantastic.

推荐答案

您将从 __user_initial_stackheap() 文档,该函数用于遗留支持,并被 __user_setup_stackheap();后者的文档为您的问题提供了线索:

You will see from the __user_initial_stackheap() documentation, that the function is for legacy support and that it is superseded by __user_setup_stackheap(); the documentation for the latter provides a clue ragarding your question:

与 __user_initial_stackheap() 不同,__user_setup_stackheap() 适用于应用程序以已经正确的 sp (r13) 值开头的系统,例如 Cortex-M3

Unlike __user_initial_stackheap(), __user_setup_stackheap() works with systems where the application starts with a value of sp (r13) that is already correct, for example, Cortex-M3

[..]

使用 __user_setup_stackheap() 而不是 __user_initial_stackheap() 可以改善代码大小,因为不需要临时堆栈.

Using __user_setup_stackheap() rather than __user_initial_stackheap() improves code size because there is no requirement for a temporary stack.

在 Cortex-M 上,sp 是在硬件从向量表中存储的值重置时初始化的,在较旧的 ARM7 和 ARM9 设备上,情况并非如此,必须在软件中设置堆栈指针.在应用用户定义的堆栈之前,启动代码需要一个小堆栈以供使用 - 例如,如果用户堆栈在外部存储器中并且在存储器控制器初始化之前无法使用,则可能是这种情况.88 字节的限制仅仅是因为这个临时堆栈的大小尽可能小,因为它可能在启动后未被使用.

On Cortex-M the sp is initialised on reset by the hardware from a value stored in the vector table, on older ARM7 and ARM9 devices this is not the case and it is necessary to set the stack-pointer in software. The start-up code needs a small stack for use before the user defined stack is applied - this may be the case for example if the user stack were in external memory and could not be used until the memory controller were initialised. The 88 byte restriction is imposed simply because this temporary stack is sized to be as small as possible since it is probably unused after start-up.

就您在 STM32(Cortex-M 设备)中的情况而言,实际上可能没有此类限制,但您或许应该更新启动代码以使用较新的函数来确定.也就是说,鉴于此函数所需的行为以及其结果在寄存器中返回的事实,如果您需要那么多,我建议 88 字节会相当奢侈!此外,如果您按照描述使用分散加载文件,则只需重新实现它.

In your case in STM32 (a Cortex-M device), it is likely that there is in fact no such restriction, but you should perhaps update your start-up code to use the newer function to be certain. That said, given the required behaviour of this function and the fact that its results are returned in registers, I would suggest that 88 bytes would be rather extravagant if you were to need that much! Moreover, you only need to reimplement it if you are using scatter loading file as described.

这篇关于ARM Cortex-M3 启动代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆