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.

TMDX570LC43HDK: The sprintf function triggers the dataEntry interrupt vector

Part Number: TMDX570LC43HDK
Other Parts Discussed in Thread: HALCOGEN

Tool/software:

Hi!

I'm trying to implement a code that uses the sprintf() function to print data to a char. When using a formatted input (i.e.: "... %u ..."), the execution of the code stops running. If the code is paused at this idle stage, the HL_sys_intvecs.asm opens at a line that reads:

b   dataEntry
.

Doing a step by step debug, I've noticed that the interrupt is triggered inside the _pproc_fwp() function in the _printfi.c file, when trying to do the assignment 

*tmpptr = '\0';
(line 559 in my case).

My suspicion is that it could be related to the way I've configured the memory sections in the HL_sys_link.cmd file, as I'm not confident with what I did:

/*                                                                            */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN (0) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Linker Settings                                                            */

--retain="*(.intvecs)"

/* USER CODE BEGIN (1) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/
/* Memory Map                                                                 */

MEMORY
{
    VECTORS (X)  : origin=0x00000000 length=0x00000020
    KERNEL  (RX) : origin=0x00000020 length=0x00008000 
    FLASH0  (RX) : origin=0x00008020 length=0x001F7FE0
    FLASH1  (RX) : origin=0x00200000 length=0x00200000
    STACKS  (RW) : origin=0x08000000 length=0x00000800
    KRAM    (RW) : origin=0x08000800 length=0x00000800
    RAM     (RW) : origin=(0x08000800+0x00000800) length=(0x0007f800 - 0x00000800)
    
/* USER CODE BEGIN (2) */
/* USER CODE END */
}

/* USER CODE BEGIN (3) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/
/* Section Configuration                                                      */

SECTIONS
{
    .intvecs : {} > VECTORS
    /* FreeRTOS Kernel in protected region of Flash */
    .kernelTEXT  align(32) : {} > KERNEL
    .cinit       align(32) : {} > KERNEL
    .pinit       align(32) : {} > KERNEL
    /* Rest of code to user mode flash region */
    .text        align(32) : {} > FLASH0 | FLASH1
    .const       align(32) : {} > FLASH0 | FLASH1
    /* FreeRTOS Kernel data in protected region of RAM */
    .kernelBSS    : {} > KRAM
    .kernelHEAP   : {} > RAM
    .bss          : {} > RAM
    .data         : {} > RAM    

/* USER CODE BEGIN (4) */
	.sysmem                : {} > RAM
	.freertosStaticStack   : {} > RAM
	.noinit                : {} > RAM
/* USER CODE END */
}

/* USER CODE BEGIN (5) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/
/* Misc                                                                       */

/* USER CODE BEGIN (6) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/
 

The code that I'm running is a simple sprintf example:

uint8_t i = 2;
char buffer[50];
int a = 10, b = 20, c;
c = a + b;
sprintf(buffer, "Sum of %d and %d is %d", a, b, c);

Thank you in advance!

  • Hi,

    I am not facing any issues with your code.

    Here is my tested project:

    Customer_Issue_Sprintf_test_LC4357.zip

    Refer above attached project once, if it doesn't solve your problem then please share your project to debug the issue at my end.

    --
    Thanks & regards,
    Jagadish.

  • Hi! Thanks for the reply!

    I've realised that the error does not occur every time I use the sprintf() function. In my project, I'm using the SCI driver to print to the terminal, and that's where it fails.

    Interestingly enough, running the same main on your project (adding the SCI driver in HALCoGen) seems to work (although the printed values are wrong, but that's something I'll worry about in the future).

    Here is my project:

    sprintf_test.zip

    And here is the modified version of your project:

    2671.Customer_Issue_Sprintf_test_LC4357.zip

    Thanks and regards,

    Enrique

  • Hi Enrique,

    I didn't get time to debug this issue due to other priority issues.

    Mean time i am suggesting you to refer below FAQ for troubleshooting of different exceptions:

    (+) [FAQ] TMS570LC4357: Troubleshooting the Abort Exceptions on Hercules Devices - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    --
    Thanks & regards,
    Jagadish.

  • So...

    I managed to solve the issue.

    It was as simple as declaring the bufferTX variable as static (and setting all of its values to 0). It appears that when you do not do that, the memory that was allocated for the buffer gets overwritten, eventually resulting on the program trying to write into a null pointer, thus triggering the data exception (I believe, but I'm still not quite sure). I must admit that I still don't understand completely how this microcontroller uses memory, but I guess I'll figure it out along the way.

    Regarding the other problem (the gibberish I got instead of the expected values passed to the sprintf function), I just was stupid and really didn't look into the interaction of va_list variables and the printf family of functions. The issue was solved by changing sprintf to vsprintf. I think it's something that falls into the small bugs part of programming, but since I mentioned it on another comment, I think it was worth to explain the solution.

    The final (and functional) code of the function that was causing me problems is:

    void print_func(const char * fmt, ...) {
    
        va_list args;
    
        static char bufferTX[255];
    
        memset(bufferTX, 0, 255);
    
        va_start(args, fmt);
        vsprintf(bufferTX, fmt, args);
        va_end(args);
    
        sciDisplayText(sciREG1, (uint8_t *) &bufferTX, 255);
    }

    That said, thank you Jagasidh for your help and comments!