This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] RTOS/TMS570LS1224:snprintf n#39;t 正常工作

Guru**** 2463330 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/656032/rtos-tms570ls1224-snprintf-doesn-t-work-correct

器件型号:TMS570LS1224

工具/软件:TI-RTOS

大家好、

我的程序中的 snprintf 函数有问题。 我也在使用 FreeRTOS。

当我调用 snprintf 时、微控制器(TI Hercules)在函数的第4次调用后冻结:

//打印。
LevelValues 级别=级别[levelNumber];
int n = 0;
char str[50]={0};
N = snprintf (str、50、"%d %d %d %d %d %d"、level.fl_heel、level.fr_wheel、level.bl_heel、level.br_wheel);
printText_ex (str、n);
//结束打印

在调试中、我看到它卡在"Abort"(或类似的东西)等函数中。

P.S. 我在这里发现了类似的问题:

e2e.ti.com/.../595518

感谢你的帮助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    Alex、您好!

    中止意味着存在某种 CPU 异常。 您能否判断中止是数据中止还是预取中止? 此外、您能否查看 CP15中的故障状态寄存器以查看导致中止的地址以及中止是精确还是不精确?

    通常、在这些情况下、这意味着您尝试访问不存在的一部分存储器。 即、如果您使用动态分配的存储器或指针、则它可能是失控指针或存储器分配、对于器件来说太大。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好、Chuck、

    我将代码更改为下一个代码:

    int n = 0;
    char str[50]={0};
    n = snprintf (str、50、"%d %d %d %d %d"、0、1、2、3);
    sciDisplayData(str, n); 

    其中

    void sciDisplayData (const portCHAR *文本、portSHORT 长度)
    {
    sciBASE-t * sciReg = scilinREG;
    while (length--)
    {
    uint8 chr =(uint8)(*(text++));
    while ((sciReg->FLR & 0x4)=4)
    ;/*等待忙*/
    sciSendByte (sciReg、chr);/*发送文本*/
    };
    } 

    按下"暂停"按钮时、我还连接了屏幕。 我假设"_dabort"是数据中止。 还可以看到 CP15寄存器。

    我跟踪(使用 F6)到调用它的函数(请参阅屏幕截图2)。 看起来它与我在程序中使用的队列连接。

    如果我不使用 snprintf、则一切都正常。

    使用注释的正常运行的 snprintf:

    int n = 0;
    //char str[50]={0};
    //n = snprintf (str、50、"%d %d %d %d %d"、0、1、2、3);
    char* str ="olololo";
    sciDisplayData(str, 5); 

    P.S. 我在一个任务中使用 snprintf、在另一个任务中使用队列。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    尊敬的 Alex:

    您注意到这可能与您在应用中使用的队列有关、我们还需要做什么来帮助调试吗? 您是否确认了 snprintf 函数和队列之间的冲突? 是否有与这些函数相关联的缓冲区重叠导致内存损坏?