Topic : Compiller makes wrong code!!

Forum : ARM

Original Post
Post Information Post
December 8, 2010 - 3:12pm
Guest

I have Ride-7 for STM32107CV device. I use example code for STM3210C-EVAl board for testing uart polling. Compiller creates wrong code.

I have make such simply code in main loop:

chr='0';
while(1)
{
if(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) != RESET)
{
USART_SendData(USARTy, chr++);
if(chr>'z') chr='0';
}
}

and it doesnt work, no characters are transmitted! I used debugger - program worked strange in this loop. So I have added one dummy line after "if" statement:

chr='0';
while(1)
{
if(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) != RESET)
{
USART_SendData(USARTy, chr++);
if(chr>'z') chr='0';
}
tmp++; // this line is added and tmp varible has no function in the code!!
}

and now everything works.
:mad:

Replies
Post Information Post
+1
0
-1
December 9, 2010 - 3:01pm
Guest

For a conclusion that the compiler makes wrong code you would really have to look at the generated assembly: It is impossible to come to that conclusion otherwise.

Without any other source code than this it impossible to say where the error in your code is.

+1
0
-1
December 9, 2010 - 11:34pm
Guest

Well, you are mostly right, but.... I think not this time. I have got ready code from examples dedicated for STM3210C-EVAL board. I only deleted big main loop from sources and added my simply one instead.
I can of course include source code, I will do it next week.
thanks

+1
0
-1
December 13, 2010 - 11:57am
Guest

So, here is the code:

int main(void)
{
char chr,tmp;

RCC_Configuration();
GPIO_Configuration();

USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);


chr='0';
while(1)
{
if(USART_GetFlagStatus(USART2, USART_FLAG_TXE) != RESET)
{
USART_SendData(USART2, chr++);
if(chr>'z') chr='0';
}
tmp++;
}
}

+1
0
-1
December 13, 2010 - 2:01pm
Raisonance Support Team

Hi,

It is highly unlikely that the problem comes from the compiler. These simple issues are of course tested before the compiler is released...

The first thing to do is checking that you are using the latest version of the ST library. I remember that in some older versions, there were some 'volatile' keywords missing. That was typically leading to the kind of problems that you observe. Download the latest update from the ST website. Also make sure that you don't have a version conflict. (old h files with new c files ...)

Note that depending on the optimization level, the tmp 'useless variable' can indeed have a big impact, even if just on timing. Please tell us which optimization level you are using. You might also want to try other levels. The results will help understanding the problem better.

Then, you should also make sure that you are using the latest version of the compiler. Update the RKit-ARM from the Raisonance website.

Please tell us if it helps.

Best Regards,

Vincent

+1
0
-1
March 8, 2011 - 11:24pm
Guest

Hi!
I have of course the latest versions of ST library and compiler.
I have made many tries, and when I use no optimization program behaves strange - especially on simple loops.
When I use -O3 optimization level, it look that program works good. Strange....

+1
0
-1
April 6, 2011 - 9:25am
Guest

Have you configured the GPIO pins?

Have you enabled the right clocks in the clock tree?

+1
0
-1
April 13, 2011 - 5:52pm
Raisonance Support Team

Hi,

There is an example in your C:\Program Files\Raisonance\Ride\Lib\ARM\io_putchar directory, which shows how to configure the GPIOs, USART, REMAP. This example works fine.

You can use it as a base for experimenting and understanding why you code has problems.

As a side note, there may be some RS-232 problems on the Windows side as well. The best way to check if your code works is to plug an ascilloscope and to check that the bit width is correct (103us for 9600bps).

Best Regards,