你的启动代码请参考我的那个例子。
加上那么一段。
IF :DEF:DEBUG_ENABLE_SEMIHOST
ALIGN
; int SH_DoCommand(int n32In_R0, int n32In_R1, int *pn32Out_R0);
; Input
; R0,n32In_R0: semihost register 0
; R1,n32In_R1: semihost register 1
; Output
; R2,*pn32Out_R0: semihost register 0
; Return
; 0: No ICE debug
; 1: ICE debug
SH_DoCommand PROC
EXPORT SH_DoCommand
BKPT 0xAB ; Wait ICE or HardFault
; ICE will step over BKPT directly
; HardFault will step BKPT and the next line
B SH_ICE
SH_HardFault ; Captured by HardFault
MOVS R0, #0 ; Set return value to 0
BX lr ; Return
SH_ICE ; Captured by ICE
; Save return value
CMP R2, #0
BEQ SH_End
STR R0, [R2] ; Save the return value to *pn32Out_R0
SH_End
MOVS R0, #1 ; Set return value to 1
BX lr ; Return
ALIGN
ENDP
ENDIF