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.

Compiler/MSP430FR5994: some questions

Genius 12760 points
Part Number: MSP430FR5994

Tool/software: TI C/C++ Compiler

I have some questions about the MSP430 and TI compiler.

1) Is there a "break" instruction in the MSP430 instruction set ?
A "break" instruction would act as a breakpoint when a debugger is connected, otherwise it would act as a NOP.

2) For the C instructions "A |= B;" and "A &= ~B;", is the compiler always generates a single assembler instruction "BIS B, A" or "BIC B, A" ?
If it is not always the case, what are the constraints to respect ?

3) What is the undocumented compiler option "-vmspx" used for ?

4) How to prevent the replacement of an access to a const object by its value ?
For example :
The following constant is defined to 0x10 in the C source.
And we allow the production to change this value in the FRAM (or flash) before to start the firmware.

const unsigned char ProductionParameter = 0x10;
...
{
    P1OUT &= ~ProductionParameter;

Debug   --opt_level=0  --opt_for_speed=0  // access to const object: OK
    D2C2     BIC.B   &ProductionParameter,&P1OUT
    C240    
    0202    

Release --opt_level=4  --opt_for_speed=5   
    The const object is replaced by the value ~0x10, and the production value is ignored !
    F2F0     AND.B   #0x00ef,&P1OUT
    EF00    
    0202    

Regards, Bernd

  • 1) There's no single instruction, but I suspect there's a way to achieve this that I'm not aware of.  You might need to ask that in the MSP-specific forum.

    2) It is not guaranteed that the compiler will always generate BIS or BIC in that situation, but it is pretty likely, especially if the arguments are registers.  I'm sorry, I don't have a better answer for you at this time.

    3) It's not undocumented.  It chooses between 16-bit MSP and 20-bit MSPX.  From the compiler help screen:

      -v,--silicon_version=msp,mspx

                             Specify silicon core version. (when not specified,

                              compiler defaults to --silicon_version=msp)

    4) Declare it volatile:

    const volatile unsigned char ProductionParameter = 0x10;

  • 1) Will check that

    2) We use often BIC and BIS on peripheral registers.
    At assembly level, the instructions BIC and BIS are naturally atomic, then we avoid problems when a peripheral register is modified by interrupts.
    I'm looking for an efficient way to have an atomic BIC and BIS at C/C++ level.
    Do you have some ideas ?

    3) It is ok. I searched for "-vmspx" in documentation but not for "-v".

    4) When I use "volatile", the replacement is prevented, it is ok.
    But the code generated by the optimizer is twice the size and half more cycles than without optimization.
    At least, I expect that the optimizer chooses either the smallest or fastest code, but not both the biggest and slowest.
    This problem doesn't appear with "P1xxx |= ProdParam", but only with "P1xxx &= ~ProdParam".
    It seams that the optimizer replaces "BIC" by "AND", but preserves "BIS".
    Is it possible to improve the generated code ?

    const volatile unsigned char ProductionParameter = 0x10;
    ...
    {
        P1OUT &= ~ProductionParameter;

    Debug   --opt_level=0  --opt_for_speed=0
        D2C2     BIC.B   &ProductionParameter,&P1OUT  ; 6 cycles
        C240    
        0202    

    Release --opt_level=4  --opt_for_speed=5   
        3F40     MOV.W   #0x00ff,R15                  ; 2 cycles
        FF00           
        5FE2     XOR.B   &ProductionParameter,R15     ; 3
        BE40           
        C2FF     AND.B   R15,&P1OUT                   ; 4
        0202   

    Regards, Bernd        

  • I am unable to reproduce this result ...

    BO said:
    Release --opt_level=4  --opt_for_speed=5   
        3F40     MOV.W   #0x00ff,R15                  ; 2 cycles
        FF00           
        5FE2     XOR.B   &ProductionParameter,R15     ; 3
        BE40           
        C2FF     AND.B   R15,&P1OUT                   ; 4
        0202   

    Please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George