Tyler Weaver
/
rtos_sprintf
Demonstration of the use of sprintf() causing a run time problem with RTOS.
Diff: main.cpp
- Revision:
- 0:7fecc17e2765
diff -r 000000000000 -r 7fecc17e2765 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 16 14:03:52 2012 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); + +char* teststring = ""; +int testint = 65; + +// uncomment only one of the sprintf functions at a time to see it fail at that point + +void led2_thread(void const *argument) { + while (true) { + led2 = !led2; + //sprintf(teststring, "This is a test: %d", testint); + Thread::wait(1000); + } +} + +int main() { + Thread thread(led2_thread); + //sprintf(teststring, "This is a test: %d", testint); + + while (true) { + led1 = !led1; + sprintf(teststring, "This is a test: %d", testint); + Thread::wait(500); + } +}