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 doesn't work correct

Part Number: TMS570LS1224

Tool/software: TI-RTOS

Hi guys,

I have a problem with snprintf function in my program. I am using FreeRTOS as well.

When I call snprintf my microcontroller (TI Hercules) freezes after the 4th call of the function:

            // printing.
            LevelValues level = levels[levelNumber];
            int n = 0;
            char str[50] = {0};
            n = snprintf(str, 50, "%d %d %d %d", level.fl_wheel, level.fr_wheel, level.bl_wheel, level.br_wheel);
            printText_ex(str, n);
            // end printing

In debug I see that it is stuck in the function like "Abort" (or something like that).

P.S. I found the similar issue here:

e2e.ti.com/.../595518

Thank you for help.

  • Hello Alex,

    Abort means there has been a CPU exception of some kind. Can you tell if the abort was a data abort or a pre-fetch abort? Also, can you have a look at the fault status register in CP15 to see what address caused the abort and if it is a precise or imprecise abort?

    Generally, in these circumstances, it means you have tried to access a portion of memory that doesn't exist. i.e., if you are using dynamically allocated memory or pointers it can be a runaway pointer or memory allocation that is too big for the device.
  • Hi Chuck,

    I changed my code to the next one:

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

    Where

    void sciDisplayData(const portCHAR *text, portSHORT length)
    {
       sciBASE_t *sciReg = scilinREG;
       while (length--)
       {
           uint8 chr = (uint8)(*(text++));
           while ((sciReg->FLR & 0x4) == 4)
               ; /* wait until busy */
           sciSendByte(sciReg, chr); /* send out text */
       };
    }

    I also attached screen when pressed 'pause' button. I suppose that "_dabort" it is data abort. There is also CP15 registers are visible.

    I traced (using F6) to the function where it was called (see screenshot number 2). It looks like it is connected with queues that I am using in my program.

    If I do not use snprintf, then everything works.

    With commented snprintf that works:

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

    P.S. I am using snprintf in one task, and queues in another.

  • Hi Alex,

    As you noted this is potentially related to queues that you are using in your application, is there anything else that we need to do to help debug? have you confirmed the conflict between the snprintf function and the queues? Are there buffers associated with these functions that overlap causing memory corruption?