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.

AM263P4: PRU stack pointer initialization when using c code

Part Number: AM263P4


Tool/software:

I was informed yesterday that the c-code compiler for the PRU does not add instructions to initialize the value of the stack pointer held at r2.  I was told I need to work around this and add inline assembly to initialize this value.

Specifically, the compiled code creates an assembly command to move the stack pointer immediately upon entry to the main function. I need a way to add an instruction prior to the entry into the main function which initializes the value of r2 correctly based on the size of the stack.

  • Hi Nathan,

    Please follow the guide here on how o program PRU with a mix of C language and assembly:

    software-dl.ti.com/.../PRU-Getting-Started-Labs_Lab2.html

  • Thank you for the information. Unfortunately this does not answer my question. None of the examples provided show a method for r2 being initialized to the stack pointer location. There is no mention in the project setup of any special steps required to accomplish this. And there is no example that shows how an assembly command can be inserted prior to the entry to the main function.

  • I am still seeking solutions to this problem. For additional information, here is a snippet of the generated assembly code which shows register r2 being manipulated immediately upon entry to the main function.  Please provide me with a method that can set r2 to the correct value prior to entering main.

    ;***************************************************************
    ;* FNAME: main FR SIZE: 33 *
    ;* *
    ;* FUNCTION ENVIRONMENT *
    ;* *
    ;* FUNCTION PROPERTIES *
    ;* 1 Auto, 32 SOE *
    ;***************************************************************

    ||main||:
    ;* --------------------------------------------------------------------------*
    .dwcfi cfa_offset, 0
    SUB r2, r2, 0x21 ; []
    .dwcfi cfa_offset, 33
    SBBO &r3.b2, r2, 1, 32 ; []

  • Nathan, this does not fixes the issue completely as even using assembly initialization of R2 , it comes after SUB R2, R2,4

  • But it should enable you to use the R2 after the forced initialization have been done. A harder work around is to use assembly level programming.