Problems with uart_putchar in M52235.

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

Problems with uart_putchar in M52235.

2,157 Views
vale
Contributor I
Hallo everyone,
I have a problem with my M52235 board.
I used Codewarrior stationery for my board, then simply write down this main:
 
int main()
{
 uart_putchar(0,'a');
 
 while(1); // Idle
 
 return 0;
 }
 
where putchar is the predefined function I find in the uart.c file in the Codewarrior stationery
(prototype: void uart_putchar (int channel, char ch))
It doesn't work.
I examined the assembly generated after compiling and I realized that char 'a' is first stored in register d0 (32 bit) then pushed to the stack (pushing 4 bytes).
When loading UART TX buffer, only one byte of the four bytes on the stack is taken, and it is the most significant one. Hence, as 'a' is 0x00000062, only byte 0x00 is loaded to the TX buffer.
What is happening?
Is it a problem of little endian/ big endian mismatch?
Can anyone help me?
Thank you
 
Valentina
Labels (1)
0 Kudos
Reply
3 Replies

625 Views
CrasyCat
Specialist III
Hello
 
Not sure what the problem is here, but it looks like you are calling a function and there is no prototype for the function available in the source file.
 
You need to include the appropriate header file, where the prototype for function uart_putchar is defined prior to invoking the function.
As far as I can tell you need to include uart.h at the beginning of your source file.
 
Does that help?
 
CrasyCat
0 Kudos
Reply

625 Views
vale
Contributor I
Thank you!
That was the problem! Now everything works.
I was misled by the fact that the function was found even without the prototype was included in main.c
 
Is there a configuration option in CodeWarrior to get a warning for such errors?
What was the problem with the compiler? Did it take the char for an int because of the lack of the prototype?
 
Thank you for your immediate help!
 
Valentina 
0 Kudos
Reply

625 Views
CrasyCat
Specialist III
Hello
 
Basically the ANSI C standard allows you top call a function when no prototype is defined.
In that case the compiler will apply the integral promotion rule.
That means in your case compiler passes an int (32-bit) to the function, which tries to read a character (8 bit).
 
You can ask the compiler to generate an error instead of a warning in such cases.
Just check the "Require Function Prototypes" box in the Target Settings "C/C++ Language" Panel.
 
This way you will get an error when you call a function  and you have no prototype for it.
 
If you want to activate/desactivate  that only for some source file you can alternatively use the pragma require_prototypes.
Please refer to the ColdFire_Build_Tools_Reference.pdf for more info on this pragma.
 
I hope this helps.
 
CrasyCat
0 Kudos
Reply