printf implementation causes problems.

aeyes wrote on Sunday, October 19, 2008:

Hi ,

I am working on a FreeRTOS port on Samsung 4510 processor . I have ported the RTOS successfully, however when I try to do a printf application port on it , I see some annomalies.

   I have ported the standard printf implementation ( named my_printf ) where I have used the UART . And have created some .c files which handle the my_printf function , I have also used the stdarg.h for this implementation . When I run the image , the printing happens once for the respective task ( say I have put a my_printf statement for task no x ) however from the next time the printing does not happen for that task . Hence I have no idea if that task works anymore . 

  However for those taske in which I have directly output characters through the UART like below , the output is visible consistently .

int i ;
for (;:wink: {
char * hellostr="Task 2 running \n ";
    long* paddr=(long*)0x3ffd00c;

                * paddr=hellostr[i];


This works faithfully .

But the printf implementation fails after one time print  .

What might be the problem ?


davedoors wrote on Monday, October 20, 2008:

I’m not sure which parts of printf you wrote yourself and which come from the C library. If you are using the GCC C library then you will probably find that the printf family of functions uses lots of stack, is not reentrant, and may even attempt to use malloc. The most likely cause of your problem is a stack overflow.

The FreeRTOS download includes some cut down versions of sprintf that use much less stack and are reentrant. Try using one of those. Look for a file called printf-stdarg.c

aeyes wrote on Monday, October 20, 2008:

  Hi ,

    Sorry for the false alarm :slight_smile: . I got the problem I mistakenly deleted the endless for loop in the task I put the printf statement in so after printing once it was exiting that function .

  My printf implementation uses no GCC libraries and I have named it as my_printf which does not make any calls to the GCC library , it is a cut down version as you stated , it only uses stdarg.h header which is external , apart from that there is a my_printf.c function and uart.c function which I created with their respective header files .

  It works fine now , so far so good :). Thanks a lot .