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.

TMS320C6727: Return address not being saved to stack causing RET to jump to bogus address

Part Number: TMS320C6727

Hi, I'm running into what looks like a low-level or hardware issue which causes one of my functions to jump to a bogus address on return.

I'm using CCSV7 on linux and compiler 7.3.17. The function causing the issue is written in C. All assembly shown here is generated by the compiler.

The info from the assembly listing file for this function is:

;* FUNCTION NAME: xxxxxxxxxxxxxxxxxxxx                                        *
;*                                                                            *
;*   Regs Modified     : A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,   *
;*                           A15,B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,   *
;*                           B13,SP,A16,A17,A18,A19,A20,A21,A22,A23,A24,A25,  *
;*                           A26,A27,A28,A29,A30,A31,B16,B17,B18,B19,B20,B21, *
;*                           B22,B23,B24,B25,B26,B27,B28,B29,B30,B31          *
;*   Regs Used         : A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,   *
;*                           A15,B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,   *
;*                           B13,DP,SP,A16,A17,A18,A19,A20,A21,A22,A23,A24,   *
;*                           A25,A26,A27,A28,A29,A30,A31,B16,B17,B18,B19,B20, *
;*                           B21,B22,B23,B24,B25,B26,B27,B28,B29,B30,B31      *
;*   Local Frame Size  : 0 Args + 40 Auto + 44 Save = 84 byte                 *

When the function starts, the return address register B3 holds the correct return address 0x8046.FA9C.

The code is going to save B3 onto the stack at SP[20]; SP[20] is highlighted in the memory browser tab:

Everything looks as expected as the STW is about to be executed:

But SP[20] remains unchanged after the STW (B3 has changed per the other instructions):

Jumping to the end of the function, B3 is about to be loaded from the stack:

But the stack holds a bogus address, so the function does not return to the correct address.

If I manually set SP[20] to the correct value of 0x8046.FA9C when PC is at 0x8046.ECE0 then the function returns correctly and the rest of the code runs as expected. This is the only function in the entire program that shows this weird behavior.

As far as I can tell, the assembly code looks correct, assuming the code in the disassembly view is what the DSP is actually seeing.

It appears as if the hardware just does not perform the STW to SP[20]. I have also tried clearing SP[20] to 0 prior to executing the STW and it remains at 0, adding support to the theory that the STW is not executing.

Some more background: immediately prior to calling this function, we load some data out of flash memory via the async EMIF interface at 0x9000.0000 and save it to external RAM at 0x8000.0000. Part of the flash reading operation requires playing with some GPIOs on the UHPI interface to set the upper address bits for the flash chip. No interrupts are running at this point in the code.

Any ideas as to what could be causing this issue or how to resolve it? Thanks in advance.

  • I recompiled the same code with compiler 7.4.18 and was no longer seeing the issue

    I then reworked some of the code to fix some unrelated timing, reverted back to 7.3.17, and am no longer seeing the issue.

    So whatever the issue was, it seems to be extremely rare, perhaps was related to the exact code placement of the original version of the function or the exact combination of registers being used, and may or may not be limited to compiler 7.3.17.

  • Hi Edward,

    Thanks for the update. Feel free to post a reply here to re-open the thread if you see the issue return.