AnsweredAssumed Answered

Kinetis L - Optimization stopps IF Loop functionality

Question asked by Edward Kaeding on Jul 1, 2014
Latest reply on Jul 2, 2014 by Edward Kaeding

Hello Freescale Support Team,

 

As usual I apologise for my questions, if they have allready been answered in a different discussion.

 

I am working with the MKL02Z32VFM4 MCU, CodeWarrior v10.5 and not PE.

 

I am currently programming a Bootloader and therefore small size is of most importance.

Everything works fine, but after I run the Optimization "Optimize size (-Os)" nothing works anymore.

 

Using the debugger I figured out that the code is stuck at the first "if-Loop".

 

Here my code of my GetChar UART0 program, where the program is stuck:

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

void UART0_GetChar(unsigned char *value, unsigned char block) {

    for (;;) {

 

        if (ReceiveChar_Length > 0) {    /* Is number of received chars greater than 0? */

            NVIC_ICER |= NVIC_ICER_CLRENA(0x1000);     /* Deactivate Rx-Interrupt. */

           

            ReceiveChar_Length--; /* Decrease number of remaining received chars. */

           

            NVIC_ICPR |= NVIC_ICPR_CLRPEND_MASK; /* Clear any Pending Interrupts. */

            NVIC_ISER |= NVIC_ISER_SETENA(0x1000); /* Activate Rx-Interrupt. */

           

            *value = InpBuffer[InpIndexR++]; /* Take value out of the buffer. */

           

            if (InpIndexR >= RECEIVE_BUF_SIZE) { /* Is the index out of the receive buffer? */

                InpIndexR = 0; /* Set index to the first item into the receive buffer. */

            }

            break;

        }

        else {

            *value = -1;

 

            if (!block) {

                break;

            }

        }

    }

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------

 

block gets the value 1. The Interrupt still works fine, but then it just jumps back to if (!block) and stays there.

I believe that there will be even more problems after this issue is solved.

The Optimization would really help, because it reduces the size from about 5000 to 2900.

 

I thank everyone in advance for your great support,

Edward.

Outcomes