TMS320VC5502: Writing to sprintf buffer crashes firmware

Part Number: TMS320VC5502

Tool/software:

Will the following code write to m_logBuffer as desired when the buffer is at address 0x0004'9C40 or will it also write to someplace else (like 0x0000'9C40)?

My system is crashing when I write to this buffer, but not immediately.  The debugger shows that the correct content is being written to the buffer but I'm suspicious since the system doesn't crash if I comment out the vsnprintf call.

Here's a collapsed version of the code -- I'm not showing the va_list and va_start macros of my Printf() function.

#pragma DATA_SECTION("ExtPgm3")
char m_logBuffer[1024] = { 0 };

char *put_ptr = m_logBuffer;


int bytesAvail = sizeof(m_logBuffer) - (put_ptr - m_logBuffer);
int bytesPrinted = vsnprintf(put_ptr, bytesAvail, fmt, args);
put_ptr += (bytesPrinted > bytesAvail) ? bytesAvail : bytesPrinted;

MEMORY CONFIGURATION

         name            origin    length      used     unused   attr    fill
                        (bytes)   (bytes)    (bytes)   (bytes)
----------------------  --------  ---------  --------  --------  ----  --------
  MMR                   00000000   000000c0  00000000  000000c0  RWIX
  VECT                  00000200   00000100  00000100  00000000  RWIX
  DARAM                 00000400   0000cc00  0000caee  00000112  RWIX
  DMABuffers            0000d000   00003000  00002acc  00000534  RWIX
  ExtPgm                00010000   00040000  0002d490  00012b70  RWIX
  ExtPgm1               00050000   00010000  0000bdce  00004232  RWIX
  ExtPgm2               00060000   00020000  00020000  00000000  RWIX
  ExtPgm3               00080000   00020000  00014088  0000bf78  RWIX
  NCISFrameBuf          000a0000   00020000  00000000  00020000  RWIX
  • Hi Dean,

    Keep in mind all C55xx devices are 16-bit addressable for data (not byte addressable). When you specify a char type array, it allocates 16-bit word for each byte element.  0x0004'9C40 must be the word address, because the ExtPgm3 starts at 0x00080000 (byte address) and 0x00040000 (word address).

    About the crash, I would monitor the bytesAvail and bytesPrinted while single step through the code. The code segment looks OK to me, except the fmt and args are unknown.

    Best regards,

    Ming

  • Hi Ming,

    Thanks for helping me understand what the problem is not.  :)  

    I found that the problem was a stack overflow on the task stack where my vsnprintf function was being called from.  It was set too small.

    I had to move the task stack from DARAM to external memory to find a place large enough for it.

    Regarding the two stack pointers on the C5502 (stack and sysstack) -- do those need to be the same size?  What's on the sysstack or how should I determine its size?

    Thanks,

    -dean

  • Hi Dean,

    As I recall, the sysstack is for the DSP/BIOS and the stack is for the user application code. You can first allocate big size for stacks, fill them with 0xA5A5, then after the program runs for some time, you check the unused stack memory (still are 0xA5A5). This way, you will get a better estimation for the actual stack sizes.

    Best regards,

    Ming