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/TMS320F28034: Volatile for structure variable and its bit operation

Part Number: TMS320F28034

Tool/software: TI C/C++ Compiler

Hi,

One doubt about structure and its variable's bit operation:

1) Compiler version, V6.xx.xx

2) Customer's code is level-2 optimized

3) One structure variable, all of its bits are set/reset independently as: "user.variable_1.bit.1= 1" or "user.variable_1.bit.1= 0"

4) There's one bit (for example bit 1) is set in main loop, each 2ms; but it's not reset at any other places, like ISR

5) This bit is read and used in ISR like "if(user.variable_1.bit.1==1)"

6) This variable's other bits are set/reset at other places, like ISR and main loop

If the structure and variables are not volatile defined, bit 1 sometimes is reset;

If it's volatile defined, it seems bit 1 will never be reset. 

Is that possible?

Thanks a lot.

Br, Jordan

  • Jordan Zhou said:
    4) There's one bit (for example bit 1) is set in main loop, each 2ms; but it's not reset at any other places, like ISR

    So, this one bit in a bit field structure is assigned the value 1, but is never assigned the value 0.  Whether it is declared volatile or not, optimized or not, it should never change to 0.  For the situation where this happens, we need a test case that allows us to reproduce the problem.  If you are confident the problem resides in one source file, then for that source file, please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • Please consider the possibility this compiler issue causes the problem.  It is fixed in versions 16.9.2.LTS and later.

    Thanks and regards,

    -George

  • George,

    Thanks for your support.

    Is it possible that, other bits' operation, with ISR, changed this bit's value to 0?

    No matter volatile or not, it will not improve the situation, right?

    When volatile, this structure will not be optimized, in this case, the code's execution will be changed. This is what I can image.

    Test case, it's very very hard to prepare. Customer can't share their code.

    Br, Jordan

  • Jordan Zhou said:
    Is it possible that, other bits' operation, with ISR, changed this bit's value to 0?

    It is possible.  If that happened, I suspect it is due to a compiler bug, and I want to investigate.

    Jordan Zhou said:
    No matter volatile or not, it will not improve the situation, right?

    Using volatile tends to disable lots of optimizations.  So, that could change what happens and thus avoid the problem.

    Jordan Zhou said:
    Test case, it's very very hard to prepare. Customer can't share their code.

    I understand.  But without a test case, I do not see how we can resolve this issue.

    Thanks and regards,

    -George