硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3674|回复: 5
收起左侧

[有问必答] 浮点数打印问题

[复制链接]

1

主题

2

回帖

5

积分

新手上路

积分
5
发表于 2019-3-16 13:02:53 | 显示全部楼层 |阅读模式
安富莱V4的ucsoiii官方例程用MDK4编译后能够正常打印CPU的使用率(浮点数显示),但是改成用MDK5.25编译后同样下载到板子中切打印CPU的使用率全部为0,这是为什么啊?
官方代码什么也没有改,只是换了一下编译器,求指教,谢谢
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2019-3-16 13:09:45 | 显示全部楼层
F1没浮点问题,直接上传你转换后的,例子,我在V4上走一个。
回复

使用道具 举报

1

主题

2

回帖

5

积分

新手上路

积分
5
 楼主| 发表于 2019-3-16 15:06:19 | 显示全部楼层
你的ucosiii教程中每个例子都有打印线程信息的那个函数啊,我这边换成MDK5.25后执行那个函数浮点数打印全是0(打印CPUUsag也一直为0)
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2019-3-16 15:06:58 | 显示全部楼层
在现人_BuIa1 发表于 2019-3-16 15:06
你的ucosiii教程中每个例子都有打印线程信息的那个函数啊,我这边换成MDK5.25后执行那个函数浮点数打印全是 ...

上传你转换的例子,我这里没问题。我看看是不是你的MDK异常了。
回复

使用道具 举报

14

主题

9

回帖

51

积分

初级会员

积分
51
发表于 2019-3-16 23:42:04 | 显示全部楼层
可能是任务堆栈对齐问题,我写的os也遇到过这个问题,后来在创建任务堆栈数组的时候用8位对齐方式创建后浮点就打印正常了
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2019-3-16 23:43:29 | 显示全部楼层
Angle_145 发表于 2019-3-16 23:42
可能是任务堆栈对齐问题,我写的os也遇到过这个问题,后来在创建任务堆栈数组的时候用8位对齐方式创建后浮 ...

创建的时候设置8字节对齐解决不了根本问题,根本问题是移植文件里面得做8字节对齐,这里设置后,即使任务栈不是对齐也没关系,因为移植这里修改为对齐了。
p_stk = (CPU_STK *)((CPU_STK)(p_stk) & 0xFFFFFFF8); 这句话是关键

  1. /*
  2. **********************************************************************************************************
  3. *                                       INITIALIZE A TASK'S STACK
  4. *
  5. * Description: This function is called by OS_Task_Create() or OSTaskCreateExt() to initialize the stack
  6. *              frame of the task being created. This function is highly processor specific.
  7. *
  8. * Arguments  : p_task       Pointer to the task entry point address.
  9. *
  10. *              p_arg        Pointer to a user supplied data area that will be passed to the task
  11. *                               when the task first executes.
  12. *
  13. *              p_stk_base   Pointer to the base address of the stack.
  14. *
  15. *              stk_size     Size of the stack, in number of CPU_STK elements.
  16. *
  17. *              opt          Options used to alter the behavior of OS_Task_StkInit().
  18. *                            (see OS.H for OS_TASK_OPT_xxx).
  19. *
  20. * Returns    : Always returns the location of the new top-of-stack' once the processor registers have
  21. *              been placed on the stack in the proper order.
  22. *
  23. * Note(s)    : 1) Interrupts are enabled when task starts executing.
  24. *
  25. *              2) All tasks run in Thread mode, using process stack.
  26. **********************************************************************************************************
  27. */

  28. CPU_STK  *OSTaskStkInit (OS_TASK_PTR    p_task,
  29.                          void          *p_arg,
  30.                          CPU_STK       *p_stk_base,
  31.                          CPU_STK       *p_stk_limit,
  32.                          CPU_STK_SIZE   stk_size,
  33.                          OS_OPT         opt)
  34. {
  35.     CPU_STK  *p_stk;


  36.     (void)opt;                                              /* Prevent compiler warning                               */

  37.     p_stk = &p_stk_base[stk_size];                          /* Load stack pointer                                     */
  38.                                                             /* Align the stack to 8-bytes.                          */
  39.     p_stk = (CPU_STK *)((CPU_STK)(p_stk) & 0xFFFFFFF8);
  40.         
  41.                                                                                                                         /* Registers stacked as if auto-saved on exception        */
  42.     *--p_stk = (CPU_STK)0x01000000u;                        /* xPSR                                                   */
  43.     *--p_stk = (CPU_STK)p_task;                             /* Entry Point                                            */
  44.     *--p_stk = (CPU_STK)OS_TaskReturn;                      /* R14 (LR)                                               */
  45.     *--p_stk = (CPU_STK)0x12121212u;                        /* R12                                                    */
  46.     *--p_stk = (CPU_STK)0x03030303u;                        /* R3                                                     */
  47.     *--p_stk = (CPU_STK)0x02020202u;                        /* R2                                                     */
  48.     *--p_stk = (CPU_STK)p_stk_limit;                        /* R1                                                     */
  49.     *--p_stk = (CPU_STK)p_arg;                              /* R0 : argument                                          */
  50.                                                             /* Remaining registers saved on process stack             */
  51.     *--p_stk = (CPU_STK)0x11111111u;                        /* R11                                                    */
  52.     *--p_stk = (CPU_STK)0x10101010u;                        /* R10                                                    */
  53.     *--p_stk = (CPU_STK)0x09090909u;                        /* R9                                                     */
  54.     *--p_stk = (CPU_STK)0x08080808u;                        /* R8                                                     */
  55.     *--p_stk = (CPU_STK)0x07070707u;                        /* R7                                                     */
  56.     *--p_stk = (CPU_STK)0x06060606u;                        /* R6                                                     */
  57.     *--p_stk = (CPU_STK)0x05050505u;                        /* R5                                                     */
  58.     *--p_stk = (CPU_STK)0x04040404u;                        /* R4                                                     */

  59.     return (p_stk);
  60. }
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-11 19:58 , Processed in 0.259838 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表