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.

TM4C1237E6PM: Device hangs when compiled with -O2, runs fine when compiled with -O0.

Part Number: TM4C1237E6PM

I'm working with CCS 6.2.  We had a problem with the TIVA device on out custom board failing to call Systick and thus hanging in its FSM, so I tried running through the debugger.  The code was compiled with -O2, which caused the debugger to jump around, so I recompiled with -O0 to make it easier for me to debug.  When I did that, the device didn't hang.

We were using compile 15.12.3 LTS.  We looked at the errata for the compiler and found issue CODEGEN-2053 was fixed in 15.12.4, so we changed to the newest compiler availble, 15.12.7. That didn't solve the problem.  There is a tie-in to usb_dev_serial because the problem will not occur if we have a USB cable connected to our board.

We made some changes to the usb_dev_serial.c file and that rearranged the code enough to make the failure go away, but it has returned in a new image again.  If I compile the code with -O0 it works just fine, so I think some flavor of the CODEGEN-2053 issue is still present in the compiler.

  • Hi Chuck,

        Can you confirm it is really related to CODEGEN-2053 per the conditions listed below? Can you try the very latest TI compiler v20.2.1LTS? If it is related to compiler then I will need to move your post to the compiler experts for analysis. It will be good if you can reproduce the issue in a smaller project not your full-fledge project. This will be easier for the compiler team to analyze.  

    This bug can only happen in a function compiled with optimization level 1 or higher which contains both of the following: 1) A struct assign where the destination is volatile, and the source is a known constant, and the struct contains a bit-field, and the struct is of size "int" or smaller. 2) Any bit-field access (read or write) other than as part of a struct assign or initialization expression. That is, the name of the bit-field is present in the access expression. Note that the optimizer can create this situation by inlining functions, so 1 and 2 might be in different functions in the source code.