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.

Basic math does not work MSP430F5438

Other Parts Discussed in Thread: MSP430F5438

Yikes! Hopefully you can help me with this.

I am using CCS 5, MSP430 Compiler 4.0.1

I used default basic project generation to get a basic project.

I am trying to do a simple calculation where a multiplication gets skipped over in the debugger.

In the code below both the line

    lsrOH = lsrOH * 3;  // debugger skips over this line - I have tried many variations with same results

  slotTime = 18.0/40000. + (float) lsrOH;  // trying to calculate a float value and value is garbage when looked at in the debugger

#include <msp430f5438.h>

void main(void) {
    
    int maxRepeats = 3;

    unsigned int value;

    WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

    value = test(maxRepeats,1,2);

    printf("%d",value);


}

unsigned int test(unsigned int maxRepeats, unsigned int testB, unsigned int testC)
{
    unsigned int lsrOH;
    float slotTime;

    lsrOH = (maxRepeats + 1);

    lsrOH = lsrOH * 3;

    slotTime = 18.0/40000. + (float) lsrOH;

    return (unsigned int) slotTime * 1000;
}


  • Forgot to add to initial post...

    I have tried many projects options to try and get this to work.  But are there others you can recommend?

    thanks

    dan

  • You may be encountering the bug discussed in the following thread

    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/140177.aspx

    Try the workaround suggested there and let me know if it works.

  • Thanks for the guidance...

    There are so many work around in that thread, I'm not sure which one you refer to.  However I have tried the following:

    Switched from compiler version 4.0.1 to 4.0.0.

    Switched --use_hw_mpy from "F5", to "32" to "  "

    Turned off all optimizations (that I can find).

    None of these made a difference - it looks like the code is simply not there in the disassembly window...

    Was there a particular work around you had in mind?

    thanks!

  • I mean to remove the --use_hw_mpy option entirely.  Leaving it blank will not suffice.  The bug discussed in that thread only happens when using the hardware multiply functions in the library, and turning off hardware multiply is a quick test for that bug.  If disabling --use_hw_mpy does not make the test case work, I'll need a complete, compilable test case including all of the command line options.  It might also help to post the dissassembly for that file.

    Also, don't forget to include stdio.h

  • OK.  How do you completely remove the option if using the CCS 5 Project Settings?  When I select --use_hw_mpy="  ", it seems to remove it.

    Here are my linker flags

    -vmspx --abi=coffabi -g --define=__MSP430F5438__ --diag_warning=225 --display_error_number --silicon_errata=CPU15 --silicon_errata=CPU18 --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU23 --silicon_errata=CPU40 --global_register=r4 --global_register=r5 --printf_support=minimal -z -m"TestCalc.map" --stack_size=1000 --heap_size=1000 -i"C:/Texas Instruments/ccsv5/ccs_base/msp430/include" -i"C:/Texas Instruments/MSP430 Code Generation Tools 4.0.1/lib" -i"C:/Texas Instruments/MSP430 Code Generation Tools 4.0.1/include" --reread_libs --warn_sections --rom_model

    Here are my compiler flags

    -vmspx --abi=coffabi -g --include_path="C:/Texas Instruments/ccsv5/ccs_base/msp430/include" --include_path="C:/Texas Instruments/MSP430 Code Generation Tools 4.0.1/include" --define=__MSP430F5438__ --diag_warning=225 --display_error_number --silicon_errata=CPU15 --silicon_errata=CPU18 --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU23 --silicon_errata=CPU40 --global_register=r4 --global_register=r5 --printf_support=minimal

    Yes, <stdio.h> is included, it got lost in my cut and paste...

    Here is my disassembly for main() and test().  Would it be best to just send my project?  Should I zip it up.

            test:
    006c1c:   0CCF                MOVA    R12,R15
    006c1e:   025F                RLAM.W  #1,R15
    006c20:   5F0C                ADD.W   R15,R12
    006c22:   503C 0003           ADD.W   #0x0003,R12
    37          slotTime = 18.0/40000. + (float) lsrOH;
    006c26:   13B0 6C6A           CALLA   #__fs_utof
    006c2a:   403E EDFA           MOV.W   #0xedfa,R14
    006c2e:   403F 39EB           MOV.W   #0x39eb,R15
    006c32:   13B0 5CBC           CALLA   #_fs_add
    39          return (unsigned int) slotTime * 1000;
    006c36:   13B0 6812           CALLA   #__fs_tou
    006c3a:   403D 03E8           MOV.W   #0x03e8,R13
    006c3e:   13B0 6D2C           CALLA   #__mpyi
    40      }
    006c42:   0110                RETA    
    12      void main(void) {
            main:
    006c44:   8221                SUB.W   #4,SP
    18          WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
    006c46:   40B2 5A80 015C      MOV.W   #0x5a80,&Watchdog_Timer_WDTCTL
    20          value = test(maxRepeats,1,2);
    006c4c:   403C 0003           MOV.W   #0x0003,R12
    006c50:   431D                MOV.W   #1,R13
    006c52:   432E                MOV.W   #2,R14
    006c54:   13B0 6C1C           CALLA   #test
    22          printf("%d",value);
    006c58:   40B1 6D90 0000      MOV.W   #0x6d90,0x0000(SP)
    006c5e:   4C81 0002           MOV.W   R12,0x0002(SP)
    006c62:   13B0 6B16           CALLA   #printf
    25      }
    006c66:   5221                ADD.W   #4,SP
    006c68:   0110                RETA    
            __fs_utof:
    006c6a:   4C0D                MOV.W   R12,R13
    006c6c:   930D                TST.W   R13
    006c6e:   240E                JEQ     (RETURN_0)
    006c70:   403B 008F           MOV.W   #0x008f,R11

    thanks again for your quick help...

  • DAN CLAPP said:
    006c1c:   0CCF                MOVA    R12,R15
    006c1e:   025F                RLAM.W  #1,R15
    006c20:   5F0C                ADD.W   R15,R12

    These three instructions perform a multiplication by 3 by using the alternate expression ((lsrOH<<1)+lsrOH).

    DAN CLAPP said:
    --global_register=r4 --global_register=r5

    Using global registers could pose a problem.  Try disabling those two options.  If you need to use global registers, you're probably going to have to recompile the entire RTS library with those options.

    DAN CLAPP said:
    OK.  How do you completely remove the option if using the CCS 5 Project Settings?  When I select --use_hw_mpy="  ", it seems to remove it.

    Hmm.  Well, I can't see exactly what you're doing, but this option does not appear in the command-line options you show above, so I suppose that rules out hardware multiply problems.  I doubt multiplication is your problem in any case, as the multiplication by 3 is still there, as shown above.

  • Archaeologist,

    OK, It appears to be calculating right, but the debugger is not making it easy.

    1. The global registers I accidently set when I was winging it trying to get some results.  I disabled them but got the same results (so these were a don't care, at least related to debugging, see next).

    2. When stepping through the source, the debugger jumps over the multiply operation and then I cannot see anything withing the subroutine with the debugger (either by dragging my cursor over the variable or by setting the variables in the watch window).  All it does is show the initialization line, suce as "unsigned int lsrOH;", even through it has calculated a value.

    So I think it is working, but it would be better if the debugger can handle this rather simple type of operations.

    Thank you so much for your quick help.

    cheers,

    Dan

  • Just a follow up.

    My sample code above was a snippet from a very large project containing lots of code and lots of compiler and linker options.

    The problems was that the function that was being called (in this test case the equivalent function was "test()"), was being jumped over in the debugger, and appeared to not be called.

    Removing the "--use_hw_mpy=F5" by choosing "  " as a choice in the project options (which removes the command line option), made it so I could step through the code properly, and at least step on the function that was being called.  The routine was calculating properly, but I am still not able to debug it as described in my previous post.  But at least I have got going again...

    cheers.

    Dan

  • DAN CLAPP said:
    The routine was calculating properly, but I am still not able to debug it as described in my previous post.

    Dan,

    Since the compiler performs some level of optimization by default, if you want a better debug experience, try the option that disables all high level optimization (--no_high_level_opt). It is under Project Properties->Build->Compiler->Advanced Options->Advanced Optimization.

  • AartiG,

    Thank you!  That did it.  One of those hidden gems.  Now I can debug those routines that use math operations!