Kinetis L - Optimization stopps IF Loop functionality

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Kinetis L - Optimization stopps IF Loop functionality

ソリューションへジャンプ
1,018件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 解決策
843件の閲覧回数
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 件の賞賛
返信
2 返答(返信)
844件の閲覧回数
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 件の賞賛
返信
843件の閲覧回数
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 件の賞賛
返信