谢谢版主的热心回复,可是我还是比较纳闷为何我设置了8字节对齐打印浮点会出错,不手动设置8字节对齐反而能正常打印浮点数,以下是ucos2.92.11版本里面对堆栈初始化的操作:
OS_STK *OSTaskStkInit ( void ( *task ) ( void *p_arg ), void *p_arg, OS_STK *ptos, INT16U opt )
{
OS_STK *p_stk;
( void ) opt; /* 'opt' is not used, prevent warning */
p_stk = ptos; /* Load stack pointer */
/* Align the stack to 8-bytes. */
p_stk = ( OS_STK * ) ( ( OS_STK ) ( p_stk ) & 0xFFFFFFF8u );
/* Registers stacked as if auto-saved on exception */
* (p_stk ) = ( INT32U ) 0x01000000uL; /* xPSR */
* ( --p_stk ) = ( INT32U ) task; /* Entry Point */
* ( --p_stk ) = ( INT32U ) OS_TaskReturn; /* R14 (LR) */
* ( --p_stk ) = ( INT32U ) 0x12121212uL; /* R12 */
* ( --p_stk ) = ( INT32U ) 0x03030303uL; /* R3 */
* ( --p_stk ) = ( INT32U ) 0x02020202uL; /* R2 */
* ( --p_stk ) = ( INT32U ) 0x01010101uL; /* R1 */
* ( --p_stk ) = ( INT32U ) p_arg; /* R0 : argument */
/* Remaining registers saved on process stack */
* ( --p_stk ) = ( INT32U ) 0x11111111uL; /* R11 */
* ( --p_stk ) = ( INT32U ) 0x10101010uL; /* R10 */
* ( --p_stk ) = ( INT32U ) 0x09090909uL; /* R9 */
* ( --p_stk ) = ( INT32U ) 0x08080808uL; /* R8 */
* ( --p_stk ) = ( INT32U ) 0x07070707uL; /* R7 */
* ( --p_stk ) = ( INT32U ) 0x06060606uL; /* R6 */
* ( --p_stk ) = ( INT32U ) 0x05050505uL; /* R5 */
* ( --p_stk ) = ( INT32U ) 0x04040404uL; /* R4 */
return ( p_stk );
}
可以看出,这里面
p_stk = ( OS_STK * ) ( ( OS_STK ) ( p_stk ) & 0xFFFFFFF8u );
是对堆栈首地址8字节对齐的,但是实际调试打印浮点却出错,如果把这个语句屏蔽了或者改成4字节对齐反而能正常打印浮点数。