STM32F1 Programming Manual

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

Previous topic - Next topic

tha

Exception return

Exception return เกิดขึ้นเมื่อ the processor อยู่ใน Handler mode และปฏิบัติหนึ่งของคำสั่งต่อไปนี้เพื่อโหลด the EXC_RETURN value ลงใน the PC:
•   A POP instruction ที่รวม the PC ไว้
•   A BX instruction ด้วย register ใดๆ.
•   An LDR or LDM instruction ที่มี the PC เป็น the destination(ปลายทาง)

EXC_RETURN คือค่าที่โหลดลงใน the LR ตอน exception entry. The exception mechanism อาศัยค่านี้ในการตรวจจับเมื่อ the processor เสร็จสมบูรณ์ an exception handler. The lowest four bits ของค่านี้จัดให้มี information เกี่ยวกับ the return stack และ processor mode. Table 17 แสดง the EXC_RETURN[3:0] values ที่มีคำอธิบายของ the exception return behavior

The processor เซ็ต EXC_RETURN bits[31:4] เป็น 0xFFFFFFF. เมื่อค่านี้ถูกโหลดลงใน the PC มันแสดงไปยัง the processor ว่า the exception เสร็จสมบูรณ์, และ the processor เริ่มต้น the exception return sequence.


tha

2.4 Fault handling

Faults คือ a subset ของ the exceptions, ดู Exception model บนหน้า 32. สิ่งต่อไปนี้สร้าง a fault:
•   A bus error on:
     –   An instruction fetch or vector table load
     –   A data access
•   An internally-detected error อย่างเช่น an undefined instruction หรือความพยายามเพื่อเปลี่ยน state ด้วย a BX instruction
•   ความพยายามปฏิบัติ an instruction จาก a memory region ที่ทำเครื่องหมายเป็น Non-Executable(XN).

2.4.1 Fault types

Table 18 แสดง the types of fault, the handler ที่ใช้สำหรับ the fault, the corresponding fault status register, and the register bit ที่แสดงให้เห็นว่า the fault ได้เกิดขึ้นแล้ว. ดู Configurable fault status register (SCB_CFSR) บนหน้า 142 สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ the fault status registers.


tha

2.4.2 Fault escalation and hard faults

ทุก faults exceptions ยกเว้นสำหรับ hard fault จะมี configurable exception priority, ดู System handler priority registers (SHPRx) บนหน้า 138. Software สามารถปิดใช้งานการปฏิบัติของ the handlers สำหรับ faults เหล่านี้, ดู System handler control and state register (SCB_SHCSR) บนหน้า 140.

โดยปกติ, the exception priority, ร่วมกันกับค่าของ the exception mask registers, จะกำหนดว่า the processor เข้าสู่ the fault handler หรือไม่, และว่า a fault handler สามารถยึดไว้ใช้สิทธิ์ทำงานก่อน another fault handler. ตามที่อธิบายใน Section 2.3: Exception model บนหน้า 32.

ในบางสถานการณ์, a fault ที่มี configurable priority ถูกถือว่าเป็น a hard fault. สิ่งนี้ถูกเรียกว่า priority escalation, และ the fault ถูกอธิบายเป็นการบานปลายเป็น hard fault. การบานปลายเป็น hard fault เกิดขึ้นเมื่อ:
•   A fault handler ทำให้เกิด fault ประเภทเดียวกันกับ fault หนึ่งที่มันกำลังให้บริการ. escalation to hard fault นี้เกิดขึ้นเนื่องจาก a
     fault handler ไม่สามารถยึดไว้ใช้สิทธิ์ทำงานก่อนตัวมันเองเนื่องจากมันต้องมี priority เดียวกันกับ the current priority level.
•   A fault handler ทำให้เกิด a fault ที่มี priority เดียวกันหรือต่ำกว่า the fault ที่มันกำลังให้บริการ. นี้เนื่องจาก the handler สำหรับ
     the new fault ไม่สามารถยึดไว้ใช้สิทธิ์ทำงานก่อน the currently executing fault handler.
•   An exception handler ทำให้เกิด a fault ที่ the priority เท่ากับหรือต่ำกว่า the currently executing exception.
•   A fault เกิดขึ้นและ the handler สำหรับ fault นั้นไม่ถูกเปิดใช้งาน.

ถ้า a bus fault เกิดขึ้นในระหว่าง a stack push เมื่อเข้าสู่ a bus fault handler, the bus fault ไม่บานปลายเป็น a hard fault. นี้หมายความวาถ้า a corrupted stack ทำให้เกิด a fault, the fault handler จะปฏิบัติถึงแม้ว่า the stack push สำหรับ the handler จะล้มเหลว. The fault handler ทำงานแต่ the stack contents จะเสียหาย.

มีเพียง Reset and NMI ที่สามารถยึดไว้ใช้สิทธิ์ทำงานก่อน the fixed priority hard fault. A hard fault สามารถยึดไว้ใช้สิทธิ์ทำงานก่อน exception ใดๆนอกเหนือจาก Reset, NMI, หรือ another hard fault.


tha

2.4.3 Fault status registers and fault address registers

The fault status registers แสดงให้เห็นสาเหตุของ a fault. สำหรับ bus faults and memory management faults, the fault address register แสดงให้เห็น the address ที่เข้าถึงโดยการทำงานที่ทำให้เกิด the fault, ดังแสดงใน Table 19.


tha

2.4.4 Lockup

The processor เข้าสู่ a lockup state ถ้า a hard fault เกิดขึ้นเมื่อปฏิบัติ the NMI หรือ hard fault handlers. เมื่อ the processor อยู่ใน lockup state มันจะไม่ปฏิบัติคำสั่งใดๆ. The processor ยังคงอยู่ใน lockup state จนกระทั่งอย่างใดอย่างหนึ่ง :
•   มันถูก reset
•   An NMI เกิดขึ้น

ถ้า lockup state เกิดขึ้นจาก the NMI handler a subsequent NMI ไม่เป็นเหตุให้ the processor ออกจาก lockup state.

tha

2.5 Power management

The STM32 and Cortex-M3 processor sleep modes จะลด power consumption:
•   Sleep mode หยุด the processor clock. system อื่นทั้งหมดและ peripheral clocks อาจยังคงรันอยู่.
•   Deep sleep mode หยุดส่วนใหญ่ของ the STM32 system และ peripheral clocks. ที่ product level, นี้ตรงกันกับอย่างใดอย่าง
     หนึ่ง the Stop หรือ the Standby mode. สำหรับรายละเอียดเพิ่มเติม, โปรดดูที่ the "Power modes" Section ใน the STM32
     reference manual.

The SLEEPDEEP bit ของ the SCR จะเลือก sleep mode ที่ถูกใช้, ดู System control register (SCB_SCR) บนหน้า 136. สำหรับข้อมูลเพิ่มเติมเกี่ยวกับลักษณะการทำงานของ the sleep modes ดู the STM32 product reference manual.

ส่วนนี้อธิบายกลไกสำหรับการเข้าสู่ sleep mode, และเงื่อนไขสำหรับการ waking up จาก sleep mode.

tha

2.5.1 Entering sleep mode

ส่วนนี้อธิบาย the mechanisms software สามารถใช้เพื่อผลัก the processor ลงใน sleep mode.

The system สามารถสร้าง spurious wakeup events, ตัวอย่างเช่น a debug operation จะปลุก the processor ขึ้น. ดังนั้น software ต้องสามารถที่จะผลัก the processor กลับลงใน sleep mode หลังจาก an event ดังกล่าว. A program อาจจะมี an idle loop เพื่อผลัก the processor กลับไปยัง sleep mode.

Wait for interrupt

The wait for interrupt instruction, WFI, เป็นเหตุให้เข้าสู่ sleep mode ทันที. เมื่อ the processor ปฏิบัติ a WFI instruction มันจะหยุดปฏิบัติ instructions และเข้าสู่ sleep mode. ดู WFI บนหน้า 104 สำหรับข้อมูลเพิ่มเติม.

tha

Wait for event

The wait for event instruction, WFE, เป็นเหตุให้เข้าสู่ sleep mode โดยมีเงื่อนไขตามค่าของ an one-bit event register. เมื่อ the processor ปฏิบัติ a WFE instruction, มันจะตรวจสอบ register นี้:
•   ถ้า the register เป็น 0 the processor จะหยุดการปฏิบัติ instructions และเข้าสู่ sleep mode
•   ถ้า the register เป็น 1 the processor จะเคลียร์ the register เป็น 0 และปฏิบัติ instructions ต่อเนื่องไปโดยไม่มีการเข้าสู่ sleep
     mode.

ดู WFE บนหน้า 103 สำหรับข้อมูลเพิ่มเติม.

ถ้า the event register เป็น 1, นี้แสดงให้เห็นว่า the processor ต้องไม่เข้าสู่ sleep mode ตอนการปฏิบัติของ a WFE instruction. โดยปกติ, นี้เนื่องจาก an external event signal ถูกยืนยัน, หรือ a processor ใน the system ที่ปฏิบัติ an SEV instruction, ดู SEV บนหน้า 102. Software ไม่สามารถเข้าถึง register นี้ได้โดยตรง.

Sleep-on-exit

ถ้า the SLEEPONEXIT bit ของ the SCR ถูกเซ็ตเป็น 1, เมื่อ the processor เสร็จสมบูรณ์การปฏิบัติของ an exception handler มันจะรีเทิร์นไปยัง Thread mode และเข้าสู่ sleep mode ทันที. ใช้กลไกนี้ใน applications ที่ต้องการเพียง the processor ทำงานเมื่อ an exception เกิดขึ้น.