从RAM初始状态启动ARM Cortex-M3 [英] ARM Cortex-M3 boot from RAM initial state

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

问题描述

我有两块ARM Cortex-M3芯片: STMF103C8T6 STM32F103VET6 .

I have two ARM Cortex-M3 chips: STMF103C8T6 and STM32F103VET6.

设置为从RAM引导时, STMF103C8T6 PC 寄存器的初始状态为 0x20000108 STM32F103VET6 0x200001e0 .

When set to boot from RAM, initial state of STMF103C8T6 PC register is 0x20000108; 0x200001e0 for STM32F103VET6.

我无法在数据表中找到有关这些地址的信息.他们为什么以这种方式启动,在哪里可以找到有关它的信息?

I am unable to find and information about these addresses in the datasheets. Why are they booted this way and where I can find some information about it?

要澄清.当芯片组从闪存启动时, PC 寄存器指向复位处理程序的位置.该地址在复位向量表中的地址0x0处提供.但是,当芯片组从RAM启动时, PC 指向上面提到的常量地址.

To clarify. When chip set to boot from flash, PC register points to the location of the Reset Handler. This address is provided in the reset vector table at address 0x0. But when chip set to boot from RAM, PC points to constant addresses, mentioned above.

STMF103C8T6 拆卸:

20000000 <Vectors>:
20000000:       20005000        andcs   r5, r0, r0
20000004:       2000010f        andcs   r0, r0, pc, lsl #2
20000008:       2000010d        andcs   r0, r0, sp, lsl #2
2000000c:       2000010d        andcs   r0, r0, sp, lsl #2
20000010:       2000010d        andcs   r0, r0, sp, lsl #2
20000014:       2000010d        andcs   r0, r0, sp, lsl #2
20000018:       2000010d        andcs   r0, r0, sp, lsl #2
    ...
20000108:       f000 b801       b.w     2000010e <Reset_Handler>

2000010c <HardFault_Handler>:
2000010c:       e7fe            b.n     2000010c <HardFault_Handler>

2000010e <Reset_Handler>:
    ...

STM32F103VET6 拆卸:

20000000 <Vectors>:
20000000:       20005000        andcs   r5, r0, r0
20000004:       200001e7        andcs   r0, r0, r7, ror #3
20000008:       200001e5        andcs   r0, r0, r5, ror #3
2000000c:       200001e5        andcs   r0, r0, r5, ror #3
20000010:       200001e5        andcs   r0, r0, r5, ror #3
20000014:       200001e5        andcs   r0, r0, r5, ror #3
20000018:       200001e5        andcs   r0, r0, r5, ror #3
    ...
200001e0:       f000 b801       b.w     200001e6 <Reset_Handler>

200001e4 <HardFault_Handler>:
200001e4:       e7fe            b.n     200001e4 <HardFault_Handler>

200001e6 <Reset_Handler>:
    ...

推荐答案

我无法在数据表中找到有关这些地址的信息.他们为什么以这种方式启动,在哪里可以找到有关它的信息?

I am unable to find and information about these addresses in the datasheets. Why are they booted this way and where I can find some information about it?

据我所知,尚无ST的官方文档提及这种行为,更不用说对其进行详细解释了. STM32F1系列参考手册在第3.4节(启动配置""):

As far as I am aware, there is no official documentation from ST that so much as mentions this behavior, let alone explains it in any detail. The STM32F1 family reference manual states vaguely in section 3.4 ("Boot Configuration") that:

由于其固定的内存映射,代码区从地址0x0000开始(通过ICode/DCode总线访问),而数据区(SRAM)从地址0x2000 0000开始(通过系统总线访问).Cortex®-M3CPU始终在ICode总线上获取复位向量,这意味着引导空间仅在代码区域(通常为闪存)中可用. STM32F10xxx微控制器实现了一种特殊的机制,使其不仅可以从SRAM引导,而且还可以从SRAM引导.

唯一引用这些地址和值的唯一位置是它们的某些模板启动文件中,即使这样,也并非全部.为ARM和IAR工具链提供的SPL启动文件缺少对BootRAM的支持.此功能仅包含在GCC和TrueSTUDIO工具链的启动文件中.

The only place these addresses and values are referenced at all is in some of their template startup files -- and even then, not all of them. The SPL startup files supplied for the ARM and IAR toolchains lack support for BootRAM; this functionality is only included in the startup files for the GCC and TrueSTUDIO toolchains.

无论如何.这是我对情况的最佳分析.

Anyways. Here's my best analysis of the situation.

复位STM32F1部件时,将根据BOOT引脚的配置来映射从0x00000000开始的存储块.设置为从Flash引导时,该块将别名为Flash;否则,该块将成为Flash的别名.设置为从引导加载程序运行时,该块将别名为内部ROM块(大约或略低于0x1FFFF000).但是,将其设置为从RAM引导时,会发生非常奇怪的情况.

When a STM32F1 part is reset, the memory block starting at 0x00000000 is mapped based on the configuration of the BOOT pins. When it is set to boot from flash, that block is aliased to flash; when it is set to run from the bootloader, that block is aliased to a block of internal ROM (around or slightly below 0x1FFFF000). However, when it is set to boot from RAM, something very strange happens.

不是像您期望的那样将该存储块别名为SRAM,而是将该存储块别名为一个很小的(16字节!)ROM.在STM32F103C8(中等密度)部分上,此ROM具有以下内容:

Instead of aliasing that memory block to SRAM, as you would expect, that memory block is aliased to a tiny (16 byte!) ROM. On a STM32F103C8 (medium density) part, this ROM has the contents:

20005000 20000109 20000004 20000004

此数据被解释为向量表:

This data is interpreted as a vector table:

  • 第一个字使堆栈指针初始化为0x20005000,它位于RAM的顶部.

  • The first word causes the stack pointer to be initialized to 0x20005000, which is at the top of RAM.

第二个字是复位向量,并设置为0x20000108(低位设置为启用Thumb模式).该地址也位于RAM中,比向量表的末尾多了几个字,在这里应该将魔术"值设置为0xF108F85F.这实际上是 ldr.w pc,[pc,#-480] 指令,该指令从RAM加载实际的复位向量并分支到其中.

The second word is the reset vector, and is set to 0x20000108 (with the low bit set to enable Thumb mode). This address is in RAM as well, a few words beyond the end of the vector table, and it's where you're supposed to put the "magic" value 0xF108F85F. This is actually the instruction ldr.w pc, [pc, #-480], which loads the real reset vector from RAM and branches to it.

第三个和第四个单词是NMI和Hardfault向量.它们没有设置低位,因此,如果在VTOR仍为零的情况下发生这些异常之一,则处理器将发生双重故障.令人困惑的是,PC将指向RAM中的向量表.

The third and fourth words are the NMI and hardfault vectors. They do not have the low bit set, so the processor will double-fault if either of these exceptions occurs while VTOR is still zero. Confusingly, the PC will be left pointing to the vector table in RAM.

此ROM的确切内容因部件而异.例如,一条F107(连接线)具有ROM内容:

The exact contents of this ROM vary slightly from part to part. For example, a F107 (connectivity line) has the ROM contents:

20005000 200001e1 20000004 20000004

具有相同的初始SP,但具有不同的初始PC.这是因为该部分具有更大的向量表,并且中等密度地址将位于其向量表内.

which has the same initial SP, but a different initial PC. This is because this part has a larger vector table, and the medium-density address would be inside its vector table.

使用的位置和值的完整列表是:

A full list of the locations and values used is:

  • 低/中密度:0x0108(值:0xF108F85F)
  • 低/中密度值行:0x01CC(值:0xF1CCF85F)
    注意:ST的样本文件与低/中密度零件的值相同.我敢肯定这是错误的,并已在此处进行了更正,但是我没有要测试的任何这种类型的部件.感谢您提供反馈以确认是否可行.
  • 其他所有:0x01E0(值:0xF1E0F85F)
  • Low/medium density: 0x0108 (value: 0xF108F85F)
  • Low/medium density value line: 0x01CC (value: 0xF1CCF85F)
    Note: ST's sample files give the same value as for low/medium density parts. I'm pretty sure this is wrong and have corrected it here, but I don't have any parts of this type to test with. I'd appreciate feedback to confirm if this works.
  • All others: 0x01E0 (value: 0xF1E0F85F)

值得庆幸的是,这种行为在很大程度上似乎是F103/5/7系列所独有的.较新的部件使用不同的方法来控制启动,这些方法更加一致.

Thankfully, this behavior seems to be largely unique to the F103/5/7 family. Newer parts use different methods to control booting which are much more consistent.

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

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