在线时间3 小时
UID4047955
注册时间2024-10-10
NXP金币0
TA的每日心情 | 开心 2024-11-20 15:21 |
---|
签到天数: 3 天 连续签到: 1 天 [LV.2]偶尔看看I
新手上路

- 积分
- 31
- 最后登录
- 2024-11-20
|
本帖最后由 eefocus_4047955 于 2024-10-24 15:34 编辑
最近在做LPC2136的BOOT实验,FLASH的读写IAP和程序跳转都没有问题,但转到FREERTOS的APP程序后,单步运行至OS中的一个上下文切换的位置,程序跑飞,目前没有思路,APP中,具体路径是: main()--->vTaskStartScheduler()--->xPortStartScheduler() --->vPortStartFirstTask()--->portRESTORE_CONTEXT--->{LDMFD LR, {R0-R14}^ }
后R14就跑飞,内容是0xAAAAAAAA,导致后续PC指针飞,但具体原因是什么未知,不知道去改什么地方。
请教论坛大神,这可能会是什么问题?
补充:1. FREERTOS的APP,单独运行是完全正常可以跑的程序,在这个程序 DEBUG里,我也看了上下文切换的位置,是正常的,PC不会跑飞。
2.APP程序换成纯裸机时,没有死机现象,从BOOTLOADER跳转至APP,APP运行也是正常的。
3. USR_Stack_Size EQU 0x00001000,比这个值稍微设置大点,编译就不通过,报错.\bin\RTOSDemo.axf: Error: L6406E: No space in execution regions with .ANY selector matching startup.o(STACK). 这个也不知道原因。
//MAIN函数
void main()
{
...
//系统初始化
xTaskCreate( (TaskFunction_t) initial_system,
(const char *)"initial_system",
(u16)200,
(void*)NULL,
(BaseType_t)3,
(TaskHandle_t*)NULL
);
vTaskStartScheduler();
for(;;);
}
void vTaskStartScheduler( void ) {
...
if( xPortStartScheduler() != pdFALSE )
{
/* Should not reach here as if the scheduler is running the
function will not return. */
}
...
}
BaseType_t xPortStartScheduler( void )
{
...
/* Start the first task. This is done from portISR.c as ARM mode must be
used. */
vPortStartFirstTask();
/* Should not get here! */
return 0;
}
vPortStartFirstTask()是用汇编写的函数如下:
; Starting the first task is done by just restoring the context
; setup by pxPortInitialiseStack
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
vPortStartFirstTask
PRESERVE8
portRESTORE_CONTEXT
vPortYield
PRESERVE8
SVC 0
bx lr
portRESTORE_CONTEXT的宏定义如下,也是用汇编写的:
IMPORT ulCriticalNesting ;
IMPORT pxCurrentTCB ;
MACRO
portRESTORE_CONTEXT
LDR R0, =pxCurrentTCB ; Set the LR to the task stack. The location was...
LDR R0, [R0] ; ... stored in pxCurrentTCB
LDR LR, [R0]
LDR R0, =ulCriticalNesting ; The critical nesting depth is the first item on...
LDMFD LR!, {R1} ; ...the stack. Load it into the ulCriticalNesting var.
STR R1, [R0] ;
LDMFD LR!, {R0} ; Get the SPSR from the stack.
MSR SPSR_cxsf, R0 ;
LDMFD LR, {R0-R14}^ ; Restore all system mode registers for the task运行到这个位置后,R14值为AAAAAAAA
NOP ;导至后续 PC跑飞
LDR LR, [LR, #+60] ; Restore the return address
; And return - correcting the offset in the LR to obtain ...
SUBS PC, LR, #4 ; ...the correct address.
MEND
|
|