LAUNCHXL-F28P65X: 32 bit function returning only 16 LSB

Part Number: LAUNCHXL-F28P65X

Hi experts, 

My customer is using 32 bit function like 

TestFun is called in main, and it calls TestFunInner. TestFunInner should return a 32 bit value 0x12345678 to TestFun, and then return to main.

However, the returning value of TestFunInner is 0x00005678, which only includes the LSB. 

If we call TestFunInner dirrectly in main, the returning value is normal. 

When we look into the assembly, we found that there is an extra line that makes the MSB of ACC 0x0000

This line does not exist when calling TestFunInner directly from main

Could you help explaining this? I can share a project that can reproduce this issue.

Thanks,

Hang

  • Hi Hang,

    If the function TestFunInner() isn't declared in a .h file, it would need to be defined above TestFun() since that function calls it. This should be the cause of the warnings shown in their screenshot. Changing the order of the definitions of the two functions or including function declarations in an included header file should fix the issue.

    When C code calls a function without a prior definition or declaration, the compiler generates an implicit declaration with no parameters. The default return type is an integer, which in the case of the c28x represents a 16-bit value. Therefore, the temp value 0x12345678 is casted to 16-bits when it is returned to TestFun(), hence the loss of the upper 16 bits.

    Another note is that the variable temp is global, so there should be no need to return it in this case. TestFun() can access the updated value already (and so can the main).

    Best Regards,

    Delaney

  • Hi Delaney,

    Thanks for the hint, looks like the default type casting is the issue in my testcase. Switching the order solved the problem in my project.

    This project is a demo that I extract from customer's application code, I would confirm if this is the issue in the actual application,

    Thanks,

    Hang.

  • Hi Hang,

    Please upvote my previous response if this solution works for the customer's application code. If they are still seeing the issue or have any other questions, let me know.

    Best Regards,

    Delaney

  • Thanks Delaney, the solution works for customer.

  • Great, glad to hear this fixed their issue.

    Best Regards,

    Delaney