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.

Minor bug in usb_dev_serial.c - delay loop is getting optimized out by CCS

Other Parts Discussed in Thread: SW-TM4C

Hello,

   Today I downloaded the latest TivaWare library (SW-TM4C) and started testing the Hello.c application and usb_dev_serial application. Hello worked fine, but the usb_dev_serial application wasn't working as expected - I wasn't seeing the LED illuminate when a character was entered in the terminal. So I probed it with a scope and found that the LED was being illuminated but not for very long, a few uSecs. I saw the delay line in the code:

            for(ui32Loop = 0; ui32Loop < 150000; ui32Loop++)
            {
            }

Usually these will get optimized out by CCS, so you need to tell the compiler to do something. I changed this to:

            for(ui32Loop = 0; ui32Loop < 150000; ui32Loop++)
            {
                foo++;
            }

...with variable foo defined previously as:

    volatile uint32_t foo = 0;

That solved the problem. Sometime omitting the volatile keyword can still result in it getting optimized out, but making the variable volatile usually prevents the compiler from removing it. Now the LED is illuminating properly, for about 25mSecs each time. BTW, I haven't changed any compiler settings; just imported the project and compiled it.