vsnprintf() problem with gcc+eclipse+LPC2214

Hi, I’m using vsnprintf() to try to create a version of printf() that will work with preemtive multi tasking – preventing output text being mixed up. I am using the serial.c library distributed with the source, modified to support two serial ports and called with a new function that replaces printf() using vsnprintf() to format the text before being sent to vSerialPutString().  A semaphore prevents the output texts from numerours tasks being mixed up. The trouble is my code crashes with a memory access exception within the call to vsnprintf(). I’ve even tried it with const text and sprintf() and it does the same. Why would these functions not work when the RTOS is running, yet I can use them before the scheduler starts without a problem? If I replace them with puts() instead I get the format text as expected (obviously via a different software route) Any suggestions of other tests I can do to isolate the problem which appears to be an interaction between FreeRTOS and libc or libgcc. Cheers, Jason.

vsnprintf() problem with gcc+eclipse+LPC2214

sprintf type functions in GCC are nutorios for using a LOT of stack.  I suspect your problem is just a stack overflow. Take a look at the LPC2148 CrossFire demo in the freertos download.  This uses a task to control printing – if any other task wants to print it sends the text to print to the printer task.  The printer task is the only task that is allowed to access the IO.

vsnprintf() problem with gcc+eclipse+LPC2214

Hi, No worries, fixed it.   The new printf function is being called from many tasks.  Some of these tasks had a too small size stack, causing the stack to become corrupted. Pity the RTOS does not have stack checking as standard.   I have noticed that others have done a patch that implements this, I’ll take a look at it. j.