ARM Cortex M0 and M0+ 学习:Architecture

张开发
2026/4/3 18:52:09 15 分钟阅读
ARM Cortex M0 and M0+ 学习:Architecture
Block DiagramOperation ModeThe ARMv6-M architecture hastwo operation modes and two states. In addition, it can haveprivilegedandunprivilegedaccess levels.Core RegistersR0-R12:通用寄存器R13(SP):存储主栈指针MSP或进程指针PSP,目的是帮助CPU在栈中寻址比如复位后,CPU读取镜像文件地址0的数据,将其写入MSP中就是让CPU知道main函数对应在栈中的位置比如程序定义一个局部变量A,那么执行到A时,CPU会把A在栈中的地址写入到MSP,从而对该变量进行读取或写入。PSP只在使用操作系统时会用到,这是因为操作系统中系统和程序是运行在不同的栈上。R13是指MSP还是PSP取决于特殊寄存器CONTROL的配置MSP和PSP只有在Thread mode下可选,handler mode下固定使用MSPR14(LR):链接寄存器。记录子函数在母函数中的位置,以便CPU在执行完子函数后会顺利回到母函数并执行下一条指令。具体来说,当执行 BL 或 BLX 指令时,返回地址会存储在 LR 中。在子程序或函数结束时,存储在 LR 中的返回地址会被加载到程序计数器(PC)中,以便恢复调用程序的执行。R15(PC):程序计数寄存器。用来告诉CPU下一条指令存储的地址。Reading PC returns the current instruction address + 4 (this is caused by the pipeline nature of the design). Writing to R15 will cause a branch to take place (but unlike a function call, the LR does not get updated).xPSR: 程序状态寄存器(只读)。它是APSR应用状态寄存器+IPSR中断状态寄存器+EPSR执行状态寄存器的合并TheAPSRcontains theALU flags: N (negative flag), Z (zero flag), C (carry or borrowflag), and V (overflow flag). These bits are at the top 4 bits of the APSR. The common useof these flags is to control conditional branches.TheIPSRcontains thecurrent executing ISR (Interrupt Service Routine) number中断号. This is useful for identifying the current interrupt type during debugging and allows anexception handler that is shared by several exceptions to know which exception it is serving.TheEPSRon the Cortex-M0/M0+

更多文章