Kinetis L - Optimization stopps IF Loop functionality

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Kinetis L - Optimization stopps IF Loop functionality

Jump to solution
1,021 Views
edwardkäding
Contributor III

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.

Labels (1)
0 Kudos
Reply
1 Solution
846 Views
mjbcswitzerland
Specialist V

Hi Edward

Make sure that you have declared

volatile int ReceiveChar_Length = 0;                      [if not int, use whatever type it is - the volatile key word is the important bit]

If not, you may have this effect.

Regards

Mark

View solution in original post

0 Kudos
Reply
2 Replies
847 Views
mjbcswitzerland
Specialist V

Hi Edward

Make sure that you have declared

volatile int ReceiveChar_Length = 0;                      [if not int, use whatever type it is - the volatile key word is the important bit]

If not, you may have this effect.

Regards

Mark

0 Kudos
Reply
846 Views
edwardkäding
Contributor III

Hello Mark,

Your advice solved my problem. I was quite surprised for this easy solution but after research I also read about this effect after Optimizations. 

I thank you very much for your great and quick support.

I wish you and your team a great day,

Edward.

0 Kudos
Reply