This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

use printf in threads.

I use printf in a thread. like the following code:

void task1(void)
{ while(1) printf("hello!\n");
}

void task2(void)
{ while(1);
}

Finally, the program run in to OS_ERR_STK_OVF.

Parents
  • Here the reply that I got once from Keil support for similar question:
    "
    The printf/sprintf functions use more stack. I think this depends on the print parameters and print format (%s,%d,... etc).

    I cannot tell you the exact usage of stack for printf/sprintf.
    "
    (End of citation)

    So, you can measure by yourself the stack usage of specific calling, by filling the stack with constant before and examine how much of these values was destroyed after running the function.

    I'll be happy to hear about printf implementation that uses less stack or about a way to calculate the stack consuming without actually running the code.

Reply
  • Here the reply that I got once from Keil support for similar question:
    "
    The printf/sprintf functions use more stack. I think this depends on the print parameters and print format (%s,%d,... etc).

    I cannot tell you the exact usage of stack for printf/sprintf.
    "
    (End of citation)

    So, you can measure by yourself the stack usage of specific calling, by filling the stack with constant before and examine how much of these values was destroyed after running the function.

    I'll be happy to hear about printf implementation that uses less stack or about a way to calculate the stack consuming without actually running the code.

Children