STM32F1 Programming Manual

Started by tha, January 16, 2021, 06:11:52 AM

Previous topic - Next topic

tha

2   The Cortex®-M3 processor

2.1   Programmers model

หัวข้อนี้อธิบาย the Cortex-M3 programmers model. นอกเหนือจาก the individual core register descriptions, มันบรรจุข้อมูลข่าวสารเกี่ยวกับ the processor modes และ privilege levels สำหรับ software execution และ stacks.

2.1.1   Processor mode and privilege levels for software execution

     The processor modes คือ:

     Thread mode          ถูกใช้เพื่อปฏิบัติ application software. The processor เข้าสู่ Thread mode เมื่อมันออกจาก reset.

     Handler mode         ถูกใช้เพื่อจัดการ exceptions. The processor กลับคืนสู่ Thread mode เมื่อมันเสร็จสิ้น exception
                                       processing.

     The privilege levels สำหรับ software execution คือ:

     Unprivileged         The software:
                                      •   มีการจำกัดการเข้าถึง the MSR and MRS instructions, และไม่สามารถใช้ the CPS instruction
                                      •   ไม่สามารถเข้าถึง the system timer, NVIC, หรือ system control block
                                      •   อาจมีการจำกัดการเข้าถึง memory หรือ peripherals.
                                      Unprivileged software ปฏิบัติที่ the unprivileged level.

     Privileged              The software สามารถใช้ทุก the instructions และเข้าถึงได้ทุก resources.
                                      Privileged software ปฏิบัติที่ the privileged level.

ใน Thread mode, the CONTROL register ควบคุมว่า software execution เป็น privileged หรือ unprivileged, ดู CONTROL register บนหน้า 21. ใน Handler mode, software execution จะเป็น privileged เสมอ.

มีเพียง privileged software สามารถเขียนถึง the CONTROL register เพื่อเปลี่ยน the privilege level สำหรับ software execution ใน Thread mode. Unprivileged software สามารถใช้ the SVC instruction เพื่อทำ a supervisor call เพื่อส่งถ่ายการควบคุมไปยัง privileged software.

tha

2.1.2 Stacks

The processor ใช้ a full descending stack. ซึ่งหมายความว่า the stack pointer ระบุ the last stacked item บน the stack memory. เมื่อ the processor ใส่ a new item ไปบน the stack, มันจะลด the stack pointer และจากนั้นเขียน the item ไปยัง the new memory location. The processor จัดให้มีใช้ two stacks, the main stack and the process stack, โดยมีสำเนาอิสระของ the stack pointer, ดู Stack pointer บนหน้า 15.

ใน Thread mode, the CONTROL register ควบคุมว่า the processor ใช้ the main stack หรือ the process stack, ดู CONTROL register บนหน้า 21. ใน Handler mode, the processor จะใช้ the main stack เสมอ. ตัวเลือกสำหรับ processor operations คือ:

tha



tha


tha

General-purpose registers

R0-R12 คือ 32-bit general-purpose registers สำหรับ data operations.

Stack pointer

The Stack Pointer (SP) คือ register R13. ใน Thread mode, bit[1] of the CONTROL register ระบุ the stack pointer ที่ใช้:
•   0 = Main Stack Pointer (MSP). นี้คือ the reset value.
•   1 = Process Stack Pointer (PSP).
เมื่อ reset, the processor จะโหลด the MSP ด้วย the value จาก address 0x00000000.

tha

Link register

The Link Register (LR) คือ register R14. มันเก็บ the return information สำหรับ subroutines, function calls, and exceptions. เมื่อ reset, the processor จะโหลด the LR value 0xFFFFFFFF.

Program counter

The Program Counter (PC) คือ register R15. มันบรรจุ the current program address. Bit[0] เป็น 0 เสมอเพราะว่า instruction fetches ต้องเป็น halfword aligned. เมื่อ reset, the processor จะโหลด the PC ด้วย the value ของ the reset vector, ซึ่งคือที่ address 0x00000004.

tha

Program status register

The Program Status Register (PSR) รวมกัน:
•   Application Program Status Register (APSR)
•   Interrupt Program Status Register (IPSR)
•   Execution Program Status Register (EPSR)

รีจิสเตอร์เหล่านี้เป็นบิตฟิลด์ที่ไม่เกิดร่วมกันใน the 32-bit PSR. The bit assignments เป็นดังแสดงใน Figure 3 and Figure 4.

เข้าถึง registers เหล่านี้ทีละรายการหรือรวมกันของสองหรือทั้งหมดสาม registers, โดยใช้ the register name เป็น an argument ไปยัง the MSR or MRS instructions. ตัวอย่างเช่น:
•   อ่าน registers ทั้งหมดโดยใช้ PSR กับ the MRS instruction
•   เขียนถึง the APSR โดยใช้ APSR กับ the MSR instruction.
The PSR combinations and attributes คือ:

ดู the instruction descriptions MRS บนหน้า 100 และ MSR บนหน้า 101 สำหรับข้อมูลที่มากขึ้นเกี่ยวกับวิธีการเข้าถึง the program status registers.

tha

Application program status register

The APSR บรรจุ the current state ของ the condition flags จาก previous instruction executions. ดู the register summary ใน Table 2 บนหน้า 15 สำหรับ attributes ของมัน. The bit assignments คือ: