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.

TMS320F28377D: TMS320F28377D Stack Pointer Reset issue.

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hi Team,
i tyring to jump my Application as well as reset Stack pointer but Get some Error in Assembly level or what I don't understand so it' s Great help for resolve this issue here I'm sharing code and Respected Error as below.



above is code Snip.

below as error:-

Description Resource Path Location Type
#18 expected a ")" main.c /Power_Convt_SW_New_DSP line 292 C/C++ Problem.

Regards,

  • Hello,

    Is the JumpToApplication() function code that you wrote? Or is this provided by one of TI's software packages?

    Best Regards,

    Delaney

  • Hi Ujwal, 

    Can you send me your code as text so I can test it out?

    Best Regards,

    Delaney

  • Hi Delaney,

    Sure will share code so you might evolute itself, if possible to you come online like TeamViewer or anything so you can check it out rapidly all my hardware stuff it ready.

    Regards,
    Ujwal AP. 

  • Hi Ujwal,

    Can you send the code through E2E first for me to try? Since it is a build error, I should be able to replicate easily without hardware.

    Best Regards,

    Delaney

  • void JumpToApplication(void)
    {
    //#if 0
        // Define a function pointer to the application start address
        void (*appStart)(void);
    
        // Get the reset vector address (address of the application's reset handler)
        appStart = (void (*)(void))(*((volatile uint32_t *)(APPLICATION_FLASH_START_ADDRESS + 0x4)));
    
        // Disable interrupts
        DINT;
    
        // Set the stack pointer to the application's stack pointer
        uint32_t appStackPointer = *(volatile uint32_t *)APPLICATION_FLASH_START_ADDRESS; // Get the stack pointer from the application's start address
        __asm(" MOV     DP, %0" : : "r" (appStackPointer)); // Set the stack pointer
    
        // Jump to the application
        appStart(); // Call the application
    //#endif
    /*    // Disable interrupts
        DINT; // Disable global interrupts
    
        // Set the Stack Pointer (SP)
        asm(" MOV     DP, %0" : : "r" (STACK_START_ADDR)); // Set Data Pointer to stack address
        asm(" MOV     SP, %0" : : "r" (STACK_START_ADDR)); // Set Stack Pointer to stack address
    
        // Set the Program Counter (PC) to the application start address
        asm(" MOV     DP, %0" : : "r" (APPLICATION_FLASH_START_ADDRESS)); // Set Data Pointer to application address
        asm(" MOV     PC, %0" : : "r" (APPLICATION_FLASH_START_ADDRESS)); // Set Program Counter to application address
    
        // Set the Program Counter (PC) to the application start address
        AppEntry appEntry = (AppEntry)(APPLICATION_FLASH_START_ADDRESS); // Cast the application start address to a function pointer
        appEntry(); // Jump to the application
    */
        /*    // Define the new stack pointer location
        // This should be a valid RAM address where the stack will start
        volatile Uint32 *newStackPointer = (volatile Uint32 *)0x2000; // Change this address as needed
    
        // Set the stack pointer to the new location
        // In C, you can't directly assign to SP, so you need to use assembly
        asm(" MOV     A, newStackPointer"); // Load the address into A register
        asm(" MOV     SP, A");              // Move the value in A to the stack pointer
         */
    /*
        // Get the application's stack pointer value from the start of the image
        uint32_t app_sp = *((uint32_t *)APP_START_ADDRESS);
    
        // Get the application's entry point (Reset Handler)
        AppEntryPoint app_entry = (AppEntryPoint)(*((uint32_t *)(APP_START_ADDRESS + 4)));
    
        __asm(" MOV SP, @_stack_top");
        // Reset the stack pointer (SP)
        (__asm__ volatile ("MOV SP, %0" : : "r" (app_sp) : ));
    
        // Jump to the application entry point
        app_entry();
    */
    
    void main(void)
    {
        //ReceiveCANData();
        JumpToApplication();
    }
    }

    hey Delaney here sharing function and it calling stage from main 

    __asm(" MOV DP, %0" : : "r" (appStackPointer)); // Set the stack pointer
    above line will spotted on "linenum=15" for error

    error: Description Resource Path Location Type
    #18 expected a ")" main.c /CPS_SW_GEN5_New_DSP line 294 C/C++ Problem


    regards
    Ujwal AP. 

  • Hi Ujwal,

    I apologize for the delay. To update, I have copied your code into a project and am getting the same issue as you are seeing. Unfortunately, I have not been able to resolve the build warning after the adjusting the code, currently working with the compiler team to see what may be causing this.

    Best regards,

    Delaney

  • Thanks Delaney for your prompt Response, but we are curiously looking for solution,

    tell me if any thing required from my end, so i'll provide and we can mitigate this issue.
    awaiting for your solution.

    Thanks,
    Ujwal AP. 

  • Hi Ujwal,

    From our compiler expert:

    asm statements are not specified in the C or C++ standards. That particular variant comes from GCC. Our clang-based compilers (tiarmclang and c29clang) support it. 

    Best Regards,

    Delaney

  • Hi Delaney!!!

    Thanks, Respond,

    but how i can resolve this issue?
    If you can give me your asm statements just Verified by you so, i can implement nullify particular challenge.

    Awaiting for your good response.

    Regards,
    Ujwal AP.

  • Hi Ujwal,

    Delaney is currently out of office until after the holidays. Please expect a delay in response. Thank you for your patience.

    Best Regards,

    Aishwarya

  • Hi Ujwal,

    I apologize for my delayed response.

    asm statements are not specified in the C or C++ standards. That particular variant comes from GCC. Our clang-based compilers (tiarmclang and c29clang) support it. 

    In other words, the C28x compiler does not support the statement you are trying to use. While C28x does support __asm statements, they should really only be used for simple instructions like EINT, NOP, ESTOP0 etc. MOV instructions require a known state of CPU control registers to work; the GCC compiler knows how to define these states but the C28x compiler cannot.

    I'm assuming this code is for a custom bootloader? Do you have a separate stack defined for the bootloader in the bootloader's linker cmd file? If so, there is no need to reset the stack pointer in your application. All you should need to do is jump to your application code, usually this is done with a long branch instruction.

    Best Regards,

    Delaney

  • Hi, Team
    Happy New Year!!!!
    Hope you guys are doing very well,

    Add on this i have one more question as below,

    if we have code and it's store into ABCD flash sector and one more small code like Led Blinking which will store into "H" flash Sector so I i want to jump using "asm(" LB 0x0A0000");" instruction so both code are Switching or Jumping Perfectly 

    NOTE:  above both code are push by TI debugger only.

    Now, Same code as LED blink Hex file i want to store using CAN protocol as well as FlashAPI Function it's store in Flash Sector "H" successfully without any error but now i wanted to Jump using "asm(" LB 0x0A0000");" instruction it not jumping or switching it directly jump below function.

    __interrupt void Interrupt_illegalOperationHandler(void)
    {
    //
    // Something has gone wrong. The CPU has tried to execute an illegal
    // instruction, generating an illegal instruction trap (ITRAP).
    //
    ESTOP0;
    for(;;)
    {
    ;
    }
    }



    I need to understand like if we push the code using TI Debugger than both code are jump properly without any error but if we flash same Hex file of "H" sector related (LED Blinking code Hex file) so it store perfectly but code it not jump or switching, so kindly please look into this matter.

    awaiting for your Good Response!!!!

    Regards
    UJWAL AP

  • Hi,

    Delaney is out of office until next week, please expect a delayed response.

    Best Regards,

    Ben Collier

  • Hi Ujwal,

    Hope you had a happy holiday! I looping in the flash expert for your latest question.

    Best Regards,

    Delaney

  • Hi Ujwal,

    So you are able to branch to 0xA0000 properly with asm(" LB 0xA0000"); when you flash the application via JTAG/debugger but not when you program it via the flash API? Is my understanding correct? There should be no difference in what is loaded by the flash API and what is loaded via JTAG/debugger. I suggest doing a memory dump of flash sector H and comparing the contents when it is programmed via JTAG/debugger and when programmed via the flash API. If you find a difference, there is likely an error in the programming logic. 

    Kind regards,

    Skyler

  • Hi, Skyler!!!

    Thank you for your Prompt Respond.
    I already Check both .Hex file with Beyond Compare and there is no error, even each line are matching with what we dump with debugger as well as with flash dump.

    Regards,
    Ujwal AP.


  • Hi Skyler!!!
    can you please help us how we can jump, if any different Method? rather doing asm(" LB 0xA0000"); 

    regards,
    Ujwal AP.

  • Hi Ujwal,

    You can try using the Long Indirect Branch instruction. So you would need to store 0xA0000 in the XAR7 register and then branch to it with asm(" LB *XAR7");

    This instruction is detailed in the TMS320C28x CPU and Instruction Set Guide, and is used in other flash kernels. You can refer to the flash_kernel_ex5_dcan_flash_kernel.c from the F280015x DCAN flash kernel project (C2000ware/driverlib/f280015x/examples/flash/ccs/f280015x_flash_kernel_ex5_can_flash_kernel.projectspec) to see how it is used. 

    Kind regards,

    Skyler