sprintf breaking under new FreeRTOS

Hi,
Trying to format a string using sprintf and with padding , as this example: sprintf(bufferIn, “%u-%.2u-%.2u”, a, b, c); Instead of adding a “0” it prints nothing except “.2u%”.
I’ve found previous posts where this has been an issue and tried the suggestion of changing the “portBYTE_ALIGNMENT” from 8 to 4, with no success. Can anyone help out? Thank you

sprintf breaking under new FreeRTOS

Check which print formatting library you have loaded.  I had to enable semi-hosting in Code Red just to be able to get the full print library.

sprintf breaking under new FreeRTOS

I’m using IAR EWARM 6.5, not code red. I’ve included the required libraries. If i build a test program without FreeRTOS, it formats OK, so it’s something in FreeRTOS causing it.

sprintf breaking under new FreeRTOS

Your printf() implementation will normally come from your compiler libraries, or sometimes from specialist third party libraries. FreeRTOS does not implement any standard library functions and it is highly improbable that anything in FreeRTOS could cause this.  I think the issue you were referring to with the byte alignment was with regards to using 64 bit floating point numbers where the stack alignment needed adjusting – but the symptom was different.  The symptom in that case was 0 being printed out instead of the floating point number, whereas in your case the symptom seems to be the printf formater does not understand the format string. However many FreeRTOS demos (demos, not the kernel) come with a third party file called printf-stdarg.c that provides a tiny cut down print/sprintf/printf implementation for use in cases where the libraries that come with the compiler are just too big for small embedded use (notably when NewLib is used).  I’m guessing that your project is including printf-starg.c in the build, and that is replacing the compilers implementation. Regards.

sprintf breaking under new FreeRTOS

Richard, Thanks for elaborating your thoughts.
To this point, I have half a dozen other projects that I have used the CMSIS included “debug_frmwrk.h” file, and have had no issues using the calls from that (_DBG_, _DBG32_, etc)
This formatting issue has just surfaced since I began developing with FreeRTOS a few weeks back. I can load any of those projects and don’t see this issue. Regartding the file you are referring to – “printf-stdarg.c”, it is in the RTOS source directory as I used one of your starting projects to get this going. It was the “Web dataserver” project. If i understand correctly, should I be using this instead of the CMSIS calls? Thank you.

sprintf breaking under new FreeRTOS

One thing to note, not every file under the FreeRTOS directory is “part of FreeRTOS”, in particular, the contents of the demo directory is only sample programs provided as a guide. The file printf-stdarg.c that appears in many demos is such a file. If you want the functionality that the file provides, you can use it, but if it isn’t compatible with your requirements you shouldn’t.

sprintf breaking under new FreeRTOS

Understood. I should clarify I have NOT used the file printf-stdarg.c
To this point, only the CMSIS libs.

sprintf breaking under new FreeRTOS

I suggest adding a simple printf(”Hello world”) line in your main() function then step into the function in the debugger to see where it takes you.

sprintf breaking under new FreeRTOS

Could it be that your IAR project options are set to use a minimal printf() implementation? If you bring up the project options, then go to the General Options category, then the Library Options tab, what is Printf Formatter set to?  If it is set to anything other than “Full” can you try setting it to Full to see if that fixes your issue. Regards.

sprintf breaking under new FreeRTOS

Awesome! Problem fixed. I started out using FULL, then worked back until I found the smallest option that worked OK. It ended up being “Full without multibytes” Thanks so much, you guys are just great, all the help is appreciated.

sprintf breaking under new FreeRTOS

RATHER – it is set to “Large without multibytes” and works good. Regards,
Gary