Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

sprintf breaking under new FreeRTOS

Posted by rog57 on January 17, 2013
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


RE: sprintf breaking under new FreeRTOS

Posted by Jerry Durand on January 17, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by rog57 on January 17, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by Richard on January 18, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by rog57 on January 18, 2013
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.


RE: sprintf breaking under new FreeRTOS

Posted by Richard Damon on January 18, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by rog57 on January 18, 2013

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



RE: sprintf breaking under new FreeRTOS

Posted by Dave on January 18, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by Richard on January 18, 2013
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.

RE: sprintf breaking under new FreeRTOS

Posted by rog57 on January 18, 2013
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.


RE: sprintf breaking under new FreeRTOS

Posted by rog57 on January 18, 2013
RATHER - it is set to "Large without multibytes" and works good.

Regards,
Gary


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists