ARM Cortex M
HardFault Handling
Analyze Hard Fault
當Exception發生時,如何找到Exception發生的位置?
EXC_RETURN |
條件 |
0xFFFFFFF1 |
返回handler mode(巢狀中斷) |
0xFFFFFFF9 |
返回thread mode,使用msp |
0xFFFFFFFD |
返回thread mode,使用psp |
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
實驗
- 定義0xFFFFFFFF位址。
- 嘗試放在某個程式段中,會發生Hard Fault。
- 判斷目前的Stack Pointer是MSP還是PSP,另外儲存LR。
- 倒出Stacking的Stack Memory資訊。
實驗結果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
執行到LDR r0, [r0, #0x00]會造成Hard Fault。
Why Use "volatile"
Compiler開O0和O3的差異
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
分析組語
分析assembly,開O3結果變成重複一直跳0x080029f8。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
原因
Compiler會因為要加速程式執行的performance,把0x20000060位址的數值暫存在CPU Register(R0~R12)中,不再從Memory裡載入到CPU Register(R0~R12)中,導致value值沒有被更新。因此使用volatile來避免Compiler過度優化。
Variable Length Argument
結果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →