So, I decided to take this one step further and build a library that hides the details of the mutex and variadic macro. To use the library you will need to:
- Go into your libraries directory and make a new directory called ‘mprintf’
- Copy these two files into the new directory; mprintf.h mprintf.cpp
- Put the #include <mprintf.h> and #include <cserial.h> into all the sketches or programs that will be using mprintf.
- Put the following two statements at the beginning of your setup() function
serial_stdout_init(9600);
mprintf_init();
5. use mprintf the same way you would use printf
example: mprintf(“hello world\n”);
Update: 20100118:
make sure your freeRTOS task has more then the minimum stack. mprintf
will not work properly for some value conversions (like int or decimal
or anything that requires addition stack depth). I increased by 2 X (2 *
configMINIMAL_STACK_SIZE) and all is well for a while. I’m working on
getting some kind of high water stack report by task so we can see when
things are getting read to blow up!). Note, tasks use stack for their
local variables. Global variables (not welcome) are safer until a good
method of reporting predicted stack usage can be generated from the
compiler. Thoughts? send them to me!
source : http://www.out--there.com/blog/mprintf-a-thread-safe-printf-mprintf-library/
date : Tuesday, January 12, 2010