broken mb-gcc -O2 ?

Hi,

I'm compiling this code for microblaze gcc

void uart1_printchar(unsigned char c) { while( (*(unsigned char *) UARTS_STATUS_REGISTER) & UART1_TX_BUFFER_FULL ); *(char *) UART1_TXRX_DATA = c; }

and when using no optimization the code works OK but when using -O2 to improve code optimization, mb-gcc generates this:

uart1_printchar: lbui r3,r0,UARTS_STATUS_REGISTER andi r5,r5,0x00ff andi r3,r3,UART1_TX_BUFFER_FULL #and1 $L2: bnei r3,$L2 sbi r5,r0,UART1_TXRX_DATA rtsd r15,8 nop

As you can see if the UART1_TX_BUFFER_FULL bit is 1 the program enters in infinite loop $L2

May be this is a broken mb-gcc? mb-gcc --version shows:

mb-gcc (GCC) 3.4.1 ( Xilinx EDK 8.2 Build EDK_Im.14 120906 ) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thanks for any help Manuel

Reply to
manuel-lozano
Loading thread data ...

You need to change (unsigned char *) above to (volatile unsigned char

*) or the compiler will correctly optimize this into an infinite loop.

volatile tells the compiler that the memory may change without the compiler knowing about it.

Alan Nishioka

Reply to
Alan Nishioka

Hi,

thanks now it's working...

Regards Manuel

Reply to
manuel-lozano

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.