已经按例程全改了,运行程序还是进入HardFault.
1、------------------------------------------------------------
PendSV_Handler
CPSID I ; Prevent interrup
tion during context switch
MRS R0, PSP ; PSP is process stack pointer 如果在用PSP堆栈,则可以忽略保存寄存器,参考CM3权威中的双堆栈-白菜注
CBZ R0, PendSV_Handler_Nosave ; Skip register save the first time
;Is the task using the FPU context? If so, push high vfp registers.
TST R14, #0x10
IT EQ
VSTMDBEQ R0!, {S16-S31}
SUBS R0, R0, #0x20 ; Save remaining regs r4-11 on process stack
STM R0, {R4-R11}
LDR R1, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R1, [R1]
STR R0, [R1] ; R0 is SP of process being switched out
; At this point, entire context of process has been saved
PendSV_Handler_Nosave
PUSH {R14} ; Save LR exc_return value
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, =OSPrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, =OSPrioHighRdy
LDRB R2, [R1]
STRB R2, [R0]
LDR R0, =OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R1, =OSTCBHighRdy
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdy->OSTCBStkPtr;
LDM R0, {R4-R11} ; Restore r4-11 from new process stack
ADDS R0, R0, #0x20
;Is the task using the FPU context? If so, push high vfp registers.
TST R14, #0x10
IT EQ
VLDMIAEQ R0!, {S16-S31}
MSR PSP, R0 ; Load PSP with new process SP
ORR LR, LR, #0x04 ; Ensure exception return uses process stack
CPSIE I
BX LR ; Exception return will restore remaining context
NOP
end
2、------------------------------------------------------------
OS_STK *OSTaskStkInit (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT16U opt)
{
OS_STK *stk;
(void)opt; /* 'opt' is not used, prevent warning */
stk = ptos; /* Load stack pointer */
#if (__FPU_PRESENT==1)&&(__FPU_USED==1)
*(--stk) = (INT32U)0x00000000L; //No Name Register
*(--stk) = (INT32U)0x00001000L; //FPSCR
*(--stk) = (INT32U)0x00000015L; //s15
*(--stk) = (INT32U)0x00000014L; //s14
*(--stk) = (INT32U)0x00000013L; //s13
*(--stk) = (INT32U)0x00000012L; //s12
*(--stk) = (INT32U)0x00000011L; //s11
*(--stk) = (INT32U)0x00000010L; //s10
*(--stk) = (INT32U)0x00000009L; //s9
*(--stk) = (INT32U)0x00000008L; //s8
*(--stk) = (INT32U)0x00000007L; //s7
*(--stk) = (INT32U)0x00000006L; //s6
*(--stk) = (INT32U)0x00000005L; //s5
*(--stk) = (INT32U)0x00000004L; //s4
*(--stk) = (INT32U)0x00000003L; //s3
*(--stk) = (INT32U)0x00000002L; //s2
*(--stk) = (INT32U)0x00000001L; //s1
*(--stk) = (INT32U)0x00000000L; //s0
#endif
/* Registers stacked as if auto-saved on exception */
*(stk) = (INT32U)0x01000000L; /* xPSR */
*(--stk) = (INT32U)task; /* Entry Point */
*(--stk) = (INT32U)OS_TaskReturn; /* R14 (LR) (init value will cause fault if ever used)*/
*(--stk) = (INT32U)0x12121212L; /* R12 */
*(--stk) = (INT32U)0x03030303L; /* R3 */
*(--stk) = (INT32U)0x02020202L; /* R2 */
*(--stk) = (INT32U)0x01010101L; /* R1 */
*(--stk) = (INT32U)p_arg; /* R0 : argument */
#if (__FPU_PRESENT==1)&&(__FPU_USED==1)
*(--stk) = (INT32U)0x00000031L; //s31
*(--stk) = (INT32U)0x00000030L; //s30
*(--stk) = (INT32U)0x00000029L; //s29
*(--stk) = (INT32U)0x00000028L; //s28
*(--stk) = (INT32U)0x00000027L; //s27
*(--stk) = (INT32U)0x00000026L; //s26
*(--stk) = (INT32U)0x00000025L; //s25
*(--stk) = (INT32U)0x00000024L; //s24
*(--stk) = (INT32U)0x00000023L; //s23
*(--stk) = (INT32U)0x00000022L; //s22
*(--stk) = (INT32U)0x00000021L; //s21
*(--stk) = (INT32U)0x00000020L; //s20
*(--stk) = (INT32U)0x00000019L; //s19
*(--stk) = (INT32U)0x00000018L; //s18
*(--stk) = (INT32U)0x00000017L; //s17
*(--stk) = (INT32U)0x00000016L; //s16
#endif
/* Remaining registers saved on process stack */
*(--stk) = (INT32U)0x11111111L; /* R11 */
*(--stk) = (INT32U)0x10101010L; /* R10 */
*(--stk) = (INT32U)0x09090909L; /* R9 */
*(--stk) = (INT32U)0x08080808L; /* R8 */
*(--stk) = (INT32U)0x07070707L; /* R7 */
*(--stk) = (INT32U)0x06060606L; /* R6 */
*(--stk) = (INT32U)0x05050505L; /* R5 */
*(--stk) = (INT32U)0x04040404L; /* R4 */
return (stk);
}
3、keil环境配置和FPU功能也选了
帮帮我吧!!!!!!!!!!!!!!!!!!!